mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-12-04 08:07:04 +00:00
a2d889da3d
mknb writes the network boot scripts of an unknown client from my_nets and my_hexnets, both of which skip inet6 on Linux, and it builds every xcatd= value by concatenation. No test covers either, so an IPv6 management node gets no script, and an address written as xcatd=2001:db8:177::1:3001 reads as a valid literal with no port. mknb_xcatd_address.t stubbed the whole of xCAT::NetworkUtils, so the formatting helpers were absent from the harness and could not be measured. The three harnesses now load the real module and replace only the probes that read the running host's interfaces. The new assertions cover the nets/ scripts, the UEFI and elilo entries, the POWER URLs, the s390x APPEND line and the grub2 roots for one IPv6 network, and networkutils_my_nets6.t covers my_nets6 and the prefix masking. 16 of the mknb assertions fail on this commit, and the my_nets6 file does not run at all for lack of the subroutine. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
116 lines
4.7 KiB
Perl
116 lines
4.7 KiB
Perl
#!/usr/bin/env perl
|
|
# An unknown UEFI client with the upstream iPXE loader reads its discovery script from
|
|
# xcat/ipxe/nets. Nothing signs the Genesis kernel, so with Secure Boot on the script must name a
|
|
# shim, which verifies the kernel against the MOK list that the site enrolls. mknb writes the
|
|
# scripts into a scratch TFTP root. Tables and name resolution are stand-ins.
|
|
use strict;
|
|
use warnings;
|
|
## no critic (Modules::RequireFilenameMatchesPackage)
|
|
|
|
use File::Path qw(make_path);
|
|
use File::Slurper qw(read_text write_binary);
|
|
use File::Temp qw(tempdir);
|
|
use FindBin;
|
|
use lib "$FindBin::Bin/../../perl-xCAT";
|
|
use Test::More;
|
|
|
|
BEGIN {
|
|
package xCAT::Utils;
|
|
$INC{'xCAT/Utils.pm'} = __FILE__;
|
|
|
|
package xCAT::TableUtils;
|
|
our $tftpdir;
|
|
sub getTftpDir { return $tftpdir }
|
|
sub get_site_attribute { return $_[-1] eq 'master' ? ('master.example.com') : () }
|
|
$INC{'xCAT/TableUtils.pm'} = __FILE__;
|
|
|
|
# The real module is loaded so mknb's address formatting is the real one.
|
|
# Only the probes that read the running host's interfaces are replaced.
|
|
require xCAT::NetworkUtils;
|
|
package xCAT::NetworkUtils;
|
|
no warnings 'redefine'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
|
|
*my_nets = sub { return { '192.168.144.0/20' => ['192.168.148.10'] } };
|
|
*my_nets6 = sub { return {} };
|
|
*my_hexnets = sub { return { c0a89 => ['192.168.148.10'] } };
|
|
*getipaddr = sub { return ('203.0.113.10') };
|
|
*get_nic_ip = sub { return {} };
|
|
|
|
package xCAT::MsgUtils;
|
|
sub trace { return }
|
|
$INC{'xCAT/MsgUtils.pm'} = __FILE__;
|
|
|
|
package xCAT::Table;
|
|
sub new { return }
|
|
$INC{'xCAT/Table.pm'} = __FILE__;
|
|
|
|
package xCAT::NodeRange;
|
|
sub import {
|
|
my $caller = caller;
|
|
no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
|
|
*{"${caller}::noderange"} = sub { return };
|
|
return;
|
|
}
|
|
$INC{'xCAT/NodeRange.pm'} = __FILE__;
|
|
|
|
package main;
|
|
$INC{'xCAT_monitoring/monitorctrl.pm'} = __FILE__;
|
|
}
|
|
|
|
my $repo = "$FindBin::Bin/../..";
|
|
unshift @INC, "$repo/perl-xCAT", "$repo/xCAT-server/lib/perl";
|
|
require "$repo/xCAT-server/lib/xcat/plugins/mknb.pm"; ## no critic (Modules::RequireBarewordIncludes)
|
|
|
|
my $tmp = tempdir( CLEANUP => 1 );
|
|
$::XCATROOT = "$tmp/xcatroot";
|
|
make_path("$::XCATROOT/share/xcat/netboot/genesis/x86_64");
|
|
|
|
# What mknb needs in the TFTP root before it writes a configuration: the payload it boots, and the
|
|
# Secure Boot shim that ipxe-xcat installs.
|
|
sub prepare {
|
|
my (%opt) = @_;
|
|
$xCAT::TableUtils::tftpdir = "$tmp/$opt{name}";
|
|
make_path( "$xCAT::TableUtils::tftpdir/xcat", "$xCAT::TableUtils::tftpdir/etc" );
|
|
write_binary( "$xCAT::TableUtils::tftpdir/xcat/genesis.kernel.x86_64", '' );
|
|
write_binary( "$xCAT::TableUtils::tftpdir/xcat/genesis.fs.x86_64.gz", '' );
|
|
if ( $opt{shim} ) {
|
|
make_path("$xCAT::TableUtils::tftpdir/xcat/ipxe/x86_64-sb");
|
|
write_binary( "$xCAT::TableUtils::tftpdir/xcat/ipxe/x86_64-sb/shimx64.efi", 'shim' );
|
|
}
|
|
my @errors;
|
|
xCAT_plugin::mknb::process_request( { arg => [ 'x86_64', '--configfileonly' ] },
|
|
sub { push @errors, grep { ref eq 'HASH' && $_->{error} } @_; return } );
|
|
is_deeply( \@errors, [], "mknb writes the x86_64 configuration with shim=" . ( $opt{shim} ? 1 : 0 ) );
|
|
return;
|
|
}
|
|
|
|
sub script {
|
|
my ($relative) = @_;
|
|
return -f "$xCAT::TableUtils::tftpdir/$relative" ? read_text("$xCAT::TableUtils::tftpdir/$relative") : '';
|
|
}
|
|
|
|
prepare( name => 'tftpboot-shim', shim => 1 );
|
|
like(
|
|
script('xcat/ipxe/nets/192.168.144.0_20.uefi'),
|
|
qr{^imgload kernel\nshim http://\$\{next-server\}/tftpboot/xcat/ipxe/x86_64-sb/shimx64\.efi$}m,
|
|
'the UEFI discovery script names the shim of ipxe-xcat, after it selects the Genesis kernel'
|
|
);
|
|
like( script('xcat/ipxe/nets/192.168.144.0_20.uefi'), qr{^shim \S+\nimgargs kernel }m,
|
|
'and names it before the kernel runs' );
|
|
unlike( script('xcat/ipxe/nets/192.168.144.0_20'), qr{^shim }m,
|
|
'the BIOS discovery script names no shim' );
|
|
unlike( script('xcat/ipxe/nets/192.168.144.0_20.elilo'), qr{^shim }m,
|
|
'the elilo configuration names no shim' );
|
|
|
|
# mknb writes the discovery scripts of both methods in one loop. The loader of xnba does not know
|
|
# the shim command, so the line stops that script whether Secure Boot is on or off.
|
|
like( script('xcat/xnba/nets/192.168.144.0_20.uefi'), qr{^imgload kernel$}m,
|
|
'mknb writes the UEFI discovery script of the xnba method as well' );
|
|
unlike( script('xcat/xnba/nets/192.168.144.0_20.uefi'), qr{^shim }m,
|
|
'and that script names no shim, while the shim of ipxe-xcat is on disk' );
|
|
|
|
prepare( name => 'tftpboot-noshim', shim => 0 );
|
|
unlike( script('xcat/ipxe/nets/192.168.144.0_20.uefi'), qr{^shim }m,
|
|
'a server without the ipxe-xcat shim names no shim' );
|
|
|
|
done_testing();
|