Skip to content

Commit

Permalink
aii-pxelinux: add unit tests for Grub2 configuration
Browse files Browse the repository at this point in the history
- Also replace pxelinux_no_append.pan by pxelinux_config_common and
  adjust unit tests accordingly
  • Loading branch information
jouvin committed Mar 1, 2017
1 parent bfac2a1 commit 17c5cf7
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 0 deletions.
46 changes: 46 additions & 0 deletions aii-pxelinux/src/test/perl/filepath.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use strict;
use warnings;
use Test::More;
use Test::Quattor qw(pxelinux_base_config);
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<filepath> method.
=cut

$CAF::Object::NoAction = 1;

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');

my $pxe_file_path;

$pxe_file_path = NCM::Component::pxelinux::filepath($cfg, PXE_VARIANT_PXELINUX);
is($pxe_file_path, "$NBPDIR_PXELINUX_VALUE/x.y.cfg", "PXE config file path ok for PXELINUX");

$pxe_file_path = NCM::Component::pxelinux::filepath($cfg, PXE_VARIANT_GRUB2);
is($pxe_file_path, "$NBPDIR_GRUB2_VALUE/x.y.cfg", "PXE config file path ok for Grub2");


done_testing();
32 changes: 32 additions & 0 deletions aii-pxelinux/src/test/perl/hexip_filename.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use strict;
use warnings;
use Test::More;
use Test::Quattor;
use NCM::Component::PXELINUX::constants qw(:pxe_variants);
use NCM::Component::pxelinux;
use CAF::FileWriter;
use CAF::Object;


=pod
=head1 SYNOPSIS
Tests for the C<hexip_filename> method.
=cut

$CAF::Object::NoAction = 1;

our $this_app = $main::this_app;

my $ip = "133.2.85.234";

my $hepix_str = NCM::Component::pxelinux::hexip_filename($ip, PXE_VARIANT_PXELINUX);
is($hepix_str, "850255EA", "filename from IP (PXELINUX variant)");

$hepix_str = NCM::Component::pxelinux::hexip_filename($ip, PXE_VARIANT_GRUB2);
is($hepix_str, "grub.cfg-850255EA", "filename from IP (Grub2 variant)");


done_testing();
66 changes: 66 additions & 0 deletions aii-pxelinux/src/test/perl/pxelink.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use strict;
use warnings;
use Test::More;
use Test::Quattor qw(pxelinux_base_config);
use NCM::Component::PXELINUX::constants qw(:all);
use NCM::Component::pxelinux;
use CAF::FileWriter;
use CAF::Object;
use Sys::Hostname;
use Readonly;


=pod
=head1 SYNOPSIS
Tests for the C<pxelink> method.
=cut

sub pxelink_test {
my ($cfg, $command, $pxe_variant, $pxe_variant_name) = @_;
unless ( defined($command) ) {
$command = "";
}

my $pxelink_status = NCM::Component::pxelinux::pxelink($cfg, $command, $pxe_variant);
is($pxelink_status, 1, "pxelink ok for $pxe_variant_name (command=$command)");
}

$CAF::Object::NoAction = 1;

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);
$this_app->{CONFIG}->define(LOCALBOOT);
$this_app->{CONFIG}->set(LOCALBOOT, LOCAL_BOOT_CONFIG_FILE);

my $comp = NCM::Component::pxelinux->new('grub2_config');
my $cfg = get_config_for_profile('pxelinux_base_config');

# PXELINUX variant
pxelink_test($cfg, CONFIGURE, PXE_VARIANT_PXELINUX, "PXELINUX");
pxelink_test($cfg, BOOT, PXE_VARIANT_PXELINUX, "PXELINUX");
pxelink_test($cfg, INSTALL, PXE_VARIANT_PXELINUX, "PXELINUX");
pxelink_test($cfg, FIRMWARE, PXE_VARIANT_PXELINUX, "PXELINUX");
pxelink_test($cfg, LIVECD, PXE_VARIANT_PXELINUX, "PXELINUX");
pxelink_test($cfg, RESCUE, PXE_VARIANT_PXELINUX, "PXELINUX");

# PXELINUX variant
pxelink_test($cfg, CONFIGURE, PXE_VARIANT_GRUB2, "Grub2");
pxelink_test($cfg, BOOT, PXE_VARIANT_GRUB2, "Grub2");
pxelink_test($cfg, INSTALL, PXE_VARIANT_GRUB2, "Grub2");
pxelink_test($cfg, FIRMWARE, PXE_VARIANT_GRUB2, "Grub2");
pxelink_test($cfg, LIVECD, PXE_VARIANT_GRUB2, "Grub2");
pxelink_test($cfg, RESCUE, PXE_VARIANT_GRUB2, "Grub2");


