From f93367daaeeab305a60cce2fd3bccedb4bb03400 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 8 Nov 2026 22:47:41 -0300 Subject: [PATCH] test(xcat-core): Ubuntu genimage leaves the online hook out of the dracut module On Ubuntu 26.04 genimage stops with "dracut[F]: Cannot install a hook (.../97xcat/xcat-online.sh) that does not exist". install.netboot hooks xcat-online.sh into initqueue/online, but mkinitrd_dracut in the Ubuntu genimage copies a fixed file list into 97xcat, and that list does not name xcat-online.sh. The stateless image gets no initrd and no kernel, so nodeset fails and the node never boots. This commit moves the copy into imgutils::stage_dracut_module, with the same file list, so a unit test can call it. The test stages each mode from the source tree and checks that every file the staged install script gives to inst_hook is in the module. It fails on xcat-online.sh. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> (cherry picked from commit 4155d98dc35a65d5d6721298bf9c2c89428a29fa) Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../share/xcat/netboot/imgutils/imgutils.pm | 37 +++++++++++++ .../share/xcat/netboot/ubuntu/genimage | 34 +----------- .../unit/imgutils_ubuntu_dracut_module.t | 52 +++++++++++++++++++ 3 files changed, 90 insertions(+), 33 deletions(-) create mode 100644 xCAT-test/unit/imgutils_ubuntu_dracut_module.t diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9a2bf36590..fecf922f24 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -284,6 +284,43 @@ sub disable_auto_profiles { return; } +#------------------------------------------------------------------------------- + +=head3 stage_dracut_module + + Descriptions: + Copies the files of the Ubuntu xCAT dracut module for a mode into the module directory + of an image. The install script of the mode is copied as "install". + Arguments: + $srcdir: the dracut directory under share/xcat/netboot/ubuntu + $moduledir: the 97xcat directory in the image + $mode: statelite or stateless + Returns: + the names of the files copied; dies on an unknown mode or a failed copy + +=cut + +#------------------------------------------------------------------------------- +sub stage_dracut_module { + my ($srcdir, $moduledir, $mode) = @_; + my %files = ( + statelite => [qw(xcat-prepivot.sh)], + stateless => [qw(xcat-cmdline.sh xcatroot installkernel)], + ); + die("Error: the mode $mode is not supported by genimage\n") unless $files{$mode}; + my $install = $mode eq 'statelite' ? 'install.statelite' : 'install.netboot'; + my @copy = (['check', 'check'], [$install, 'install']); + push(@copy, ['module-setup.sh', 'module-setup.sh']) if -f "$srcdir/module-setup.sh"; + push(@copy, map { [$_, $_] } @{ $files{$mode} }); + foreach my $pair (@copy) { + my ($from, $to) = ("$srcdir/$pair->[0]", "$moduledir/$pair->[1]"); + my $perm = (stat($from))[2]; + (defined($perm) && File::Copy::copy($from, $to) && chmod($perm & 07777, $to)) + or die("Error: cannot copy $from to $to: $!\n"); + } + return map { $_->[1] } @copy; +} + # The netboot dracut.conf names an exclusive module list, so a module nothing in the list depends # on is left out of the initial ramdisk. dracut reads the list and nothing else. # diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index cd8a306549..c2dcb94f50 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -994,14 +994,7 @@ sub mkinitrd_dracut { my $uftp_receiver = eval { imgutils::add_uftp_receiver($rootimg_dir, $arch, $dracutmpath, $mode eq 'stateless') }; xdie($@) if $@; - my $perm = (stat("$fullpath/$dracutdir/check"))[2]; - cp("$fullpath/$dracutdir/check", $dracutmpath); - chmod($perm & 07777, "$dracutmpath/check"); - if (-f "$fullpath/$dracutdir/module-setup.sh") { - $perm = (stat("$fullpath/$dracutdir/module-setup.sh"))[2]; - cp("$fullpath/$dracutdir/module-setup.sh", $dracutmpath); - chmod($perm & 07777, "$dracutmpath/module-setup.sh"); - } + imgutils::stage_dracut_module("$fullpath/$dracutdir", $dracutmpath, $mode); foreach (@ndrivers) { s/\.ko$//; } @@ -1010,15 +1003,6 @@ sub mkinitrd_dracut { if ($mode eq "statelite") { - # for statelite - cp("$fullpath/$dracutdir/install.statelite", "$dracutmpath/install"); - $perm = (stat("$fullpath/$dracutdir/install.statelite"))[2]; - chmod($perm & 07777, "$dracutmpath/install"); - - cp("$fullpath/$dracutdir/xcat-prepivot.sh", $dracutmpath); - $perm = (stat("$fullpath/$dracutdir/xcat-prepivot.sh"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-prepivot.sh"); - # update etc/dracut.conf my $dracutmodulelist = imgutils::dracut_netboot_modules(dirname($dracutmpath), -x "$rootimg_dir/usr/sbin/wicked"); open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); @@ -1027,14 +1011,6 @@ sub mkinitrd_dracut { print $DRACUTCONF qq{filesystems+=" nfs "\n}; close $DRACUTCONF; } elsif ($mode eq "stateless") { - cp("$fullpath/$dracutdir/install.netboot", "$dracutmpath/install"); - $perm = (stat("$fullpath/$dracutdir/install.netboot"))[2]; - chmod($perm & 07777, "$dracutmpath/install"); - - cp("$fullpath/$dracutdir/xcat-cmdline.sh", "$dracutmpath/"); - $perm = (stat("$fullpath/$dracutdir/xcat-cmdline.sh"))[2]; - chmod($perm & 07777, "$dracutmpath/xcat-cmdline.sh"); - if ($prinic) { my $optspec; open($optspec, '>>', "$dracutmpath/xcat-cmdline.sh"); @@ -1042,14 +1018,6 @@ sub mkinitrd_dracut { close $optspec; } - cp("$fullpath/$dracutdir/xcatroot", "$dracutmpath/"); - $perm = (stat("$fullpath/$dracutdir/xcatroot"))[2]; - chmod($perm & 07777, "$dracutmpath/xcatroot"); - - cp("$fullpath/$dracutdir/installkernel", "$dracutmpath/"); - $perm = (stat("$fullpath/$dracutdir/installkernel"))[2]; - chmod($perm & 07777, "$dracutmpath/installkernel"); - # update etc/dracut.conf my $dracutmodulelist = imgutils::dracut_netboot_modules(dirname($dracutmpath), -x "$rootimg_dir/usr/sbin/wicked"); open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); diff --git a/xCAT-test/unit/imgutils_ubuntu_dracut_module.t b/xCAT-test/unit/imgutils_ubuntu_dracut_module.t new file mode 100644 index 0000000000..11eac2d6c3 --- /dev/null +++ b/xCAT-test/unit/imgutils_ubuntu_dracut_module.t @@ -0,0 +1,52 @@ +#!/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 files that the install script $install gives to inst_hook, relative to its module. +# dracut stops the build with "Cannot install a hook ... that does not exist" when one is absent. +sub hook_files { + my ($install) = @_; + return map { m{inst_hook\s+\S+\s+\d+\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 hooks in"); + } +} + +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();