-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aii-ks: add kickstart_post_script plugin module to generate the post …
…section as a standalone script
- Loading branch information
Showing
5 changed files
with
144 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#${PMpre} NCM::Component::ks_post_script${PMpost} | ||
|
||
# Generate a the ks post section of a node as a standalone script. | ||
|
||
use parent qw (NCM::Component::ks); | ||
|
||
use CAF::FileWriter; | ||
use NCM::Component::ks qw(get_fqdn); | ||
|
||
sub _ks_filename | ||
{ | ||
my ($self, $ksdir, $fqdn) = @_; | ||
return "$ksdir/kickstart_post_$fqdn.sh"; | ||
} | ||
|
||
# Cancels the open filewriter instance on the script | ||
# and returns everything (the select magic/hack) to its normal state. | ||
# Returns the content of the cancelled filewriter instance | ||
sub ksclose | ||
{ | ||
my $fh = select; | ||
|
||
my $text = "$fh"; | ||
|
||
select (STDOUT); | ||
|
||
$fh->cancel(); | ||
$fh->close(); | ||
|
||
return "$text"; | ||
} | ||
|
||
sub make_script | ||
{ | ||
my ($self, $cfg, $post_script) = @_; | ||
|
||
my $fh = CAF::FileWriter->open($self->ks_filename($cfg), mode => 0755, log => $self); | ||
print $fh $post_script; | ||
$fh->close(); | ||
} | ||
|
||
# Prints the kickstart file. | ||
sub Configure | ||
{ | ||
my ($self, $config) = @_; | ||
|
||
my $fqdn = get_fqdn($config); | ||
if ($CAF::Object::NoAction) { | ||
$self->info ("Would run " . ref ($self) . " on $fqdn"); | ||
return 1; | ||
} | ||
|
||
$self->ksopen($config); | ||
|
||
# ignore the packages that are treated in install for now | ||
# for now assume, all is there already | ||
# this is not kickstart | ||
# won't generate the POSTNOCHROOTHOOK | ||
# no repos passed | ||
$self->post_install_script ($config, [], {}, 0); | ||
|
||
my $post_script = $self->ksclose(); | ||
|
||
$self->make_script($config, $post_script); | ||
|
||
return 1; | ||
} | ||
|
||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Quattor qw(kickstart_post_script); | ||
use NCM::Component::ks_post_script; | ||
|
||
our $this_app = $main::this_app; | ||
|
||
$this_app->{CONFIG}->define('osinstalldir'); | ||
$this_app->{CONFIG}->set('osinstalldir', '/some/path'); | ||
|
||
my $obj = Test::Quattor::Object->new(); | ||
|
||
my $ks = NCM::Component::ks_post_script->new('ks_post_script', $obj); | ||
|
||
my $cfg = get_config_for_profile('kickstart_post_script'); | ||
|
||
$ks->Configure($cfg); | ||
|
||
my $fh = get_file('/some/path/kickstart_post_x.y.sh'); | ||
like("$fh", qr{# %post phase}, "contains the post code"); | ||
unlike("$fh", qr{^%post}m, "does not contain the %post tag"); | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object template kickstart_post_script; | ||
|
||
include 'kickstart'; |