done_testing();
70 changes: 70 additions & 0 deletions aii-pxelinux/src/test/perl/write_grub2_config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use strict;
use warnings;
use Test::More;
use Test::Quattor qw(pxelinux_base_config);
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_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';

$CAF::Object::NoAction = 1;

our $this_app = $main::this_app;


sub check_config {
my ($cfg, $kernel_root, $test_msg) = @_;

NCM::Component::pxelinux::write_grub2_config($cfg);

# Retrieve config file name matching the configuration
my $fp = NCM::Component::pxelinux::filepath($cfg, PXE_VARIANT_GRUB2);

# Check config file contents
my $fh = get_file($fp);
my $hostname = hostname();
like($fh, qr{^set default=0$}m, "default kernel ($test_msg)");
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(^})m, "end of menu entry ($test_msg)");
}


my $comp = NCM::Component::pxelinux->new('grub2_config');
my $cfg = get_config_for_profile('pxelinux_base_config');

# Define a few AII options related to Grub2 support
# Normally done by aii-shellfe
$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}->define(NBPDIR_GRUB2);
$this_app->{CONFIG}->set(NBPDIR_GRUB2, $NBPDIR_GRUB2_VALUE);

check_config($cfg, '', 'No GRUB2_EFI_KERNEL_ROOT');

$this_app->{CONFIG}->define(GRUB2_EFI_KERNEL_ROOT);
$this_app->{CONFIG}->set(GRUB2_EFI_KERNEL_ROOT, $GRUB2_EFI_KERNEL_ROOT_VALUE);
check_config($cfg, $GRUB2_EFI_KERNEL_ROOT_VALUE, 'No GRUB2_EFI_KERNEL_ROOT');

done_testing();
48 changes: 48 additions & 0 deletions aii-pxelinux/src/test/perl/write_pxelinux_config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use strict;
use warnings;
use Test::More;
use Test::Quattor qw(pxelinux_base_config);
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.
=cut

Readonly my $NBPDIR_PXELINUX_VALUE => '/pxe/linux/conf.files';

$CAF::Object::NoAction = 1;

our $this_app = $main::this_app;

# Define a few AII options related to Grub2 support
# Normally done by aii-shellfe
$this_app->{CONFIG}->define(NBPDIR_PXELINUX);
$this_app->{CONFIG}->set(NBPDIR_PXELINUX, $NBPDIR_PXELINUX_VALUE);

my $comp = NCM::Component::pxelinux->new('grub2_config');
my $cfg = get_config_for_profile('pxelinux_base_config');

NCM::Component::pxelinux::write_pxelinux_config($cfg);

# Retrieve config file name matching the configuration
my $fp = NCM::Component::pxelinux::filepath($cfg, PXE_VARIANT_PXELINUX);

# Check config file contents
my $fh = get_file($fp);
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');


done_testing();
8 changes: 8 additions & 0 deletions aii-pxelinux/src/test/resources/pxelinux_base_config.pan
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
Basic object template for aii-pxelinux unit tests.
Only include pxelinux_config.common.pan
}

object template pxelinux_base_config;

include 'pxelinux_config_common';
34 changes: 34 additions & 0 deletions aii-pxelinux/src/test/resources/pxelinux_config_common.pan
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@{
Base configuration for pxelinux tests.
To be included in object templates actually used with tests.
@}
unique template pxelinux_config_common;

include 'quattor/aii/pxelinux/schema';

bind "/system/aii/nbp/pxelinux" = structure_pxelinux_pxe_info;

prefix "/system/network";
"hostname" = 'x';
"domainname" = 'y';
"nameserver/0" = 'nm1';
"nameserver/1" = 'nm2';
"default_gateway" = "133.2.85.1";
"interfaces/eth0/ip" = "133.2.85.234";
"interfaces/eth0/netmask" = "255.255.255.0";

prefix "/hardware/cards/nic";
"eth0/hwaddr" = "00:11:22:33:44:55";
"eth1/hwaddr" = "00:11:22:33:44:66";


prefix "/system/aii/nbp/pxelinux";
"initrd" = "path/to/initrd";
"kernel" = 'mykernel';
"label" = "Scientific Linux 6x (x86_64)";
"ksdevice" = "eth0";
"kslocation" = "http://server/ks";
"firmware" = "firmware.cfg";
"livecd" = "livecd.cfg";
"rescue" = "rescue.cfg";

0 comments on commit 17c5cf7

Please sign in to comment.