From d83621e78f64dcc8e9087d686249c5a5223fd914 Mon Sep 17 00:00:00 2001 From: Michel Jouvin Date: Thu, 2 Mar 2017 08:38:17 +0100 Subject: [PATCH] pxelinux: add kernel parameters in Grub2 config - Includes some code refactoring/cleanup - Unit tests adjusted to test PXELINUX and Grub2 variants, including - pxelinux_no_append_block.t removed (superseded by write_pxelinux_config.t) - Several pxelinux_ks_xxx tests merged for easier maintenance (coverage and regexps tests are identical) - Fixes #258 (caused by a typo in the initial version of this commit) --- aii-pxelinux/src/main/perl/pxelinux.pm | 70 ++++++------ aii-pxelinux/src/test/perl/main_methods.t | 52 +++++++++ .../src/test/perl/pxelinux_ks_base_options.t | 63 +++++++++++ .../src/test/perl/pxelinux_ks_block.t | 42 -------- .../src/test/perl/pxelinux_ks_bonding.t | 66 +++++++++--- .../test/perl/pxelinux_ks_bonding_bridge.t | 44 -------- .../src/test/perl/pxelinux_ks_el7_static_ip.t | 102 +++++++++++++----- .../src/test/perl/pxelinux_ks_ksdevice.t | 91 ++++++++++++++++ .../src/test/perl/pxelinux_ks_logging.t | 53 +++++++-- .../test/perl/pxelinux_ks_nologging_host.t | 35 ------ .../test/perl/pxelinux_ks_special_ksdevice.t | 47 -------- .../test/perl/pxelinux_ks_systemd_ksdevice.t | 53 --------- .../src/test/perl/pxelinux_no_append_block.t | 38 ------- .../src/test/perl/write_grub2_config.t | 11 +- .../src/test/perl/write_pxelinux_config.t | 1 + 15 files changed, 426 insertions(+), 342 deletions(-) create mode 100644 aii-pxelinux/src/test/perl/main_methods.t create mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_base_options.t delete mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_block.t delete mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_bonding_bridge.t create mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_ksdevice.t delete mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_nologging_host.t delete mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_special_ksdevice.t delete mode 100644 aii-pxelinux/src/test/perl/pxelinux_ks_systemd_ksdevice.t delete mode 100644 aii-pxelinux/src/test/perl/pxelinux_no_append_block.t diff --git a/aii-pxelinux/src/main/perl/pxelinux.pm b/aii-pxelinux/src/main/perl/pxelinux.pm index e9c0ad26..64213f4e 100755 --- a/aii-pxelinux/src/main/perl/pxelinux.pm +++ b/aii-pxelinux/src/main/perl/pxelinux.pm @@ -40,11 +40,11 @@ use NCM::Component::PXELINUX::constants qw(:all); Readonly my %GRUB2_VARIANT_PARAMS => (name => 'Grub2', nbpdir_opt => NBPDIR_GRUB2, kernel_root_path => GRUB2_EFI_KERNEL_ROOT, - format_method => \&_write_grub2_config); + format_method => '_write_grub2_config'); Readonly my %PXELINUX_VARIANT_PARAMS => (name => 'PXELINUX', nbpdir_opt => NBPDIR_PXELINUX, kernel_root_path => '', - format_method => \&_write_pxelinux_config); + format_method => '_write_pxelinux_config'); # Element in @VARIANT_PARAMS must be in the same order as enum PXE_VARIANT_xxx Readonly my @VARIANT_PARAMS => (\%PXELINUX_VARIANT_PARAMS, \%GRUB2_VARIANT_PARAMS); @@ -300,10 +300,10 @@ sub _pxe_network_bonding { } -# create a list with all append options for kickstart installations -sub _pxe_ks_append +# create a list with all kernel parameters for the kickstart installation +sub _kernel_params_ks { - my ($self, $cfg) = @_; + my ($self, $cfg, $variant) = @_; my $pxe_config = $cfg->getElement (PXEROOT)->getTree; @@ -329,12 +329,12 @@ sub _pxe_ks_append my $server = hostname(); $ksloc =~ s{LOCALHOST}{$server}; - my @append; - push(@append, - "ramdisk=32768", - "initrd=$pxe_config->{initrd}", - "${keyprefix}ks=$ksloc", - ); + # With PXELINUX, initrd path is specified with a kernel parameter + # Parameter order is not important but is kept as "ramdisk, initrd, ks" for compatibility + # with previous AII versions for easier comparisons. + my @kernel_params = ("ramdisk=32768"); + push (@kernel_params, "initrd=$pxe_config->{initrd}") if ( $variant == PXE_VARIANT_PXELINUX ); + push (@kernel_params, "${keyprefix}ks=$ksloc"); my $ksdev = $pxe_config->{ksdevice}; if ($version >= ANACONDA_VERSION_EL_6_0) { @@ -343,35 +343,35 @@ sub _pxe_ks_append my ($bonddev, $bondingtxt) = $self->_pxe_network_bonding($cfg, $kst, $ksdev); if ($bonddev) { $ksdev = $bonddev; - push (@append, $bondingtxt); + push (@kernel_params, $bondingtxt); } } - push(@append, "$ksdevicename=$ksdev"); + push(@kernel_params, "$ksdevicename=$ksdev"); if ($pxe_config->{updates}) { - push(@append,"${keyprefix}updates=$pxe_config->{updates}"); + push(@kernel_params,"${keyprefix}updates=$pxe_config->{updates}"); }; if ($kst->{logging} && $kst->{logging}->{host}) { - push(@append, "${keyprefix}syslog=$kst->{logging}->{host}:$kst->{logging}->{port}"); - push(@append, "${keyprefix}loglevel=$kst->{logging}->{level}") if $kst->{logging}->{level}; + push(@kernel_params, "${keyprefix}syslog=$kst->{logging}->{host}:$kst->{logging}->{port}"); + push(@kernel_params, "${keyprefix}loglevel=$kst->{logging}->{level}") if $kst->{logging}->{level}; } if ($version >= ANACONDA_VERSION_EL_7_0) { if ($kst->{enable_sshd}) { - push(@append, "${keyprefix}sshd"); + push(@kernel_params, "${keyprefix}sshd"); }; if ($kst->{cmdline}) { - push(@append, "${keyprefix}cmdline"); + push(@kernel_params, "${keyprefix}cmdline"); }; if ($pxe_config->{setifnames}) { # set all interfaces names to the configured macaddress my $nics = $cfg->getElement ("/hardware/cards/nic")->getTree; foreach my $nic (keys %$nics) { - push (@append, "ifname=$nic:".$nics->{$nic}->{hwaddr}) if ($nics->{$nic}->{hwaddr}); + push (@kernel_params, "ifname=$nic:".$nics->{$nic}->{hwaddr}) if ($nics->{$nic}->{hwaddr}); } } @@ -380,36 +380,36 @@ sub _pxe_ks_append $self->error("Invalid ksdevice $ksdev for static ks configuration."); } else { my $static = $self->_pxe_ks_static_network($cfg, $ksdev); - push(@append,"ip=$static") if ($static); + push(@kernel_params,"ip=$static") if ($static); } } elsif ($kst->{bootproto} =~ m/^(dhcp6?|auto6|ibft)$/) { - push(@append,"ip=$kst->{bootproto}"); + push(@kernel_params,"ip=$kst->{bootproto}"); } my $nms = $cfg->getElement("/system/network/nameserver")->getTree; foreach my $ns (@$nms) { - push(@append,"nameserver=$ns"); + push(@kernel_params,"nameserver=$ns"); } } my $custom_append = $pxe_config->{append}; if ($custom_append) { $custom_append =~ s/LOCALHOST/$server/g; - push @append, $custom_append; + push @kernel_params, $custom_append; } - return @append; + return @kernel_params; } -# create a list with all append options -sub _pxe_append +# create a list with all required kernel parameters, based on the configuration +sub _kernel_params { - my ($self, $cfg) = @_; + my ($self, $cfg, $variant) = @_; if ($cfg->elementExists(KS)) { - return $self->_pxe_ks_append($cfg); + return $self->_kernel_params_ks($cfg, $variant); } else { - $self->error("Unclear how to create the append options. Not using any options."); + $self->error("No Kickstart-related parameters in configuration: no kernel parameters added."); return; } } @@ -423,7 +423,7 @@ sub _write_pxelinux_config log => $self, mode => 0644); my $appendtxt = ''; - my @appendoptions = $self->_pxe_append($cfg); + my @appendoptions = $self->_kernel_params($cfg, PXE_VARIANT_PXELINUX); $appendtxt = join(" ", "append", @appendoptions) if @appendoptions; my $entry_label = "Install $pxe_config->{label}"; @@ -468,6 +468,11 @@ sub _write_grub2_config my $kernel_path = "$kernel_root/$pxe_config->{kernel}"; my $initrd_path = "$kernel_root/$pxe_config->{initrd}"; + my @kernel_params = $self->_kernel_params($cfg, PXE_VARIANT_PXELINUX); + @kernel_params = () unless @kernel_params; + my $kernel_params_text = join(' ', @kernel_params); + $kernel_params_text = ' ' . $kernel_params_text if $kernel_params_text; + my $fh = CAF::FileWriter->open ($self->_filepath ($cfg, PXE_VARIANT_GRUB2), log => $self, mode => 0644); print $fh <{label}" { set root=(pxe) - $linux_cmd $kernel_path ks=$pxe_config->{kslocation} ksdevice=$pxe_config->{ksdevice} + $linux_cmd $kernel_path$kernel_params_text $initrd_cmd $initrd_path } } @@ -687,7 +692,8 @@ foreach my $operation (qw(configure boot rescue livecd firmware install)) { my $variant = __PACKAGE__->$variant_constant; if ( $self->_variant_enabled($variant) ) { $self->verbose("Executing action '$operation' for variant ", $self->_variant_attribute('name', $variant)); - $self->_variant_attribute('format_method', $variant)->($self, $cfg) if ($operation eq 'configure'); + my $method = $self->_variant_attribute('format_method', $variant); + $self->$method($cfg) if ($operation eq 'configure'); unless ( $self->_pxelink ($cfg, &$cmd(), $variant) ) { my $fqdn = $self->_get_fqdn($cfg); diff --git a/aii-pxelinux/src/test/perl/main_methods.t b/aii-pxelinux/src/test/perl/main_methods.t new file mode 100644 index 00000000..5e562912 --- /dev/null +++ b/aii-pxelinux/src/test/perl/main_methods.t @@ -0,0 +1,52 @@ +use strict; +use warnings; +use Test::More; +use Test::Quattor qw(pxelinux_base_config); +use NCM::Component::PXELINUX::constants qw(:pxe_constants :pxe_commands); +use NCM::Component::pxelinux; +use CAF::FileWriter; +use CAF::Object; +use Sys::Hostname; +use Readonly; + + +=pod + +=head1 SYNOPSIS + +Tests for the public methods. + +This test only assess that internal methods to be called exists (they are all mocked in the test). +Testing of internal methods called by public methods are covered by other unit tests. +Errors (undefined methods) raise exceptions that cause the test to fail. + +=cut + +Readonly my $NBPDIR_PXELINUX_VALUE => '/pxe/linux/conf.files'; +Readonly my $NBPDIR_GRUB2_VALUE => '/grub/config_files'; + +# Define a few required AII options +# Normally done by aii-shellfe +our $this_app = $main::this_app; +$this_app->{CONFIG}->define(NBPDIR_PXELINUX); +$this_app->{CONFIG}->set(NBPDIR_PXELINUX, $NBPDIR_PXELINUX_VALUE); +$this_app->{CONFIG}->define(NBPDIR_GRUB2); +$this_app->{CONFIG}->set(NBPDIR_GRUB2, $NBPDIR_GRUB2_VALUE); + +my $comp = NCM::Component::pxelinux->new('grub2_config'); +my $cfg = get_config_for_profile('pxelinux_base_config'); + +# Mock methods called by public methods +my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); +$mockpxe->mock('_pxelink', 1); +$mockpxe->mock('_write_grub2_config', 1); +$mockpxe->mock('_write_pxelinux_config', 1); +$mockpxe->mock('cleanup', 1); + +for my $action (@PXE_COMMANDS, 'UNCONFIGURE', 'STATUS') { + my $method = ucfirst(lc($action)); + my $status = $comp->Configure($cfg); + ok($status, "$method can call the internal methods"); +}; + +done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_base_options.t b/aii-pxelinux/src/test/perl/pxelinux_ks_base_options.t new file mode 100644 index 00000000..2be58c57 --- /dev/null +++ b/aii-pxelinux/src/test/perl/pxelinux_ks_base_options.t @@ -0,0 +1,63 @@ +use strict; +use warnings; +use Test::More; +use Test::Quattor qw(pxelinux_ks_block); +use NCM::Component::PXELINUX::constants qw(:pxe_variants :pxe_constants); +use NCM::Component::pxelinux; +use CAF::FileWriter; +use CAF::Object; +use Sys::Hostname; +use Readonly; + +=pod + +=head1 SYNOPSIS + +Tests for the C<_write_xxx_config> methods with the basic KS options. + +=cut + +Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; +my $test_efi_initrd_cmd = $TEST_EFI_LINUX_CMD; +$test_efi_initrd_cmd =~ s/linux/initrd/; + +# Must be in the same order as variants in @PXE_VARIANTS +Readonly my @KERNEL_PARAMS_CMDS => ('append', GRUB2_EFI_LINUX_CMD_DEFAULT); +Readonly my @PXE_VARIANT_METHODS => ('_write_pxelinux_config', '_write_grub2_config'); +Readonly my @VARIANT_NAMES => ('PXELINUX', 'Grub2'); + +our $this_app = $main::this_app; +$this_app->{CONFIG}->define(GRUB2_EFI_LINUX_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_LINUX_CMD, $TEST_EFI_LINUX_CMD); +$this_app->{CONFIG}->define(GRUB2_EFI_INITRD_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $test_efi_initrd_cmd); + +# mock _filepath, it has this_app->option +my $fp = "target/test/pxelinux"; +my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); +$mockpxe->mock('_filepath', $fp); + +my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); +my $cfg = get_config_for_profile('pxelinux_ks_block'); +my $hostname = hostname(); + +for my $variant_constant (@PXE_VARIANTS) { + my $variant = __PACKAGE__->$variant_constant; + my $variant_name = $VARIANT_NAMES[$variant]; + my $config_method = $PXE_VARIANT_METHODS[$variant]; + my $kernel_params_cmd = $KERNEL_PARAMS_CMDS[$variant]; + + $comp->$config_method($cfg); + my $fh = get_file($fp); + + like($fh, qr{^\s{4}$kernel_params_cmd.*?\sramdisk=32768(\s|$)}m, "append ramdisk (variant=$variant_name)"); + if ( $variant == PXE_VARIANT_PXELINUX ) { + like($fh, qr{^\s{4}$kernel_params_cmd.*?\sinitrd=path/to/initrd(\s|$)}m, "append initrd (variant=$variant_name)"); + }; + like($fh, qr{^\s{4}$kernel_params_cmd.*?\sks=http://server/ks(\s|$)}m, "append ks url(variant=$variant_name)"); + like($fh, qr{^\s{4}$kernel_params_cmd.*?\sksdevice=eth0(\s|$)}m, "append ksdevice(variant=$variant_name)"); + like($fh, qr{^\s{4}$kernel_params_cmd.*?\supdates=http://somewhere/somthing/updates.img(\s|$)}m, "append ksdevice(variant=$variant_name)"); + like($fh, qr{^\s{4}$kernel_params_cmd.*?\sinst.stage2=http://$hostname/stage2.img}m, "hostname substitution in append(variant=$variant_name)"); +}; + +done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_block.t b/aii-pxelinux/src/test/perl/pxelinux_ks_block.t deleted file mode 100644 index 10039cf2..00000000 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_block.t +++ /dev/null @@ -1,42 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Quattor qw(pxelinux_ks_block); -use NCM::Component::pxelinux; -use CAF::FileWriter; -use CAF::Object; -use Sys::Hostname; - -=pod - -=head1 SYNOPSIS - -Tests for the C<_write_pxelinux_config> method. - -=cut - -$CAF::Object::NoAction = 1; - -# mock _filepath, it has this_app->option -my $fp = "target/test/pxelinux"; -my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); -$mockpxe->mock('_filepath', $fp); - -my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); -my $cfg = get_config_for_profile('pxelinux_ks_block'); - -$comp->_write_pxelinux_config($cfg); - -my $fh = get_file($fp); -my $hostname = hostname(); - -like($fh, qr{^default\sInstall\sScientific\sLinux\s6x\s\(x86_64\)}m, 'default kernel'); -like($fh, qr{^\s{4}label\sScientific\sLinux\s6x\s\(x86_64\)}m, 'label default kernel'); -like($fh, qr{^\s{4}kernel\smykernel}m, 'kernel mykernel'); -like($fh, qr{^\s{4}append\sramdisk=32768\sinitrd=path/to/initrd(\s|$)}m, 'append ramdisk and initrd'); -like($fh, qr{^\s{4}append.*?\sks=http://server/ks(\s|$)}m, 'append ks url'); -like($fh, qr{^\s{4}append.*?\sksdevice=eth0(\s|$)}m, 'append ksdevice'); -like($fh, qr{^\s{4}append.*?\supdates=http://somewhere/somthing/updates.img(\s|$)}m, 'append ksdevice'); -like($fh, qr{^\s{4}append.*?\sinst.stage2=http://$hostname/stage2.img}m, 'hostname substitution in append'); - -done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_bonding.t b/aii-pxelinux/src/test/perl/pxelinux_ks_bonding.t index 0f4810b8..027c2996 100644 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_bonding.t +++ b/aii-pxelinux/src/test/perl/pxelinux_ks_bonding.t @@ -1,20 +1,39 @@ use strict; use warnings; use Test::More; -use Test::Quattor qw(pxelinux_ks_bonding); +use Test::Quattor qw(pxelinux_ks_bonding pxelinux_ks_bonding_bridge); +use NCM::Component::PXELINUX::constants qw(:pxe_variants :pxe_constants); use NCM::Component::pxelinux; use CAF::FileWriter; use CAF::Object; +use Sys::Hostname; +use Readonly; =pod =head1 SYNOPSIS -Tests for the C<_write_pxelinux_config> method. +Tests for the C<_write_xxx_config> methods with bonding paramaters in KS options. =cut -$CAF::Object::NoAction = 1; +Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; +my $test_efi_initrd_cmd = $TEST_EFI_LINUX_CMD; +$test_efi_initrd_cmd =~ s/linux/initrd/; + +# Must be in the same order as variants in @PXE_VARIANTS +Readonly my @KERNEL_PARAMS_CMDS => ('append', GRUB2_EFI_LINUX_CMD_DEFAULT); +Readonly my @PXE_VARIANT_METHODS => ('_write_pxelinux_config', '_write_grub2_config'); +Readonly my @VARIANT_NAMES => ('PXELINUX', 'Grub2'); + +# List of configurations to test (must be added as Test::Quattor parameters) +Readonly my @TEST_PROFILES => ('pxelinux_ks_bonding', 'pxelinux_ks_bonding_bridge'); + +our $this_app = $main::this_app; +$this_app->{CONFIG}->define(GRUB2_EFI_LINUX_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_LINUX_CMD, $TEST_EFI_LINUX_CMD); +$this_app->{CONFIG}->define(GRUB2_EFI_INITRD_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $test_efi_initrd_cmd); # mock _filepath, it has this_app->option my $fp = "target/test/pxelinux"; @@ -22,21 +41,36 @@ my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); $mockpxe->mock('_filepath', $fp); my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); -my $cfg = get_config_for_profile('pxelinux_ks_bonding'); - -$comp->_write_pxelinux_config($cfg); - -my $fh = get_file($fp); - -# bonding opts -like($fh, qr{^\s{4}append\s.*?\sbond=bond0:eth0,eth1:(opt1=val1,opt2=val2|opt2=val2,opt1=val1)(\s|$)}m, 'append bond'); -# static ip settings from bond0, also bond0 is bootdev -like($fh, qr{^\s{4}append\s.*?\sip=1\.2\.3\.0::133\.2\.85\.1:255\.255\.255\.0:x.y:bond0:none(\s|$)}m, 'append static ip for bootdev bond0'); +for my $profile (@TEST_PROFILES) { + my $cfg = get_config_for_profile($profile); -# kickstart file should be fetched via ksdevice bond0 -# this is EL7, the EL6 test should be ksdevice=bond0 -like($fh, qr{^\s{4}append\s.*?\sbootdev=bond0(\s|$)}m, 'append set ksdevice/bootdev to bond0'); + for my $variant_constant (@PXE_VARIANTS) { + my $variant = __PACKAGE__->$variant_constant; + my $variant_name = $VARIANT_NAMES[$variant]; + my $config_method = $PXE_VARIANT_METHODS[$variant]; + my $kernel_params_cmd = $KERNEL_PARAMS_CMDS[$variant]; + + $comp->$config_method($cfg); + my $fh = get_file($fp); + + # bonding opts + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sbond=bond0:eth0,eth1:(opt1=val1,opt2=val2|opt2=val2,opt1=val1)(\s|$)}m, + "append bond ksdevice (profile=$profile, variant=$variant_name)"); + + # static ip settings from bond0, also bond0 is bootdev + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sip=1\.2\.3\.0::133\.2\.85\.1:255\.255\.255\.0:x.y:bond0:none(\s|$)}m, + "append static ip for bootdev bond0 ksdevice (profile=$profile, variant=$variant_name)"); + + # kickstart file should be fetched via ksdevice bond0 + # this is EL7, the EL6 test should be ksdevice=bond0 + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sbootdev=bond0(\s|$)}m, + "append set ksdevice/bootdev to bond0 ksdevice (profile=$profile, variant=$variant_name)"); + }; +}; done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_bonding_bridge.t b/aii-pxelinux/src/test/perl/pxelinux_ks_bonding_bridge.t deleted file mode 100644 index 96c0b4db..00000000 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_bonding_bridge.t +++ /dev/null @@ -1,44 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Quattor qw(pxelinux_ks_bonding_bridge); -use NCM::Component::pxelinux; -use CAF::FileWriter; -use CAF::Object; - -=pod - -=head1 SYNOPSIS - -Tests for the C<_write_pxelinux_config> method. - -=cut - -$CAF::Object::NoAction = 1; - -# mock _filepath, it has this_app->option -my $fp = "target/test/pxelinux"; -my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); -$mockpxe->mock('_filepath', $fp); - -my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); -my $cfg = get_config_for_profile('pxelinux_ks_bonding_bridge'); - -$comp->_write_pxelinux_config($cfg); - -my $fh = get_file($fp); - -# these tests are identical to the regular pxelinux_ks_bonding, but the ip is fetched from the br0 device - -# bonding opts -like($fh, qr{^\s{4}append\s.*?\sbond=bond0:eth0,eth1:(opt1=val1,opt2=val2|opt2=val2,opt1=val1)(\s|$)}m, 'append bond'); - -# static ip settings from bond0, also bond0 is bootdev -like($fh, qr{^\s{4}append\s.*?\sip=1\.2\.3\.0::133\.2\.85\.1:255\.255\.255\.0:x.y:bond0:none(\s|$)}m, 'append static ip for bootdev bond0'); - -# kickstart file should be fetched via ksdevice bond0 -# this is EL7, the EL6 test should be ksdevice=bond0 -like($fh, qr{^\s{4}append\s.*?\sbootdev=bond0(\s|$)}m, 'append set ksdevice/bootdev to bond0'); - - -done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_el7_static_ip.t b/aii-pxelinux/src/test/perl/pxelinux_ks_el7_static_ip.t index bdbc6f02..ca571fc9 100644 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_el7_static_ip.t +++ b/aii-pxelinux/src/test/perl/pxelinux_ks_el7_static_ip.t @@ -2,19 +2,38 @@ use strict; use warnings; use Test::More; use Test::Quattor qw(pxelinux_ks_el7_static_ip); +use NCM::Component::PXELINUX::constants qw(:pxe_variants :pxe_constants); use NCM::Component::pxelinux; use CAF::FileWriter; use CAF::Object; +use Sys::Hostname; +use Readonly; =pod =head1 SYNOPSIS -Tests for the C<_write_pxelinux_config> method. +Tests for the C<_write_xxx_config> methods with a static IP and logging parameters (EL7 config) =cut -$CAF::Object::NoAction = 1; +Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; +my $test_efi_initrd_cmd = $TEST_EFI_LINUX_CMD; +$test_efi_initrd_cmd =~ s/linux/initrd/; + +# Must be in the same order as variants in @PXE_VARIANTS +Readonly my @KERNEL_PARAMS_CMDS => ('append', GRUB2_EFI_LINUX_CMD_DEFAULT); +Readonly my @PXE_VARIANT_METHODS => ('_write_pxelinux_config', '_write_grub2_config'); +Readonly my @VARIANT_NAMES => ('PXELINUX', 'Grub2'); + +# List of configurations to test (must be added as Test::Quattor parameters) +Readonly my @TEST_PROFILES => ('pxelinux_ks_el7_static_ip'); + +our $this_app = $main::this_app; +$this_app->{CONFIG}->define(GRUB2_EFI_LINUX_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_LINUX_CMD, $TEST_EFI_LINUX_CMD); +$this_app->{CONFIG}->define(GRUB2_EFI_INITRD_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $test_efi_initrd_cmd); # mock _filepath, it has this_app->option my $fp = "target/test/pxelinux"; @@ -22,28 +41,63 @@ my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); $mockpxe->mock('_filepath', $fp); my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); -my $cfg = get_config_for_profile('pxelinux_ks_el7_static_ip'); - -$comp->_write_pxelinux_config($cfg); - -my $fh = get_file($fp); - -like($fh, qr{^\s{4}append\s.*?\sinst.syslog=logserver:514\sinst.loglevel=debug(\s|$)}m, 'append line logging'); -like($fh, qr{^\s{4}append\s.*?\sinst.ks=http://server/ks\sbootdev=eth0(\s|$)}m, 'append line ks and bootdev'); -# both nameservers -like($fh, qr{^\s{4}append\s.*?\snameserver=nm1(\s|$)}m, 'append nameserver 1'); -like($fh, qr{^\s{4}append\s.*?\snameserver=nm2(\s|$)}m, 'append nameserver 2'); -# both ifnames -like($fh, qr{^\s{4}append\s.*?\sifname=eth0:00:11:22:33:44:55(\s|$)}m, 'append ifname for 1st nic'); -like($fh, qr{^\s{4}append\s.*?\sifname=eth1:00:11:22:33:44:66(\s|$)}m, 'append ifname for 2nd nic'); -# static ip -like($fh, qr{^\s{4}append\s.*?\sip=133\.2\.85\.234::133\.2\.85\.1:255\.255\.255\.0:x.y:eth0:none(\s|$)}m, 'append static ip for bootdev'); -# enable sshd -like($fh, qr{^\s{4}append\s.*?\sinst.sshd(\s|$)}m, 'append enable sshd'); -# enable cmdline -like($fh, qr{^\s{4}append\s.*?\sinst.cmdline(\s|$)}m, 'append enable cmdline'); -# updates -like($fh, qr{^\s{4}append\s.*?\sinst.updates=http://somewhere/somthing/updates.img(\s|$)}m, 'append updates'); +for my $profile (@TEST_PROFILES) { + my $cfg = get_config_for_profile($profile); + + for my $variant_constant (@PXE_VARIANTS) { + my $variant = __PACKAGE__->$variant_constant; + my $variant_name = $VARIANT_NAMES[$variant]; + my $config_method = $PXE_VARIANT_METHODS[$variant]; + my $kernel_params_cmd = $KERNEL_PARAMS_CMDS[$variant]; + + $comp->$config_method($cfg); + my $fh = get_file($fp); + + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sinst.syslog=logserver:514\sinst.loglevel=debug(\s|$)}m, + "append line logging (profile=$profile, variant=$variant_name)"); + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sinst.ks=http://server/ks\sbootdev=eth0(\s|$)}m, + "append line ks and bootdev (profile=$profile, variant=$variant_name)"); + + # both nameservers + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\snameserver=nm1(\s|$)}m, + "append nameserver 1 (profile=$profile, variant=$variant_name)"); + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\snameserver=nm2(\s|$)}m, + "append nameserver 2 (profile=$profile, variant=$variant_name)"); + + # both ifnames + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sifname=eth0:00:11:22:33:44:55(\s|$)}m, + "append ifname for 1st nic (profile=$profile, variant=$variant_name)"); + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sifname=eth1:00:11:22:33:44:66(\s|$)}m, + "append ifname for 2nd nic (profile=$profile, variant=$variant_name)"); + + # static ip + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sip=133\.2\.85\.234::133\.2\.85\.1:255\.255\.255\.0:x.y:eth0:none(\s|$)}m, + "append static ip for bootdev (profile=$profile, variant=$variant_name)"); + + # enable sshd + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sinst.sshd(\s|$)}m, + "append enable sshd (profile=$profile, variant=$variant_name)"); + + # enable cmdline + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sinst.cmdline(\s|$)}m, + "append enable cmdline (profile=$profile, variant=$variant_name)"); + + # updates + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sinst.updates=http://somewhere/somthing/updates.img(\s|$)}m, + "append updates (profile=$profile, variant=$variant_name)"); + + }; +}; done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_ksdevice.t b/aii-pxelinux/src/test/perl/pxelinux_ks_ksdevice.t new file mode 100644 index 00000000..6e626794 --- /dev/null +++ b/aii-pxelinux/src/test/perl/pxelinux_ks_ksdevice.t @@ -0,0 +1,91 @@ +use strict; +use warnings; +use Test::More; +use Test::Quattor qw( + pxelinux_ks_ksdevice_bootif + pxelinux_ks_ksdevice_mac + pxelinux_ks_ksdevice_link + pxelinux_ks_ksdevice_systemd_scheme_1 + pxelinux_ks_ksdevice_systemd_scheme_2 + pxelinux_ks_ksdevice_systemd_scheme_3 + pxelinux_ks_ksdevice_systemd_scheme_4 +); +use NCM::Component::PXELINUX::constants qw(:pxe_variants :pxe_constants); +use NCM::Component::pxelinux; +use CAF::FileWriter; +use CAF::Object; +use Sys::Hostname; +use Readonly; + +=pod + +=head1 SYNOPSIS + +Tests for the C<_write_xxx_config> methods with explicit ksdevice definition. + +=cut + +Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; +my $test_efi_initrd_cmd = $TEST_EFI_LINUX_CMD; +$test_efi_initrd_cmd =~ s/linux/initrd/; + +# Must be in the same order as variants in @PXE_VARIANTS +Readonly my @KERNEL_PARAMS_CMDS => ('append', GRUB2_EFI_LINUX_CMD_DEFAULT); +Readonly my @PXE_VARIANT_METHODS => ('_write_pxelinux_config', '_write_grub2_config'); +Readonly my @VARIANT_NAMES => ('PXELINUX', 'Grub2'); + +# List of configuration file prefix and suffix to test (must match Test::Quattor parameters) +Readonly my @TEST_PROFILE_PREFIXES => ('pxelinux_ks_ksdevice', 'pxelinux_ks_ksdevice_systemd'); +Readonly my %TEST_PROFILE_SUFFIXES => (pxelinux_ks_ksdevice => ['bootif', 'mac', 'link'], + pxelinux_ks_ksdevice_systemd => ['scheme_1', 'scheme_2', 'scheme_3', 'scheme_4']); +Readonly my %TEST_PROFILE_KSDEVICES => (pxelinux_ks_ksdevice => ['bootif', 'AA:BB:CC:DD:EE:FF', 'link'], + pxelinux_ks_ksdevice_systemd => ['eno1', 'ens1', 'enp2s0', 'enx78e7d1ea46da']); + +our $this_app = $main::this_app; +$this_app->{CONFIG}->define(GRUB2_EFI_LINUX_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_LINUX_CMD, $TEST_EFI_LINUX_CMD); +$this_app->{CONFIG}->define(GRUB2_EFI_INITRD_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $test_efi_initrd_cmd); + +# mock _filepath, it has this_app->option +my $fp = "target/test/pxelinux"; +my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); +$mockpxe->mock('_filepath', $fp); + +my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); + +for my $profile_prefix (@TEST_PROFILE_PREFIXES) { + + my $i=0; + foreach my $suffix (@{$TEST_PROFILE_SUFFIXES{$profile_prefix}}) { + my $profile = $profile_prefix . '_' . $suffix; + my $cfg = get_config_for_profile($profile); + my $ksdevice = $TEST_PROFILE_KSDEVICES{$profile_prefix}[$i]; + + # Check that bonding is not defined for non standard devices (PXE variant agnostic) + my $bond = $comp->_pxe_network_bonding($cfg, {}, $ksdevice); + ok(! defined($bond), + "Bonding for unsupported device '$ksdevice' returns undef (profile=$profile)"); + + for my $variant_constant (@PXE_VARIANTS) { + my $variant = __PACKAGE__->$variant_constant; + my $variant_name = $VARIANT_NAMES[$variant]; + my $config_method = $PXE_VARIANT_METHODS[$variant]; + my $kernel_params_cmd = $KERNEL_PARAMS_CMDS[$variant]; + + # Check ksdevice is correctly defined + $comp->$config_method($cfg); + my $fh = get_file($fp); + like($fh, + qr{^\s{4}$kernel_params_cmd\s.*?\sksdevice=$ksdevice(\s|$)}m, + "ksdevice=$ksdevice (profile=$profile, variant=$variant_name)"); + if ( ($variant == PXE_VARIANT_PXELINUX) && ($suffix eq "bootif") ) { + like($fh, qr{^\s{4}ipappend\s2$}m, "ipappend 2 added (profile=$profile, variant=$variant_name)"); + }; + } + + $i++; + }; +}; + +done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_logging.t b/aii-pxelinux/src/test/perl/pxelinux_ks_logging.t index 9d531147..9eee4fe6 100644 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_logging.t +++ b/aii-pxelinux/src/test/perl/pxelinux_ks_logging.t @@ -1,20 +1,36 @@ use strict; use warnings; use Test::More; -use Test::Quattor qw(pxelinux_ks_logging); +use Test::Quattor qw(pxelinux_ks_logging pxelinux_ks_nologging_host); +use NCM::Component::PXELINUX::constants qw(:pxe_variants :pxe_constants); use NCM::Component::pxelinux; use CAF::FileWriter; use CAF::Object; +use Sys::Hostname; +use Readonly; =pod =head1 SYNOPSIS -Tests for the C<_write_pxelinux_config> method. +Tests for the C<_write_xxx_config> methods (logging related parameters). =cut -$CAF::Object::NoAction = 1; +Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; +my $test_efi_initrd_cmd = $TEST_EFI_LINUX_CMD; +$test_efi_initrd_cmd =~ s/linux/initrd/; + +# Must be in the same order as variants in @PXE_VARIANTS +Readonly my @KERNEL_PARAMS_CMDS => ('append', GRUB2_EFI_LINUX_CMD_DEFAULT); +Readonly my @PXE_VARIANT_METHODS => ('_write_pxelinux_config', '_write_grub2_config'); +Readonly my @VARIANT_NAMES => ('PXELINUX', 'Grub2'); + +our $this_app = $main::this_app; +$this_app->{CONFIG}->define(GRUB2_EFI_LINUX_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_LINUX_CMD, $TEST_EFI_LINUX_CMD); +$this_app->{CONFIG}->define(GRUB2_EFI_INITRD_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $test_efi_initrd_cmd); # mock _filepath, it has this_app->option my $fp = "target/test/pxelinux"; @@ -22,13 +38,38 @@ my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); $mockpxe->mock('_filepath', $fp); my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); + + +# Logging parameters specified + my $cfg = get_config_for_profile('pxelinux_ks_logging'); +for my $variant_constant (@PXE_VARIANTS) { + my $variant = __PACKAGE__->$variant_constant; + my $variant_name = $VARIANT_NAMES[$variant]; + my $config_method = $PXE_VARIANT_METHODS[$variant]; + my $kernel_params_cmd = $KERNEL_PARAMS_CMDS[$variant]; + + $comp->$config_method($cfg); + my $fh = get_file($fp); + + like($fh, qr{^\s{4}$kernel_params_cmd\s.*?\ssyslog=logserver:514\sloglevel=debug(\s|$)}m, "append line (variant=$variant_name)"); +}; -$comp->_write_pxelinux_config($cfg); -my $fh = get_file($fp); +# No logging host -like($fh, qr{^\s{4}append\s.*?\ssyslog=logserver:514\sloglevel=debug(\s|$)}m, 'append line'); +$cfg = get_config_for_profile('pxelinux_ks_nologging_host'); +for my $variant_constant (@PXE_VARIANTS) { + my $variant = __PACKAGE__->$variant_constant; + my $variant_name = $VARIANT_NAMES[$variant]; + my $config_method = $PXE_VARIANT_METHODS[$variant]; + my $kernel_params_cmd = $KERNEL_PARAMS_CMDS[$variant]; + $comp->$config_method($cfg); + my $fh = get_file($fp); + + unlike($fh, qr{\ssyslog}, "no syslog config (variant=$variant_name)"); + unlike($fh, qr{\sloglevel}, "no loglevel config (variant=$variant_name)"); +}; done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_nologging_host.t b/aii-pxelinux/src/test/perl/pxelinux_ks_nologging_host.t deleted file mode 100644 index 6d1aeaee..00000000 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_nologging_host.t +++ /dev/null @@ -1,35 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Quattor qw(pxelinux_ks_nologging_host); -use NCM::Component::pxelinux; -use CAF::FileWriter; -use CAF::Object; - -=pod - -=head1 SYNOPSIS - -Tests for the C<_write_pxelinux_config> method. - -=cut - -$CAF::Object::NoAction = 1; - -# mock _filepath, it has this_app->option -my $fp = "target/test/pxelinux"; -my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); -$mockpxe->mock('_filepath', $fp); - -my $comp = NCM::Component::pxelinux->new('pxelinux_ks'); -my $cfg = get_config_for_profile('pxelinux_ks_nologging_host'); - -$comp->_write_pxelinux_config($cfg); - -my $fh = get_file($fp); - -unlike($fh, qr{\ssyslog}, 'no syslog config'); -unlike($fh, qr{\sloglevel}, 'no loglevel config'); - - -done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_special_ksdevice.t b/aii-pxelinux/src/test/perl/pxelinux_ks_special_ksdevice.t deleted file mode 100644 index 4e835e25..00000000 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_special_ksdevice.t +++ /dev/null @@ -1,47 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Quattor qw(pxelinux_ks_ksdevice_bootif pxelinux_ks_ksdevice_mac pxelinux_ks_ksdevice_link); -use NCM::Component::pxelinux; -use CAF::FileWriter; -use CAF::Object; - -=pod - -=head1 SYNOPSIS - -Tests for the C<_write_pxelinux_config> method. - -=cut - -$CAF::Object::NoAction = 1; - -my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); - -my ($fp, $comp, $cfg, $bond, $fh, $search, $regtxt); -foreach my $type (("bootif", "link", "mac")) { - # mock _filepath, it has this_app->option - $fp = "target/test/pxelinux_$type"; - $mockpxe->mock('_filepath', $fp); - - $comp = NCM::Component::pxelinux->new('pxelinux_ks'); - $cfg = get_config_for_profile("pxelinux_ks_ksdevice_$type"); - - $search = $type; - $search = "AA:BB:CC:DD:EE:FF" if ($type eq "mac"); - - $bond = $comp->_pxe_network_bonding($cfg, {}, $search); - ok(! defined($bond), "Bonding for unsupported device $search returns undef"); - - $comp->_write_pxelinux_config($cfg); - - $fh = get_file($fp); - - $regtxt = '^\s{4}append\s.*?\sksdevice='.$search.'(\s|$)'; - like($fh, qr{$regtxt}m, "ksdevice=$search for ksdevice $type"); - if ($type eq "bootif") { - like($fh, qr{^\s{4}ipappend\s2$}m, "ipappend 2 for ksdevice $type"); - } -} - -done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_ks_systemd_ksdevice.t b/aii-pxelinux/src/test/perl/pxelinux_ks_systemd_ksdevice.t deleted file mode 100644 index 0a14e109..00000000 --- a/aii-pxelinux/src/test/perl/pxelinux_ks_systemd_ksdevice.t +++ /dev/null @@ -1,53 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Quattor qw( - pxelinux_ks_ksdevice_systemd_scheme_1 - pxelinux_ks_ksdevice_systemd_scheme_2 - pxelinux_ks_ksdevice_systemd_scheme_3 - pxelinux_ks_ksdevice_systemd_scheme_4 -); -use NCM::Component::pxelinux; -use CAF::FileWriter; -use CAF::Object; - -=pod - -=head1 SYNOPSIS - -Tests for the C<_write_pxelinux_config> method. - -=cut - -$CAF::Object::NoAction = 1; - -my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); - -my @scheme_data = qw(eno1 ens1 enp2s0 enx78e7d1ea46da); - -my ($fp, $comp, $cfg, $bond, $fh, $search, $regtxt); -foreach my $scheme (qw(1 2 3 4)) { - # mock _filepath, it has this_app->option - $fp = "target/test/pxelinux_$scheme"; - $mockpxe->mock('_filepath', $fp); - - $comp = NCM::Component::pxelinux->new('pxelinux_ks'); - $cfg = get_config_for_profile("pxelinux_ks_ksdevice_systemd_scheme_$scheme"); - - $search = $scheme_data[$scheme-1]; - - $bond = $comp->_pxe_network_bonding($cfg, {}, $search); - ok(! defined($bond), "Bonding for unsupported device $search returns undef"); - - $comp->_write_pxelinux_config($cfg); - - $fh = get_file($fp); - - $regtxt = '^\s{4}append\s.*?\sksdevice='.$search.'(\s|$)'; - like($fh, qr{$regtxt}m, "ksdevice=$search for ksdevice $scheme"); - if ($scheme eq "bootif") { - like($fh, qr{^\s{4}ipappend\s2$}m, "ipappend 2 for ksdevice $scheme"); - } -} - -done_testing(); diff --git a/aii-pxelinux/src/test/perl/pxelinux_no_append_block.t b/aii-pxelinux/src/test/perl/pxelinux_no_append_block.t deleted file mode 100644 index 55186243..00000000 --- a/aii-pxelinux/src/test/perl/pxelinux_no_append_block.t +++ /dev/null @@ -1,38 +0,0 @@ -use strict; -use warnings; -use Test::More; -use Test::Quattor qw(pxelinux_no_append_block); -use NCM::Component::pxelinux; -use CAF::FileWriter; -use CAF::Object; - -=pod - -=head1 SYNOPSIS - -Tests for the C<_write_pxelinux_config> method. - -=cut - -$CAF::Object::NoAction = 1; - -# mock _filepath, it has this_app->option -my $fp = "target/test/pxelinux"; -my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); -$mockpxe->mock('_filepath', $fp); - -my $comp = NCM::Component::pxelinux->new('pxelinux_no_append'); -my $cfg = get_config_for_profile('pxelinux_no_append_block'); - -$comp->_write_pxelinux_config($cfg); - -my $fh = get_file($fp); - -like($fh, qr{^default\sInstall\sScientific\sLinux\s6x\s\(x86_64\)}m, 'default kernel'); -like($fh, qr{^\s{4}label\sScientific\sLinux\s6x\s\(x86_64\)}m, 'label default kernel'); -like($fh, qr{^\s{4}kernel\smykernel}m, 'kernel mykernel'); - -unlike($fh, qr{^\s*append}m, 'no append line'); - - -done_testing(); diff --git a/aii-pxelinux/src/test/perl/write_grub2_config.t b/aii-pxelinux/src/test/perl/write_grub2_config.t index 69d0cdfd..4ff057f2 100644 --- a/aii-pxelinux/src/test/perl/write_grub2_config.t +++ b/aii-pxelinux/src/test/perl/write_grub2_config.t @@ -18,10 +18,11 @@ Tests for the C<_write_grub2_config> method. =cut -Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; -Readonly my $TEST_EFI_INITRD_CMD => 'initrdefi'; Readonly my $NBPDIR_GRUB2_VALUE => '/grub/config_files'; Readonly my $GRUB2_EFI_KERNEL_ROOT_VALUE => '/quat/or'; +Readonly my $TEST_EFI_LINUX_CMD => GRUB2_EFI_LINUX_CMD_DEFAULT; +my $test_efi_initrd_cmd = $TEST_EFI_LINUX_CMD; +$test_efi_initrd_cmd =~ s/linux/initrd/; $CAF::Object::NoAction = 1; @@ -43,8 +44,8 @@ sub check_config { like($fh, qr{^set timeout=\d+$}m, "Grub2 menu timeout ($test_msg)"); like($fh, qr(^menuentry\s"Install\s[\w\-\s\(\)\[\]]+"\s\{$)m, "Grub2 menu entry ($test_msg)"); like($fh, qr{^\s{4}set root=\(pxe\)$}m, "Grub2 root ($test_msg)"); - like($fh, qr{^\s{4}$TEST_EFI_LINUX_CMD $kernel_root/mykernel ks=http://server/ks ksdevice=eth0$}m, "Kernel loading ($test_msg)"); - like($fh, qr{^\s{4}$TEST_EFI_INITRD_CMD $kernel_root/path/to/initrd$}m, "initrd loading ($test_msg)"); + like($fh, qr{^\s{4}$TEST_EFI_LINUX_CMD $kernel_root/mykernel}m, "Kernel loading ($test_msg)"); + like($fh, qr{^\s{4}$test_efi_initrd_cmd $kernel_root/path/to/initrd$}m, "initrd loading ($test_msg)"); like($fh, qr(^})m, "end of menu entry ($test_msg)"); } @@ -57,7 +58,7 @@ my $cfg = get_config_for_profile('pxelinux_base_config'); $this_app->{CONFIG}->define(GRUB2_EFI_LINUX_CMD); $this_app->{CONFIG}->set(GRUB2_EFI_LINUX_CMD, $TEST_EFI_LINUX_CMD); $this_app->{CONFIG}->define(GRUB2_EFI_INITRD_CMD); -$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $TEST_EFI_INITRD_CMD); +$this_app->{CONFIG}->set(GRUB2_EFI_INITRD_CMD, $test_efi_initrd_cmd); $this_app->{CONFIG}->define(NBPDIR_GRUB2); $this_app->{CONFIG}->set(NBPDIR_GRUB2, $NBPDIR_GRUB2_VALUE); diff --git a/aii-pxelinux/src/test/perl/write_pxelinux_config.t b/aii-pxelinux/src/test/perl/write_pxelinux_config.t index bc05eff3..6e82c288 100644 --- a/aii-pxelinux/src/test/perl/write_pxelinux_config.t +++ b/aii-pxelinux/src/test/perl/write_pxelinux_config.t @@ -43,6 +43,7 @@ my $hostname = hostname(); like($fh, qr(^default\sInstall\s[\w\-\s\(\)\[\]]+$)m, 'PXELINUX menu entry'); like($fh, qr{^\s{4}label\s[\w\-\s\(\)\[\]]+$}m, 'Label properly defined'); like($fh, qr{^\s{4}kernel\smykernel$}m, 'Kernel properly defined'); +unlike($fh, qr{^\s*append}m, 'no append line'); done_testing();