forked from quattor/aii
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 quattor#258 (caused by a typo in the initial version of this commit)
- Loading branch information
Showing
15 changed files
with
426 additions
and
342 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,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(); |
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,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(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.