2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00
Files
xcat-core/xCAT-test/unit/imgutils_ubuntu_dracut_module.t
T
Daniel Hilst 9273a68368 test(xcat-core): the Ubuntu 26.04 netboot initramfs never gets a lease
ubuntu_netboot_initqueue.bats captures two defects in the Ubuntu dracut
module. The boot NIC gets no DHCPv4 lease, because nothing turns on
DHCP for the 70-BOOTIF.network file that systemd-network-generator
writes from BOOTIF=. And xcat-cmdline.sh writes its finished condition
outside $hookdir, so dracut-initqueue ends before the settled hook
that fetches the root runs. Both new cases fail on this tree.

imgutils_ubuntu_dracut_module.t now also checks the inst_simple
sources of the install script.

ubuntu_netboot_root_handler.bats sourced the online hook from sh. On
an Ubuntu host sh is dash, whose "." passes no arguments, so two cases
failed there. The initramfs sh is bash, so the cases now use bash.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
(cherry picked from commit 22cf6d78573f3df38c5d395dde4f50fc5c7a3640)
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-11-12 23:42:48 -03:00

54 lines
2.2 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use Cwd qw(realpath);
use File::Path qw(make_path);
use File::Slurper qw(read_text);
use File::Temp qw(tempdir);
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use Test::More;
use imgutils;
my $tmp = realpath(tempdir(CLEANUP => 1));
my $srcdir = realpath("$FindBin::Bin/../../xCAT-server/share/xcat/netboot/ubuntu/dracut");
# Returns the module files that the install script $install gives to inst_hook or inst_simple.
# dracut stops the build with "Cannot install a hook ... that does not exist" when a hook is absent,
# and leaves a missing inst_simple source out of the initial ramdisk.
sub hook_files {
my ($install) = @_;
return map { m{^\s*inst_(?:hook\s+\S+\s+\d+|simple)\s+"\$moddir/([^"]+)"} ? $1 : () } split(/\n/, read_text($install));
}
foreach my $mode (qw(stateless statelite)) {
my $moduledir = "$tmp/$mode/97xcat";
make_path($moduledir);
my @staged = imgutils::stage_dracut_module($srcdir, $moduledir, $mode);
ok(-f "$moduledir/install", "the $mode module gets its install script");
ok(-x "$moduledir/check", "the $mode module gets an executable check script");
is_deeply([sort @staged], [sort map { -e "$moduledir/$_" ? $_ : () } @staged], "every file the $mode module reports is in the module");
my @hooks = hook_files("$moduledir/install");
ok(scalar(@hooks), "the $mode install script installs a hook");
foreach my $hook (@hooks) {
ok(-f "$moduledir/$hook", "the $mode module carries $hook, which its install script installs");
}
}
my $stateless = "$tmp/stateless/97xcat";
ok(-x "$stateless/xcat-online.sh", 'the stateless module carries the executable online hook that fetches the root');
ok(-x "$stateless/xcatroot", 'the stateless module carries xcatroot');
eval { imgutils::stage_dracut_module($srcdir, "$tmp/bad", 'diskful') };
like($@, qr/the mode diskful is not supported/, 'an unknown mode is refused');
eval { imgutils::stage_dracut_module($srcdir, "$tmp/no-such-dir", 'stateless') };
like($@, qr{cannot copy \Q$srcdir\E/check to \Q$tmp\E/no-such-dir/check}, 'a failed copy stops genimage');
done_testing();