From 103076c8522d2d1c59517d00910d0c97f139aab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:08:42 -0300 Subject: [PATCH 01/45] fix(debian): skip service actions inside proc-mounted chroots --- perl-xCAT/debian/postrm | 3 ++- xCAT-server/debian/prerm | 4 +++- xCATsn/debian/postinst | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/perl-xCAT/debian/postrm b/perl-xCAT/debian/postrm index 6b983d64c7..b5617e6d6a 100644 --- a/perl-xCAT/debian/postrm +++ b/perl-xCAT/debian/postrm @@ -21,7 +21,8 @@ set -e case "$1" in upgrade) - if [ -x /opt/xcat/sbin/restartxcatd ] && [ -f "/proc/cmdline" ]; then + if [ -x /opt/xcat/sbin/restartxcatd ] && [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then . /etc/profile.d/xcat.sh XCATROOT=/opt/xcat /opt/xcat/sbin/restartxcatd -r fi diff --git a/xCAT-server/debian/prerm b/xCAT-server/debian/prerm index d0b466a4f9..9228fcc2f6 100644 --- a/xCAT-server/debian/prerm +++ b/xCAT-server/debian/prerm @@ -21,7 +21,8 @@ xcatd_init_compat=/opt/xcat/share/xcat/scripts/xcatd-init-compat case "$1" in remove) - if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image + if [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then if "$xcatd_init_compat" can-use-systemctl; then systemctl stop xcatd.service systemctl disable --now xcat-uftp-listener.service >/dev/null 2>&1 || true @@ -32,6 +33,7 @@ case "$1" in if "$xcatd_init_compat" uses-systemd --explicit-target; then if command -v systemctl >/dev/null 2>&1; then systemctl disable xcatd.service + systemctl disable xcat-uftp-listener.service >/dev/null 2>&1 || true fi else if command -v update-rc.d >/dev/null 2>&1; then diff --git a/xCATsn/debian/postinst b/xCATsn/debian/postinst index f674fb7eb8..7621b07495 100644 --- a/xCATsn/debian/postinst +++ b/xCATsn/debian/postinst @@ -64,7 +64,8 @@ case "$1" in a2enmod -q headers >/dev/null 2>&1 || : fi - if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image + if [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then systemctl start xcatd.service elif [ -x /etc/init.d/xcatd ]; then From b6f9294a792ef623dcad7b2eff2a4f424f05d1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:11:34 -0300 Subject: [PATCH 02/45] test(debian): exercise service callers in proc-mounted chroots --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/debian_chroot_services.t | 147 ++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/debian_chroot_services.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 629fc208f0..a7086fc57f 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -15,7 +15,7 @@ jobs: - name: Install lifecycle test dependencies run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests ucf debconf-utils systemd libxml-simple-perl apache2 curl - name: Test Debian package lifecycle - run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t xCAT-test/native/profile_package_payload.t + run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/debian_chroot_services.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t xCAT-test/native/profile_package_payload.t - name: Test optional statelite host keys if: ${{ !cancelled() }} run: prove -v xCAT-test/native/statelite_optional_hostkey.t diff --git a/xCAT-test/native/debian_chroot_services.t b/xCAT-test/native/debian_chroot_services.t new file mode 100644 index 0000000000..10362f1581 --- /dev/null +++ b/xCAT-test/native/debian_chroot_services.t @@ -0,0 +1,147 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use Test::More; +use File::Path qw(make_path); +use XCAT::Test::Lifecycle; + +plan skip_all => 'Run as an ordinary user on Debian or Ubuntu' + unless $^O eq 'linux' && $< != 0 && -f '/etc/debian_version'; +my %packages = map { $_ => XCAT::Test::Lifecycle::build_deb($_) } + qw(xCAT-server xCATsn); + +sub succeeds { + my ($label, @result) = @_; + is($result[0], 0, $label) or diag "$result[1]$result[2]"; +} + +for my $mode (qw(without-proc live proc-chroot systemd-chroot)) { + subtest $mode => sub { + my $root = XCAT::Test::Lifecycle->new; + $root->{live} = $mode ne 'without-proc'; + $root->{chroot} = $mode =~ /chroot/ ? 1 : 0; + my $active = $mode eq 'live'; + { + local $root->{deb} = $packages{'xCAT-server'}; + succeeds('unpack the server payload', $root->run('dpkg-deb', '-x', '/package.deb', '/unpacked')); + } + make_path(map { $root->path($_) } qw(/opt/xcat/lib /opt/xcat/sbin /opt/xcat/share/xcat /etc/apache2/conf-enabled)); + succeeds('stage packaged helpers', $root->run('cp', '-a', + '/unpacked/opt/xcat/share/xcat/scripts', '/opt/xcat/share/xcat/')); + succeeds('stage the packaged fast-restart command', $root->run('cp', + '/unpacked/opt/xcat/sbin/restartxcatd', '/opt/xcat/sbin/')); + symlink '/source/perl-xCAT', $root->path('/opt/xcat/lib/perl') or die "link Perl modules: $!"; + $root->write('/etc/os-release', $mode eq 'systemd-chroot' + ? "ID=ubuntu\nVERSION_ID=24.04\n" : "ID=ubuntu\nVERSION_ID=14.04\n"); + make_path($root->path('/run/systemd/system')) if $mode eq 'systemd-chroot'; + succeeds('install the packaged legacy init script', $root->run('cp', + '/opt/xcat/share/xcat/scripts/xcatd', '/etc/init.d/xcatd')); + if ($mode eq 'systemd-chroot') { + for my $service (qw(xcatd xcat-uftp-listener)) { + succeeds("stage the $service unit", $root->run('cp', + "/unpacked/lib/systemd/system/$service.service", '/usr/lib/systemd/system/')); + succeeds("enable $service in the image", $root->run('systemctl', 'enable', "$service.service")); + ok(-l $root->path("/etc/systemd/system/multi-user.target.wants/$service.service"), + "$service starts with an enabled link"); + } + } else { + succeeds('register xcatd in the image', $root->run('update-rc.d', 'xcatd', 'defaults')); + my @enabled = glob $root->path('/etc/rc?.d/S??xcatd'); + ok(@enabled, 'xcatd starts with enabled runlevels'); + } + $root->write('/etc/profile.d/xcat.sh', + "export XCATROOT=/opt/xcat\nexport PATH=/opt/xcat/sbin:/usr/sbin:/usr/bin:/sbin:/bin\n"); + unlink $root->path('/usr/sbin/policy-rc.d') or die "unlink policy fixture: $!" + if -l $root->path('/usr/sbin/policy-rc.d'); + $root->write('/usr/sbin/policy-rc.d', <<'SH', oct('755')); +#!/bin/sh +printf '%s\n' "$*" >> /policy-calls +exit 101 +SH + $root->record_command('/opt/xcat/sbin/xcatd'); + $root->record_command('/etc/init.d/apache2'); + $root->write('/etc/init.d/apache2', $root->read('/etc/init.d/apache2') . <<'SH', oct('755')); +### BEGIN INIT INFO +# Provides: apache2 +# Required-Start: $network +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Apache command boundary +### END INIT INFO +SH + succeeds('register the Apache dependency', $root->run('update-rc.d', 'apache2', 'defaults')); + $root->write('/calls', ''); + if ($root->{chroot}) { + succeeds('proc is mounted inside a different process root', $root->run('/bin/sh', '-c', + q{test -f /proc/cmdline && test "$(stat -c '%d:%i' /)" != "$(stat -c '%d:%i' /proc/1/root/.)"})); + } + if ($mode ne 'systemd-chroot') { + succeeds('native service policy denies an explicit start', + $root->run('invoke-rc.d', 'xcatd', 'start')); + is($root->read('/calls'), '', 'the policy control cannot reach the daemon'); + like($root->read('/policy-calls'), qr/xcatd.*start/, 'the native dispatcher consulted policy'); + } + succeeds('configure the service-node package', + $root->deb_script($packages{'xCATsn'}, 'postinst', 'configure')); + is($root->read('/calls'), $active + ? "xcatd <-p> \napache2 \n" : '', + 'only the live root starts xcatd and reloads Apache'); + $root->write('/calls', ''); + succeeds('upgrade the Perl package through the real fast-restart command', + $root->run('/bin/sh', '/source/perl-xCAT/debian/postrm', 'upgrade', '2.20.0')); + is($root->read('/calls'), $active ? "xcatd <-p> \n" : '', + 'only the live root reaches xcatd through restartxcatd'); + + $root->write('/sentinel.pl', <<'PERL'); +use strict; +use warnings; +$0 = 'xcatd: lifecycle sentinel'; +$SIG{TERM} = sub { open(my $fh, '>', '/stopped') or die $!; print {$fh} "TERM\n"; close($fh); exit 0; }; +open(my $pid, '>', '/var/run/xcatd.pid') or die $!; +print {$pid} "$$\n"; +close($pid) or die $!; +sleep 1 while 1; +PERL + local $root->{deb} = $packages{'xCAT-server'}; + succeeds('unpack the server control scripts', + $root->run('dpkg-deb', '-e', '/package.deb', '/tmp/server-control')); + succeeds('remove the server while an isolated process is running', + $root->run('/bin/sh', '-c', <<'SH', 'remove', $active ? 'live' : 'image')); +set -eu +mkdir -p /var/run +perl /sentinel.pl & +daemon=$! +trap 'kill -KILL "$daemon" 2>/dev/null || :; wait "$daemon" 2>/dev/null || :' EXIT +attempt=0 +until test -s /var/run/xcatd.pid; do + attempt=$((attempt + 1)) + test "$attempt" -lt 100 || exit 20 + sleep .05 +done +/bin/sh /tmp/server-control/prerm remove +if [ "$1" = live ]; then + test -f /stopped + test ! -f /var/run/xcatd.pid +else + kill -0 "$daemon" + test ! -f /stopped + test -f /var/run/xcatd.pid +fi +SH + is(-e $root->path('/stopped') ? $root->read('/stopped') : '', + $active ? "TERM\n" : '', 'only live-root removal signals the process'); + if ($mode eq 'systemd-chroot') { + for my $service (qw(xcatd xcat-uftp-listener)) { + ok(!-l $root->path("/etc/systemd/system/multi-user.target.wants/$service.service"), + "removal disables $service without starting the image"); + } + } else { + my @links = glob $root->path('/etc/rc?.d/S??xcatd'); + is_deeply(\@links, [], 'removal still disables offline service registration'); + } + }; +} +done_testing; From a7d7b85c7cfeded02134ebe3b83d99872fcfc652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:13:26 -0300 Subject: [PATCH 03/45] test(build): limit the upgrade log allocation fault --- xCAT-test/native/package_upgrade_logging.t | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/package_upgrade_logging.t b/xCAT-test/native/package_upgrade_logging.t index e387c4a685..b6e233ee26 100644 --- a/xCAT-test/native/package_upgrade_logging.t +++ b/xCAT-test/native/package_upgrade_logging.t @@ -57,7 +57,13 @@ SHELL my $failed = $case eq 'command-failure' || $case eq 'warning-failure'; $root->write('/command-status', "17\n") if $failed; if ($case eq 'temporary-failure') { - $root->write('/test-bin/mktemp', "#!/bin/sh\necho 'temporary allocation failed' >&2\nexit 19\n", 0755); + $root->write('/test-bin/mktemp', <<'SH', oct('755')); +#!/bin/sh +case "$1" in + /tmp/xcat-upgrade.*) echo 'temporary allocation failed' >&2; exit 19 ;; +esac +exec /usr/bin/mktemp "$@" +SH } for my $service (qw(installservice udpservice mainservice)) { $root->write("/tmp/xcat/$service.pid", "$service pid\n"); From 2f22c0d4586b7ecd8dc7ff9f90aa6fb8d87c0969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:13:26 -0300 Subject: [PATCH 04/45] fix(debian): retain management configuration context until success --- xCAT/debian/postinst | 25 +++++++++++++++++++++++-- xCAT/debian/postrm | 20 ++++++++++++++++++++ xCAT/debian/preinst | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100755 xCAT/debian/postrm create mode 100755 xCAT/debian/preinst diff --git a/xCAT/debian/postinst b/xCAT/debian/postinst index bbb179eded..bba19ba253 100644 --- a/xCAT/debian/postinst +++ b/xCAT/debian/postinst @@ -20,11 +20,28 @@ set -e case "$1" in configure) + state_dir=/var/lib/xcat/configure-state + if [ -L "$state_dir" ] || [ -L "$state_dir/context" ] || + { [ -e "$state_dir" ] && [ ! -d "$state_dir" ]; }; then + echo "Invalid xCAT configuration state: $state_dir" >&2 + exit 1 + fi + if [ -f "$state_dir/context" ]; then + context=$(cat "$state_dir/context") + case "$context" in + fresh|upgrade) ;; + *) echo "Invalid xCAT configuration context in $state_dir/context: $context" >&2; exit 1 ;; + esac + elif [ -f /tmp/xCAT_upgrade.tmp ]; then + context=upgrade + else + context=fresh + fi # Make dir for the current pid mkdir -p /var/run/xcat cp -f /opt/xcat/share/xcat/scripts/xHRM /install/postscripts/ . /etc/profile.d/xcat.sh - if [ -f /tmp/xCAT_upgrade.tmp ] + if [ "$context" = upgrade ] then if [ -r "/tmp/xcat/installservice.pid" ]; then mv /tmp/xcat/installservice.pid /var/run/xcat/installservice.pid @@ -36,7 +53,6 @@ case "$1" in mv /tmp/xcat/mainservice.pid /var/run/xcat/mainservice.pid fi xcat_run_upgrade xcatconfig -u -V - rm /tmp/xCAT_upgrade.tmp else xcatconfig -i fi @@ -75,4 +91,9 @@ esac #DEBHELPER# +if [ "$1" = configure ]; then + rm -f "$state_dir/context" /tmp/xCAT_upgrade.tmp + rmdir "$state_dir" 2>/dev/null || : +fi + exit 0 diff --git a/xCAT/debian/postrm b/xCAT/debian/postrm new file mode 100755 index 0000000000..65ea2b2b66 --- /dev/null +++ b/xCAT/debian/postrm @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +case "$1" in + remove|purge|abort-install|disappear) + state_dir=/var/lib/xcat/configure-state + if [ -L "$state_dir" ]; then + echo "Invalid xCAT configuration state directory: $state_dir" >&2 + exit 1 + fi + rm -f "$state_dir/context" "$state_dir"/context.* /tmp/xCAT_upgrade.tmp + rmdir "$state_dir" 2>/dev/null || : + ;; + upgrade|failed-upgrade|abort-upgrade) ;; + *) echo "postrm called with unknown argument: $1" >&2; exit 1 ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/xCAT/debian/preinst b/xCAT/debian/preinst new file mode 100755 index 0000000000..5231f71e49 --- /dev/null +++ b/xCAT/debian/preinst @@ -0,0 +1,42 @@ +#!/bin/sh +set -e + +state_dir=/var/lib/xcat/configure-state + +case "$1" in + install) context=fresh ;; + upgrade) context=upgrade ;; + abort-upgrade) context= ;; + *) echo "preinst called with unknown argument: $1" >&2; exit 1 ;; +esac + +if [ -n "$context" ]; then + if [ -L "$state_dir" ] || [ -L "$state_dir/context" ] || + { [ -e "$state_dir" ] && [ ! -d "$state_dir" ]; }; then + echo "Invalid xCAT configuration state directory: $state_dir" >&2 + exit 1 + fi + # dpkg skips prerm when the previous package was only unpacked. + if [ "$context" = upgrade ] && [ ! -f /tmp/xCAT_upgrade.tmp ]; then + if [ -f "$state_dir/context" ]; then + context=$(cat "$state_dir/context") + case "$context" in + fresh|upgrade) ;; + *) echo "Invalid xCAT configuration context in $state_dir/context: $context" >&2; exit 1 ;; + esac + else + context=fresh + fi + fi + mkdir -p -m 700 "$state_dir" + chmod 700 "$state_dir" + temporary=$(mktemp "$state_dir/context.XXXXXX") + trap 'rm -f "$temporary"' EXIT + trap 'exit 1' HUP INT TERM + printf '%s\n' "$context" > "$temporary" + mv -f "$temporary" "$state_dir/context" +fi + +#DEBHELPER# + +exit 0 From 11e6e642c4f8c65dbc258c173de9677a46826430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:13:26 -0300 Subject: [PATCH 05/45] test(debian): cover interrupted management package transactions --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/debian_management_recovery.t | 183 ++++++++++++++++++ 2 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/debian_management_recovery.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index a7086fc57f..cfce7c8295 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -15,7 +15,7 @@ jobs: - name: Install lifecycle test dependencies run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests ucf debconf-utils systemd libxml-simple-perl apache2 curl - name: Test Debian package lifecycle - run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/debian_chroot_services.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t xCAT-test/native/profile_package_payload.t + run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/debian_chroot_services.t xCAT-test/native/debian_management_recovery.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t xCAT-test/native/profile_package_payload.t - name: Test optional statelite host keys if: ${{ !cancelled() }} run: prove -v xCAT-test/native/statelite_optional_hostkey.t diff --git a/xCAT-test/native/debian_management_recovery.t b/xCAT-test/native/debian_management_recovery.t new file mode 100644 index 0000000000..8498e5c616 --- /dev/null +++ b/xCAT-test/native/debian_management_recovery.t @@ -0,0 +1,183 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use Test::More; +use File::Temp qw(tempdir); +use File::Slurper qw(read_binary write_binary); +use XCAT::Test::Lifecycle; + +plan skip_all => 'Run as an ordinary user on Debian or Ubuntu' + unless $^O eq 'linux' && $< != 0 && -f '/etc/debian_version'; +my $deb = XCAT::Test::Lifecycle::build_deb('xCAT'); +my $fault = tempdir(CLEANUP => 1); +XCAT::Test::Lifecycle::checked('dpkg-deb', '-R', $deb, "$fault/package"); +write_binary("$fault/package/DEBIAN/preinst", "#!/bin/sh\nexit 17\n"); +chmod 0755, "$fault/package/DEBIAN/preinst" or die "chmod failing preinst: $!"; +XCAT::Test::Lifecycle::checked('dpkg-deb', '--root-owner-group', '-b', "$fault/package", "$fault/failure.deb"); +for my $script (qw(preinst postinst postrm)) { + unlink "$fault/package/DEBIAN/$script" or die "remove legacy fixture script: $!" + if -f "$fault/package/DEBIAN/$script"; +} +my $control = read_binary("$fault/package/DEBIAN/control"); +$control =~ s/^Version:.*$/Version: 2.0/m or die 'legacy fixture has no Version'; +write_binary("$fault/package/DEBIAN/control", $control); +XCAT::Test::Lifecycle::checked('dpkg-deb', '--root-owner-group', '-b', "$fault/package", "$fault/legacy.deb"); + +sub succeeds { + my ($label, @result) = @_; + is($result[0], 0, $label) or diag "$result[1]$result[2]"; +} + +sub management_root { + my $root = XCAT::Test::Lifecycle->new; + $root->write('/opt/xcat/share/xcat/scripts/xHRM', ''); + $root->write('/opt/xcat/sbin/xcatconfig', <<'SH', oct('755')); +#!/bin/sh +printf '%s\n' "$*" >> /config-calls +if [ -f /config-fail ]; then exit 17; fi +SH + $root->write('/etc/init.d/apache2', <<'SH', oct('755')); +#!/bin/sh +if [ -f /apache-fail ]; then exit 19; fi +SH + $root->write('/config-calls', ''); + return $root; +} + +for my $case (qw(fresh-retry fresh-reinstall fresh-abort-retry fresh-legacy-return removed-fresh-retry removed-fresh-abort removed-fresh-legacy-return upgrade-retry apache-retry cleared-tmp + failed-remove failed-purge abort-remove abort-retry)) { + subtest $case => sub { + my $root = management_root(); + if ($case !~ /^fresh/) { + succeeds('install the previous package', $root->install_deb( + $case eq 'removed-fresh-legacy-return' ? "$fault/legacy.deb" : $deb)); + } + if ($case =~ /^removed-fresh/) { + succeeds('remove the configured package but keep its conffiles', + $root->run('dpkg', '--force-depends', '--remove', 'xcat')); + } + my $fresh_install = $case =~ /^(?:fresh|removed-fresh)/; + my $remove_after_failure = $case =~ /^(?:failed|abort)-(?:remove|purge)$/; + $root->write('/config-calls', ''); + $root->write($case eq 'apache-retry' ? '/apache-fail' : '/config-fail', '') + unless $case =~ /^abort/; + my ($status, $out, $err) = $root->install_deb($case =~ /^abort/ ? "$fault/failure.deb" : $deb); + isnt($status, 0, 'the injected transaction failure reaches dpkg'); + like($err, $case =~ /^abort/ ? qr/pre-installation script.*exit status 17/ + : $case eq 'apache-retry' ? qr/post-installation script.*exit status 19/ + : qr/post-installation script.*exit status 17/, 'failure comes from the intended boundary'); + is($root->read('/config-calls'), $case =~ /^abort/ ? '' + : $fresh_install ? "-i\n" : "-u -V\n", 'the first attempt uses the intended configuration mode'); + unlink $root->path('/config-fail') if -f $root->path('/config-fail'); + unlink $root->path('/apache-fail') if -f $root->path('/apache-fail'); + if ($case eq 'fresh-abort-retry' || $case eq 'removed-fresh-abort') { + my ($aborted, $out, $err) = $root->install_deb("$fault/failure.deb"); + isnt($aborted, 0, 'a later unpack can also fail before fresh configuration succeeds'); + like($err, qr/pre-installation script.*exit status 17/, 'the later failure reaches the intended preinst'); + } + if ($case =~ /legacy-return$/) { + succeeds('configure an older package without context hooks', $root->install_deb("$fault/legacy.deb")); + } + if ($case eq 'cleared-tmp') { + unlink $root->path('/tmp/xCAT_upgrade.tmp') or die "clear temporary marker: $!"; + } + $root->write('/config-calls', ''); + for my $service (qw(installservice udpservice mainservice)) { + $root->write("/tmp/xcat/$service.pid", "$service\n"); + } + my $fresh = $case eq 'fresh-retry' || $remove_after_failure; + if ($remove_after_failure) { + succeeds('remove the failed transaction', $root->run('dpkg', '--force-depends', + $case eq 'failed-purge' ? '--purge' : '--remove', 'xcat')); + succeeds('reinstall after removal', $root->install_deb($deb)); + } elsif ($case =~ /reinstall|abort|legacy-return|removed-fresh/) { + succeeds('retry the package transaction', $root->install_deb($deb)); + } else { + succeeds('retry configuration through dpkg', + $root->run('dpkg', '--force-depends', '--configure', 'xcat')); + } + is($root->read('/config-calls'), $fresh ? "-i\n" : "-u -V\n", + 'configure retry retains context and a new transaction follows dpkg mode'); + for my $service (qw(installservice udpservice mainservice)) { + my $directory = $fresh ? '/tmp/xcat' : '/var/run/xcat'; + my $file = "$directory/$service.pid"; + is(-f $root->path($file) ? $root->read($file) : undef, + "$service\n", 'PID relocation follows the recovered mode'); + } + ok(!-e $root->path('/var/lib/xcat/configure-state'), 'successful configuration clears persistent transaction state'); + ok(!-e $root->path('/tmp/xCAT_upgrade.tmp'), 'successful configuration clears the legacy marker'); + succeeds('the package is configured', $root->run('/bin/sh', '-c', + q{test "$(dpkg-query -W -f='${Status}' xcat)" = 'install ok installed'})); + }; +} + +for my $case (qw(unpacked-reinstall unpacked-abort legacy-unpacked-reinstall upgrade-unpacked-marker-loss)) { + subtest $case => sub { + my $root = management_root(); + my $upgrade = $case eq 'upgrade-unpacked-marker-loss'; + succeeds('configure the package before an unpacked upgrade', $root->install_deb($deb)) if $upgrade; + $root->write('/config-calls', ''); + local $root->{deb} = $case eq 'legacy-unpacked-reinstall' ? "$fault/legacy.deb" : $deb; + succeeds('unpack without configuring the package', + $root->run('dpkg', '--force-depends', '--unpack', '/package.deb')); + is($root->read('/config-calls'), '', 'unpack does not run configuration'); + if ($upgrade) { + unlink $root->path('/tmp/xCAT_upgrade.tmp') or die "clear temporary marker: $!"; + } + if ($case eq 'unpacked-abort') { + my ($status, $out, $err) = $root->install_deb("$fault/failure.deb"); + isnt($status, 0, 'an unpacked retry can fail'); + like($err, qr/pre-installation script.*exit status 17/, 'the retry fails at the intended preinst'); + } + for my $service (qw(installservice udpservice mainservice)) { + $root->write("/tmp/xcat/$service.pid", "$service\n"); + } + if ($case eq 'unpacked-abort') { + succeeds('configure after the aborted unpacked retry', + $root->run('dpkg', '--force-depends', '--configure', 'xcat')); + } else { + succeeds('repeat the unpacked transaction and configure', $root->install_deb($deb)); + } + is($root->read('/config-calls'), $upgrade ? "-u -V\n" : "-i\n", + 'never-configured packages stay fresh and unpacked upgrades retain context'); + for my $service (qw(installservice udpservice mainservice)) { + my $directory = $upgrade ? '/var/run/xcat' : '/tmp/xcat'; + my $file = "$directory/$service.pid"; + is(-f $root->path($file) ? $root->read($file) : undef, + "$service\n", 'PID relocation follows the pending configuration'); + } + ok(!-e $root->path('/var/lib/xcat/configure-state'), 'configuration clears persistent transaction state'); + ok(!-e $root->path('/tmp/xCAT_upgrade.tmp'), 'configuration clears the legacy marker'); + }; +} + +for my $parent_mode (undef, oct('750')) { + subtest defined $parent_mode ? 'existing state parent' : 'new state parent' => sub { + my $root = XCAT::Test::Lifecycle->new; + if (defined $parent_mode) { + $root->write('/var/lib/xcat/retained', 'unrelated state'); + chmod $parent_mode, $root->path('/var/lib/xcat') or die "chmod parent: $!"; + } + local $root->{deb} = $deb; + succeeds('unpack the management control scripts', $root->run('dpkg-deb', '-e', '/package.deb', '/tmp/control')); + succeeds('record a fresh transaction with a normal umask', $root->run('/bin/sh', '-c', + 'umask 022; /bin/sh /tmp/control/preinst install')); + is((stat($root->path('/var/lib/xcat')))[2] & oct('7777'), $parent_mode // oct('755'), + 'the shared parent retains its intended permissions'); + is((stat($root->path('/var/lib/xcat/configure-state')))[2] & oct('7777'), oct('700'), + 'transaction directory is private'); + is((stat($root->path('/var/lib/xcat/configure-state/context')))[2] & oct('7777'), oct('600'), + 'transaction context is private'); + $root->write('/var/lib/xcat/configure-state/context', "invalid\n"); + my ($status, $out, $err) = $root->deb_script($deb, 'postinst', 'configure', '2.0'); + isnt($status, 0, 'invalid context stops configuration'); + like($err, qr{Invalid xCAT configuration context in /var/lib/xcat/configure-state/context}, + 'the diagnostic identifies the invalid file'); + $root->write('/tmp/xCAT_upgrade.tmp', ''); + succeeds('a new upgrade replaces stale context', $root->deb_script($deb, 'preinst', 'upgrade', '2.0')); + }; +} + +done_testing; From c76f53a826607f9bd966c029ecd53dcdd1e24307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 20:53:11 -0300 Subject: [PATCH 06/45] refactor(boot): centralize node-template expansion --- perl-xCAT/xCAT/BootUtils.pm | 25 +++++++++++++++++++ xCAT-server/lib/xcat/plugins/boottarget.pm | 29 ++++------------------ xCAT-server/lib/xcat/plugins/pxe.pm | 27 +++----------------- xCAT-server/lib/xcat/plugins/xnba.pm | 27 +++----------------- 4 files changed, 38 insertions(+), 70 deletions(-) diff --git a/perl-xCAT/xCAT/BootUtils.pm b/perl-xCAT/xCAT/BootUtils.pm index 69158b9c86..111d825d4c 100644 --- a/perl-xCAT/xCAT/BootUtils.pm +++ b/perl-xCAT/xCAT/BootUtils.pm @@ -6,6 +6,7 @@ use warnings; use Exporter qw(import); use xCAT::Utils; +use xCAT::Table; our @EXPORT_OK = qw(find_genesis_boot_files); @@ -42,4 +43,28 @@ sub volatile_addkcmdline { return $cmdhashref->{volatile} // ''; } +sub expand_node_template { + my ($node, $text, $on_error) = @_; + return $text unless defined($text); + + while ($text =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { + my $table = xCAT::Table->new($1); + my $entry = $table->getNodeAttribs($node, [$2]); + my $value = $entry->{$2} // ''; + $text =~ s/#NODEATTRIB:([^:#]+):([^:#]+)#/$value/; + } + while ($text =~ /#TABLE:([^:#]+):([^:#]+):([^:#]+)#/) { + my ($table_name, $key, $column) = ($1, $2, $3); + if ($key =~ /THISNODE/ or $key =~ /\$NODE/) { + my $table = xCAT::Table->new($table_name); + my $entry = $table->getNodeAttribs($node, [$column]); + my $value = $entry->{$column} // ''; + $text =~ s/#TABLE:([^:#]+):([^:#]+):([^:#]+)#/$value/; + } else { + $on_error->("Table key of $key not yet supported by boottarget mini-template"); + } + } + return $text; +} + 1; diff --git a/xCAT-server/lib/xcat/plugins/boottarget.pm b/xCAT-server/lib/xcat/plugins/boottarget.pm index 39607ff5a2..dda931bf9c 100644 --- a/xCAT-server/lib/xcat/plugins/boottarget.pm +++ b/xCAT-server/lib/xcat/plugins/boottarget.pm @@ -12,6 +12,7 @@ use Thread qw(yield); use POSIX qw(WNOHANG nice); use xCAT::Table; use xCAT::Utils; +use xCAT::BootUtils; use xCAT::TableUtils; use xCAT::MsgUtils; use xCAT::Template; @@ -158,30 +159,10 @@ sub mknetboot $kcmdline = $tent->{kcmdline}; #TODO: big todo, cheap and rapid, but should be more like esx.pm implementation, i.e. more scalable - while ($kcmdline =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { - my $natab = xCAT::Table->new($1); - my $naent = $natab->getNodeAttribs($node, [$2]); - my $naval = $naent->{$2}; - $kcmdline =~ s/#NODEATTRIB:([^:#]+):([^:#]+)#/$naval/; - } - while ($kcmdline =~ /#TABLE:([^:#]+):([^:#]+):([^:#]+)#/) { - my $tabname = $1; - my $keyname = $2; - my $colname = $3; - if ($2 =~ /THISNODE/ or $2 =~ /\$NODE/) { - my $natab = xCAT::Table->new($tabname); - my $naent = $natab->getNodeAttribs($node, [$colname]); - my $naval = $naent->{$colname}; - $kcmdline =~ s/#TABLE:([^:#]+):([^:#]+):([^:#]+)#/$naval/; - } else { - my $msg = "Table key of $2 not yet supported by boottarget mini-template"; - $callback->({ - error => ["$msg"], - errorcode => [1] - }); - - } - } + $kcmdline = xCAT::BootUtils::expand_node_template( + $node, $kcmdline, + sub { $callback->({error => [$_[0]], errorcode => [1]}); } + ); if ($initrd eq '') { $bptab->setNodeAttribs( diff --git a/xCAT-server/lib/xcat/plugins/pxe.pm b/xCAT-server/lib/xcat/plugins/pxe.pm index 51913d8540..2bf97250cd 100644 --- a/xCAT-server/lib/xcat/plugins/pxe.pm +++ b/xCAT-server/lib/xcat/plugins/pxe.pm @@ -118,29 +118,10 @@ sub setstate { $kcmdlinehack = xCAT::BootUtils::volatile_addkcmdline($kcmdlinehack); - while ($kcmdlinehack =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { - my $natab = xCAT::Table->new($1); - my $naent = $natab->getNodeAttribs($node, [$2]); - my $naval = $naent->{$2}; - $kcmdlinehack =~ s/#NODEATTRIB:([^:#]+):([^:#]+)#/$naval/; - } - while ($kcmdlinehack =~ /#TABLE:([^:#]+):([^:#]+):([^:#]+)#/) { - my $tabname = $1; - my $keyname = $2; - my $colname = $3; - if ($2 =~ /THISNODE/ or $2 =~ /\$NODE/) { - my $natab = xCAT::Table->new($tabname); - my $naent = $natab->getNodeAttribs($node, [$colname]); - my $naval = $naent->{$colname}; - $kcmdlinehack =~ s/#TABLE:([^:#]+):([^:#]+):([^:#]+)#/$naval/; - } else { - my $msg = "Table key of $2 not yet supported by boottarget mini-template"; - $::PXE_callback->({ - error => ["$msg"], - errorcode => [1] - }); - } - } + $kcmdlinehack = xCAT::BootUtils::expand_node_template( + $node, $kcmdlinehack, + sub { $::PXE_callback->({error => [$_[0]], errorcode => [1]}); } + ); #$kern->{kcmdline} .= " ".$kern->{addkcmdline}; diff --git a/xCAT-server/lib/xcat/plugins/xnba.pm b/xCAT-server/lib/xcat/plugins/xnba.pm index 9df311f54d..08bde0d1ba 100644 --- a/xCAT-server/lib/xcat/plugins/xnba.pm +++ b/xCAT-server/lib/xcat/plugins/xnba.pm @@ -203,29 +203,10 @@ sub setstate { $kcmdlinehack = xCAT::BootUtils::volatile_addkcmdline($kcmdlinehack); - while ($kcmdlinehack =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { - my $natab = xCAT::Table->new($1); - my $naent = $natab->getNodeAttribs($node, [$2]); - my $naval = $naent->{$2}; - $kcmdlinehack =~ s/#NODEATTRIB:([^:#]+):([^:#]+)#/$naval/; - } - while ($kcmdlinehack =~ /#TABLE:([^:#]+):([^:#]+):([^:#]+)#/) { - my $tabname = $1; - my $keyname = $2; - my $colname = $3; - if ($2 =~ /THISNODE/ or $2 =~ /\$NODE/) { - my $natab = xCAT::Table->new($tabname); - my $naent = $natab->getNodeAttribs($node, [$colname]); - my $naval = $naent->{$colname}; - $kcmdlinehack =~ s/#TABLE:([^:#]+):([^:#]+):([^:#]+)#/$naval/; - } else { - my $msg = "Table key of $2 not yet supported by boottarget mini-template"; - $::XNBA_callback->({ - error => ["$msg"], - errorcode => [1] - }); - } - } + $kcmdlinehack = xCAT::BootUtils::expand_node_template( + $node, $kcmdlinehack, + sub { $::XNBA_callback->({error => [$_[0]], errorcode => [1]}); } + ); #$kern->{kcmdline} .= " ".$kern->{addkcmdline}; $kern->{kcmdline} .= " " . $kcmdlinehack; From 83937329714fcd90f5115647a2e33cc4dbad20f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 20:54:25 -0300 Subject: [PATCH 07/45] test(boot): characterize node templates across boot methods --- xCAT-test/unit/boot_node_template.t | 184 ++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 xCAT-test/unit/boot_node_template.t diff --git a/xCAT-test/unit/boot_node_template.t b/xCAT-test/unit/boot_node_template.t new file mode 100644 index 0000000000..14058f9078 --- /dev/null +++ b/xCAT-test/unit/boot_node_template.t @@ -0,0 +1,184 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_binary write_text); +use File::Temp qw(tempdir); +use Storable qw(dclone); +use Test::More; +use XCAT::Test::File qw(repo_path); + +my $root = tempdir(CLEANUP => 1); +my $tftp = "$root/tftp"; +$ENV{XCATROOT} = repo_path('xCAT-server'); +$ENV{XCATCFG} = "$root/config"; +make_path($ENV{XCATCFG}, $tftp); +write_text("$tftp/pxelinux.0", 'loader'); +require xCAT::TableUtils; +{ + no warnings qw(redefine once); + local *xCAT::TableUtils::getTftpDir = sub { return $tftp; }; + for my $plugin (qw(pxe xnba ipxe boottarget)) { + require(repo_path("xCAT-server/lib/xcat/plugins/$plugin.pm")); + } +} + +my (%rows, %written, %kernels); +my @responses; +sub render { + my ($method, $input, %options) = @_; + my $node = '192.0.2.10'; + %written = (); + @responses = (); + %kernels = ($node => { + kernel => $options{kernel} || 'vmlinuz', initrd => 'initrd', kcmdline => 'quiet', + addkcmdline => $input, + }); + %rows = ( + noderes => {$node => {tftpdir => $tftp}}, + chain => {$node => {currstate => 'install'}}, + nodetype => {$node => {os => 'boottarget', profile => 'custom', + provmethod => $options{image} ? 'image' : 'install'}}, + mac => {}, iscsi => {}, bootparams => {}, nodehm => {}, + boottarget => {custom => {kernel => 'vmlinuz', initrd => 'initrd', kcmdline => $input}}, + linuximage => {image => {addkcmdline => $options{image}, boottarget => $options{boottarget}}}, + hosts => {$node => { + ip => '192.0.2.10', empty => '', zero => '0', + nested => '#NODEATTRIB:hosts:ip#', + table => '#TABLE:hosts:THISNODE:ip#', + special => 'a$1\\b&c', + }}, + ); + no warnings qw(redefine once); + local @ARGV; + local *xCAT::Table::new = sub { + my ($class, $table) = @_; + die "Unexpected table $table" unless exists $rows{$table}; + return bless {table => $table}, 'Local::TemplateTable'; + }; + local *xCAT::TableUtils::getTftpDir = sub { return $tftp; }; + local *xCAT::TableUtils::getInstallDir = sub { return "$root/install"; }; + local *xCAT::TableUtils::get_site_attribute = sub { + return ('n') if $_[1] eq 'dhcpsetup'; + return () if $_[1] eq 'httpport'; + die "Unexpected site attribute $_[1]"; + }; + local *xCAT::NetworkUtils::determinehostname = sub { return ('mn.example'); }; + local *xCAT::NetworkUtils::checkNodeIPaddress = sub { return {ip => $_[1]}; }; + local *xCAT::MsgUtils::trace = sub { return; }; + my $callback = sub { push @responses, dclone($_[0]); }; + "xCAT_plugin::$method"->can('process_request')->( + {command => [$method eq 'boottarget' ? 'mknetboot' : 'nodeset'], + node => [$node], arg => ['install']}, + $callback, + sub { + my ($request, $reply) = @_; + if ($request->{command}[0] eq 'setdestiny') { + $request->{bootparams}{$node} = [$kernels{$node}]; + $reply->({node => [{name => [$node], _addkcmdlinehandled => 1}]}) + if $options{handled}; + } elsif ($request->{command}[0] !~ /\A(?:runbeginpre|runendpre)\z/) { + die "Unexpected command $request->{command}[0]"; + } + }, + ); + is_deeply(\@responses, [], "$method reports no errors"); + return $written{$node}{kcmdline} if $method eq 'boottarget'; + return $kernels{$node}{kcmdline}; +} + +my @cases = ( + ['undefined', undef, undef, 'quiet'], + ['empty', '', '', 'quiet'], + ['zero', '0', '0', 'quiet'], + ['literal', 'console=ttyS0', 'console=ttyS0', 'quiet console=ttyS0 '], + ['node attribute', 'ip=#NODEATTRIB:hosts:ip#', 'ip=192.0.2.10', 'quiet ip=192.0.2.10 '], + ['table key', 'ip=#TABLE:hosts:THISNODE:ip#', 'ip=192.0.2.10', 'quiet ip=192.0.2.10 '], + ['dollar key', 'ip=#TABLE:hosts:$NODE:ip#', 'ip=192.0.2.10', 'quiet ip=192.0.2.10 '], + ['node selector', '#TABLE:hosts:node=$NODE:ip#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['mixed order', '#TABLE:hosts:THISNODE:ip#,#NODEATTRIB:hosts:zero#,#TABLE:hosts:$NODE:ip#', '192.0.2.10,0,192.0.2.10', 'quiet 192.0.2.10,0,192.0.2.10 '], + ['missing', 'a=#NODEATTRIB:hosts:missing# b=#TABLE:hosts:THISNODE:missing#', 'a= b=', 'quiet a= b= '], + ['empty and zero', 'a=#NODEATTRIB:hosts:empty# b=#NODEATTRIB:hosts:zero#', 'a= b=0', 'quiet a= b=0 '], + ['repeat', '#NODEATTRIB:hosts:ip#,#NODEATTRIB:hosts:ip#', '192.0.2.10,192.0.2.10', 'quiet 192.0.2.10,192.0.2.10 '], + ['nested node', '#NODEATTRIB:hosts:nested#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['node then table', '#NODEATTRIB:hosts:table#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['table recursion', '#TABLE:hosts:THISNODE:table#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['table does not restart node pass', '#TABLE:hosts:THISNODE:nested#', '#NODEATTRIB:hosts:ip#', 'quiet #NODEATTRIB:hosts:ip# '], + ['literal replacement', '#NODEATTRIB:hosts:special#', 'a$1\\b&c', 'quiet a$1\\b&c '], + ['persistent', 'R::keep=1 marker=#NODEATTRIB:hosts:ip#', 'R::keep=1 marker=192.0.2.10', 'quiet marker=192.0.2.10 '], + ['persistent only', 'R::keep=1', 'R::keep=1', 'quiet '], + ['partial token', '#NODEATTRIB:hosts:ip', '#NODEATTRIB:hosts:ip', 'quiet #NODEATTRIB:hosts:ip '], +); + +for my $method (qw(pxe xnba ipxe boottarget)) { + for my $case (@cases) { + my ($name, $input, $target, $netboot) = @$case; + subtest "$method $name" => sub { + my $expected = $method eq 'boottarget' ? $target : $netboot; + is(render($method, $input), $expected, 'expansion keeps the caller contract'); + if ($method eq 'pxe') { + is(read_text("$tftp/pxelinux.cfg/192.0.2.10"), + "#install\nDEFAULT xCAT\nLABEL xCAT\n KERNEL vmlinuz\n APPEND initrd=initrd $expected\n IPAPPEND 2\n", + 'PXE writes the complete expected configuration'); + } elsif ($method ne 'boottarget') { + like(read_text("$tftp/xcat/$method/nodes/192.0.2.10"), + qr/^imgargs kernel \Q$expected\E BOOTIF=01-\$\{netX\/mac:hexhyp\}$/m, + 'the selected method writes the expanded BIOS arguments'); + like(read_text("$tftp/xcat/$method/nodes/192.0.2.10.elilo"), + qr/append="\Q$expected\E BOOTIF=%B"/, + 'the selected method writes the expanded UEFI fallback arguments'); + } else { + is_deeply($written{'192.0.2.10'}, + {kernel => 'vmlinuz', initrd => 'initrd', kcmdline => $expected}, + 'boottarget persists the kernel, initrd and expanded arguments'); + } + }; + } + next if $method eq 'boottarget'; + subtest "$method image arguments" => sub { + is(render($method, 'node=#NODEATTRIB:hosts:ip#', image => 'R::keep=1 image=#TABLE:hosts:$NODE:ip#'), + 'quiet node=192.0.2.10 image=192.0.2.10 ', 'node and image arguments retain their order'); + }; + subtest "$method handled arguments" => sub { + is(render($method, '#TABLE:hosts:unsupported:ip#', handled => 1), + 'quiet', 'a prior owner can suppress mini-template expansion'); + }; + next if $method eq 'pxe'; + subtest "$method direct UEFI" => sub { + write_binary("$tftp/modern-kernel", "\0" x 64 . pack('H*', '504500006486') . "\0" x 440); + is(render($method, 'marker=#NODEATTRIB:hosts:ip#', kernel => 'modern-kernel'), 'quiet marker=192.0.2.10 ', + 'a modern kernel gets the same expansion'); + like(read_text("$tftp/xcat/$method/nodes/192.0.2.10.uefi"), + qr/^imgargs kernel quiet marker=192\.0\.2\.10 BOOTIF=01-\$\{netX\/mac:hexhyp\} initrd=initrd$/m, + 'direct UEFI boot receives the expanded arguments'); + unlink("$tftp/modern-kernel") or die "unlink kernel: $!"; + }; +} + +done_testing(); + +package Local::TemplateTable; +sub getNodesAttribs { + my ($self, $nodes) = @_; + return {map { $_ => [$rows{$self->{table}}{$_} || {}] } @$nodes}; +} +sub getNodeAttribs { + my ($self, $node) = @_; + return $rows{$self->{table}}{$node} || {}; +} +sub getAttribs { + my ($self, $key) = @_; + my ($value) = values %$key; + return $rows{$self->{table}}{$value}; +} +sub setNodeAttribs { + my ($self, $node, $attributes) = @_; + die "Unexpected write to $self->{table}" unless $self->{table} eq 'bootparams'; + $written{$node} = Storable::dclone($attributes); + return; +} +sub close { return; } From bb8bc944dd2b68ab8781793ae396bd405dea413a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 20:55:56 -0300 Subject: [PATCH 08/45] fix(boot): stop node-template expansion on unsupported keys --- perl-xCAT/xCAT/BootUtils.pm | 1 + xCAT-server/lib/xcat/plugins/boottarget.pm | 7 ++++++- xCAT-server/lib/xcat/plugins/pxe.pm | 6 ++++-- xCAT-server/lib/xcat/plugins/xnba.pm | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/perl-xCAT/xCAT/BootUtils.pm b/perl-xCAT/xCAT/BootUtils.pm index 111d825d4c..98e3654ed3 100644 --- a/perl-xCAT/xCAT/BootUtils.pm +++ b/perl-xCAT/xCAT/BootUtils.pm @@ -62,6 +62,7 @@ sub expand_node_template { $text =~ s/#TABLE:([^:#]+):([^:#]+):([^:#]+)#/$value/; } else { $on_error->("Table key of $key not yet supported by boottarget mini-template"); + return; } } return $text; diff --git a/xCAT-server/lib/xcat/plugins/boottarget.pm b/xCAT-server/lib/xcat/plugins/boottarget.pm index dda931bf9c..fce25bce03 100644 --- a/xCAT-server/lib/xcat/plugins/boottarget.pm +++ b/xCAT-server/lib/xcat/plugins/boottarget.pm @@ -159,10 +159,15 @@ sub mknetboot $kcmdline = $tent->{kcmdline}; #TODO: big todo, cheap and rapid, but should be more like esx.pm implementation, i.e. more scalable + my $template_error; $kcmdline = xCAT::BootUtils::expand_node_template( $node, $kcmdline, - sub { $callback->({error => [$_[0]], errorcode => [1]}); } + sub { $template_error = shift; } ); + if (defined($template_error)) { + xCAT::MsgUtils->report_node_error($callback, $node, $template_error); + next; + } if ($initrd eq '') { $bptab->setNodeAttribs( diff --git a/xCAT-server/lib/xcat/plugins/pxe.pm b/xCAT-server/lib/xcat/plugins/pxe.pm index 2bf97250cd..b4ab8c2149 100644 --- a/xCAT-server/lib/xcat/plugins/pxe.pm +++ b/xCAT-server/lib/xcat/plugins/pxe.pm @@ -118,10 +118,12 @@ sub setstate { $kcmdlinehack = xCAT::BootUtils::volatile_addkcmdline($kcmdlinehack); + my $template_error; $kcmdlinehack = xCAT::BootUtils::expand_node_template( $node, $kcmdlinehack, - sub { $::PXE_callback->({error => [$_[0]], errorcode => [1]}); } + sub { $template_error = shift; } ); + return (1, $template_error) if defined($template_error); #$kern->{kcmdline} .= " ".$kern->{addkcmdline}; @@ -514,7 +516,7 @@ sub process_request { ($rc, $errstr) = setstate($_, \%bphash, \%chainhash, \%machash, \%nthash, $tftpdir, $linuximghash); if ($rc) { $response{node}->[0]->{errorcode}->[0] = $rc; - $response{node}->[0]->{errorc}->[0] = $errstr; + $response{node}->[0]->{error}->[0] = $errstr; $::PXE_callback->(\%response); } } diff --git a/xCAT-server/lib/xcat/plugins/xnba.pm b/xCAT-server/lib/xcat/plugins/xnba.pm index 08bde0d1ba..4dd715bdeb 100644 --- a/xCAT-server/lib/xcat/plugins/xnba.pm +++ b/xCAT-server/lib/xcat/plugins/xnba.pm @@ -203,10 +203,12 @@ sub setstate { $kcmdlinehack = xCAT::BootUtils::volatile_addkcmdline($kcmdlinehack); + my $template_error; $kcmdlinehack = xCAT::BootUtils::expand_node_template( $node, $kcmdlinehack, - sub { $::XNBA_callback->({error => [$_[0]], errorcode => [1]}); } + sub { $template_error = shift; } ); + return (1, $template_error) if defined($template_error); #$kern->{kcmdline} .= " ".$kern->{addkcmdline}; $kern->{kcmdline} .= " " . $kcmdlinehack; From 3b60ea3150e9afb08a881dedcd634c0837cdf0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 20:57:41 -0300 Subject: [PATCH 09/45] test(boot): reject unsupported keys without replacing boot artifacts --- xCAT-test/unit/boot_node_template.t | 115 ++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 7 deletions(-) diff --git a/xCAT-test/unit/boot_node_template.t b/xCAT-test/unit/boot_node_template.t index 14058f9078..3baac23444 100644 --- a/xCAT-test/unit/boot_node_template.t +++ b/xCAT-test/unit/boot_node_template.t @@ -31,7 +31,8 @@ my (%rows, %written, %kernels); my @responses; sub render { my ($method, $input, %options) = @_; - my $node = '192.0.2.10'; + my @nodes = @{ $options{nodes} || ['192.0.2.10'] }; + my $node = $nodes[0]; %written = (); @responses = (); %kernels = ($node => { @@ -47,12 +48,26 @@ sub render { boottarget => {custom => {kernel => 'vmlinuz', initrd => 'initrd', kcmdline => $input}}, linuximage => {image => {addkcmdline => $options{image}, boottarget => $options{boottarget}}}, hosts => {$node => { - ip => '192.0.2.10', empty => '', zero => '0', + ip => $node, empty => '', zero => '0', nested => '#NODEATTRIB:hosts:ip#', table => '#TABLE:hosts:THISNODE:ip#', special => 'a$1\\b&c', }}, ); + for my $other (@nodes) { + next if $other eq $node; + $kernels{$other} = dclone($kernels{$node}); + for my $table (qw(noderes chain nodetype hosts)) { + $rows{$table}{$other} = dclone($rows{$table}{$node}); + } + $rows{hosts}{$other}{ip} = $other; + } + if ($options{bad_node}) { + my $bad = $options{bad_node}; + $kernels{$bad}{addkcmdline} = $options{bad_input}; + $rows{nodetype}{$bad}{profile} = 'bad'; + $rows{boottarget}{bad} = {kernel => 'vmlinuz', initrd => 'initrd', kcmdline => $options{bad_input}}; + } no warnings qw(redefine once); local @ARGV; local *xCAT::Table::new = sub { @@ -70,22 +85,34 @@ sub render { local *xCAT::NetworkUtils::determinehostname = sub { return ('mn.example'); }; local *xCAT::NetworkUtils::checkNodeIPaddress = sub { return {ip => $_[1]}; }; local *xCAT::MsgUtils::trace = sub { return; }; - my $callback = sub { push @responses, dclone($_[0]); }; - "xCAT_plugin::$method"->can('process_request')->( + my $callback = sub { + push @responses, dclone($_[0]) if @responses < 5; + }; + my $completed = eval { + local $SIG{ALRM} = sub { die "template expansion timed out\n"; }; + alarm(2); + "xCAT_plugin::$method"->can('process_request')->( {command => [$method eq 'boottarget' ? 'mknetboot' : 'nodeset'], - node => [$node], arg => ['install']}, + node => \@nodes, arg => ['install']}, $callback, sub { my ($request, $reply) = @_; if ($request->{command}[0] eq 'setdestiny') { - $request->{bootparams}{$node} = [$kernels{$node}]; + $request->{bootparams}{$_} = [$kernels{$_}] for @nodes; $reply->({node => [{name => [$node], _addkcmdlinehandled => 1}]}) if $options{handled}; } elsif ($request->{command}[0] !~ /\A(?:runbeginpre|runendpre)\z/) { die "Unexpected command $request->{command}[0]"; } }, - ); + ); + alarm(0); + 1; + }; + my $exception = $@; + alarm(0); + return $exception if $options{bad_node}; + die $exception unless $completed; is_deeply(\@responses, [], "$method reports no errors"); return $written{$node}{kcmdline} if $method eq 'boottarget'; return $kernels{$node}{kcmdline}; @@ -159,6 +186,80 @@ for my $method (qw(pxe xnba ipxe boottarget)) { }; } +for my $method (qw(pxe xnba ipxe boottarget)) { + for my $position (0, 1, 2) { + for my $existing (0, 1) { + subtest "$method unsupported key at $position existing=$existing" => sub { + my @nodes = qw(192.0.2.20 192.0.2.21 192.0.2.22); + my $bad = $nodes[$position]; + for my $good (grep { $_ ne $bad } @nodes) { + next if $method eq 'boottarget'; + my $file = $method eq 'pxe' ? "$tftp/pxelinux.cfg/$good" + : "$tftp/xcat/$method/nodes/$good"; + write_text($file, "previous boot configuration\n"); + } + my @files = $method eq 'pxe' ? ("$tftp/pxelinux.cfg/$bad") + : $method eq 'boottarget' ? () + : map { "$tftp/xcat/$method/nodes/$bad$_" } ('', '.pxelinux', '.uefi', '.elilo'); + for my $file (@files) { + if ($existing) { + write_text($file, "previous boot configuration\n"); + } else { + unlink($file) or die "unlink $file: $!" if -e $file; + } + } + my $link; + if ($method eq 'pxe') { + $link = "$tftp/pxelinux.cfg/" . sprintf('%02X%02X%02X%02X', split(/\./, $bad)); + unlink($link) or die "unlink $link: $!" if -e $link || -l $link; + symlink($bad, $link) or die "symlink $link: $!" if $existing; + } + my $exception = render($method, 'marker=#NODEATTRIB:hosts:ip#', + nodes => \@nodes, bad_node => $bad, + bad_input => 'before=#NODEATTRIB:hosts:ip# #TABLE:hosts:unsupported:ip# #TABLE:hosts:other:ip#'); + is($exception, '', 'request completes before the timeout'); + my @node_errors = grep { $_->{errorcode} } + map { @{ $_->{node} || [] } } @responses; + is(scalar @node_errors, 1, 'one node error is reported'); + my $response = $node_errors[0] || {}; + is_deeply($response->{name}, [$bad], 'error identifies the failed node'); + is_deeply($response->{errorcode}, [1], 'response is an error'); + is($response->{error}[0] // '', 'Table key of unsupported not yet supported by boottarget mini-template', + 'error identifies the unsupported table key'); + for my $file (@files) { + if ($existing) { + is(read_text($file), "previous boot configuration\n", 'failure preserves the existing artifact'); + } else { + ok(!-e $file, 'failure creates no artifact'); + } + } + if ($link) { + if ($existing) { + ok(-l $link, 'failure preserves the existing boot symlink'); + is(readlink($link), $bad, 'failure preserves the boot symlink target'); + } else { + ok(!-e $link && !-l $link, 'failure creates no boot symlink'); + } + } + if ($method eq 'boottarget') { + ok(!exists($written{$bad}), 'failure does not update bootparams'); + } else { + is($kernels{$bad}{kcmdline}, 'quiet', 'failure does not append a partial expansion'); + } + for my $good (grep { $_ ne $bad } @nodes) { + if ($method eq 'boottarget') { + is($written{$good}{kcmdline}, "marker=$good", 'other nodes still update bootparams'); + } else { + my $file = $method eq 'pxe' ? "$tftp/pxelinux.cfg/$good" + : "$tftp/xcat/$method/nodes/$good"; + like(read_text($file), qr/marker=\Q$good\E /, 'other nodes still get boot artifacts'); + } + } + }; + } + } +} + done_testing(); package Local::TemplateTable; From f44c46c640a22a278850d110ec7b300219b599b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 23:15:49 -0300 Subject: [PATCH 10/45] refactor(netboot): share profile asset selection Share the readable-file search between Debian genimage and imgutils. Keep version fallbacks and path normalization with each caller so Debian retains its existing search order and returned paths. --- .../share/xcat/netboot/debian/genimage | 20 +++-------- .../xcat/netboot/debian/xCAT/ProfileUtils.pm | 17 ++++++++++ .../share/xcat/netboot/imgutils/imgutils.pm | 33 ++++--------------- 3 files changed, 28 insertions(+), 42 deletions(-) create mode 100644 xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm diff --git a/xCAT-server/share/xcat/netboot/debian/genimage b/xCAT-server/share/xcat/netboot/debian/genimage index 35219e8fd3..afd4119116 100755 --- a/xCAT-server/share/xcat/netboot/debian/genimage +++ b/xCAT-server/share/xcat/netboot/debian/genimage @@ -11,6 +11,9 @@ use File::Copy; use File::Find; use Getopt::Long; use Cwd qw(realpath); +use FindBin; +use lib "$FindBin::Bin"; +use xCAT::ProfileUtils; #use strict; Getopt::Long::Configure("bundling"); @@ -1302,21 +1305,8 @@ sub get_profile_def_filename { my $ext = shift; my $dotpos = rindex($osver, "."); my $osbase = substr($osver, 0, $dotpos); - if (-r "$base/$profile.$osver.$arch.$ext") { - return "$base/$profile.$osver.$arch.$ext"; - } elsif (-r "$base/$profile.$osbase.$arch.$ext") { - return "$base/$profile.$osbase.$arch.$ext"; - } elsif (-r "$base/$profile.$arch.$ext") { - return "$base/$profile.$arch.$ext"; - } elsif (-r "$base/$profile.$osver.$ext") { - return "$base/$profile.$osver.$ext"; - } elsif (-r "$base/$profile.$osbase.$ext") { - return "$base/$profile.$osbase.$ext"; - } elsif (-r "$base/$profile.$ext") { - return "$base/$profile.$ext"; - } - - return ""; + return xCAT::ProfileUtils::find_profile_asset( + $base, $profile, $arch, $ext, $osver, $osbase); } diff --git a/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm b/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm new file mode 100644 index 0000000000..fb6e53e1e2 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm @@ -0,0 +1,17 @@ +package xCAT::ProfileUtils; + +use strict; +use warnings; + +sub find_profile_asset { + my ($base, $profile, $arch, $ext, @versions) = @_; + + my @suffixes = ((map { "$_.$arch" } @versions), $arch, @versions, ''); + foreach my $suffix (@suffixes) { + my $file = "$base/$profile" . (length($suffix) ? ".$suffix" : '') . ".$ext"; + return $file if -r $file; + } + return ''; +} + +1; diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 160bc00891..73b50343eb 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -11,6 +11,9 @@ use File::Copy qw(move); use File::Find; use File::Path; use Cwd qw(realpath); +# Debian's standalone builder carries this helper with its copied scripts. +use lib dirname(__FILE__) . '/../debian'; +use xCAT::ProfileUtils; use xCAT::SvrUtils; sub el_major_version { @@ -241,33 +244,9 @@ sub get_profile_def_filename { if ($osver =~ /^leap15/) { $fallbackos = "sle15"; } - if (-r "$base/$profile.$osver.$arch.$ext") { - return "$base/$profile.$osver.$arch.$ext"; - } - foreach my $osbase (@osbase) { - if (-r "$base/$profile.$osbase.$arch.$ext") { - return "$base/$profile.$osbase.$arch.$ext"; - } - } - if ($fallbackos && -r "$base/$profile.$fallbackos.$arch.$ext") { - return "$base/$profile.$fallbackos.$arch.$ext"; - } elsif (-r "$base/$profile.$arch.$ext") { - return "$base/$profile.$arch.$ext"; - } elsif (-r "$base/$profile.$osver.$ext") { - return "$base/$profile.$osver.$ext"; - } - foreach my $osbase (@osbase) { - if (-r "$base/$profile.$osbase.$ext") { - return "$base/$profile.$osbase.$ext"; - } - } - if ($fallbackos && -r "$base/$profile.$fallbackos.$ext") { - return "$base/$profile.$fallbackos.$ext"; - } elsif (-r "$base/$profile.$ext") { - return "$base/$profile.$ext"; - } - - return ""; + return xCAT::ProfileUtils::find_profile_asset( + $base, $profile, $arch, $ext, $osver, @osbase, + ($fallbackos ? ($fallbackos) : ())); } sub include_file From 8866046a4bbb363015870ddfd6907924de69f9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 23:18:32 -0300 Subject: [PATCH 11/45] test(netboot): preserve profile asset lookup contracts Compare Debian and shared lookup priorities through their production entry points and real files. Exercise Debian genimage consumers in isolated filesystems, including custom-directory precedence and unchanged postinstall paths. --- .github/workflows/xcat_test.yml | 1 + xCAT-test/native/README.md | 7 ++ .../native/debian_genimage_profile_assets.t | 107 ++++++++++++++++++ .../unit/fixtures/debian_profile_lookup.pl | 20 ++++ xCAT-test/unit/profile_asset_lookup.t | 95 ++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 xCAT-test/native/debian_genimage_profile_assets.t create mode 100644 xCAT-test/unit/fixtures/debian_profile_lookup.pl create mode 100644 xCAT-test/unit/profile_asset_lookup.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 629fc208f0..b122baafc4 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -61,6 +61,7 @@ jobs: xCAT-test/native/ubuntu_genimage_debootstrap_arch.t xCAT-test/native/ubuntu_genimage_apt_mirror.t xCAT-test/native/ubuntu_genimage_resolver_libs.t + xCAT-test/native/debian_genimage_profile_assets.t - name: Exercise the liteimg ramdisk archive if: ${{ !cancelled() }} run: prove xCAT-test/native/liteimg_ramdisk_archive.t diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 71401eaa8c..7814d8d912 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -45,6 +45,13 @@ packages, execute target-architecture binaries or prove that the generated image ## Other native tests +`debian_genimage_profile_assets.t` runs the Debian genimage command in an +isolated filesystem. It checks custom and shipped package lists, +extra-package lists and postinstall scripts. Package tools and postinstall +scripts stop with deliberate failures after recording the selected input. +Only the Debian script directory is copied, with no installed xCAT libraries. +It does not install packages or build an initrd. + The pull-request workflow runs these packaging cases explicitly as an ordinary user: diff --git a/xCAT-test/native/debian_genimage_profile_assets.t b/xCAT-test/native/debian_genimage_profile_assets.t new file mode 100644 index 0000000000..a54728df04 --- /dev/null +++ b/xCAT-test/native/debian_genimage_profile_assets.t @@ -0,0 +1,107 @@ +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use File::Path qw(make_path); +use Test::More; +use XCAT::Test::ImageSandbox; + +plan skip_all => 'Linux namespaces are required' unless $^O eq 'linux'; +die 'Run image tests as an unprivileged user' unless $>; + +sub standalone_image { + my $box = XCAT::Test::ImageSandbox->new(); + make_path("$box->{root}/work/share/xcat/netboot"); + my ($rc, $output, $error) = $box->run('cp', '-R', '--no-preserve=mode,ownership', + '/repo/xCAT-server/share/xcat/netboot/debian', '/work/share/xcat/netboot/'); + die "copy Debian scripts: $output $error" if $rc; + return $box; +} + +for my $extension (qw(pkglist otherpkgs.pkglist postinstall)) { + for my $custom (0, 1) { + subtest "$extension " . ($custom ? 'custom' : 'shipped') => sub { + my $box = standalone_image(); + my $shipped = 'work/share/xcat/netboot/debian'; + my $customdir = 'install/custom/netboot/debian'; + $box->write('install/debian12.5/x86_64/Packages.gz', 'index'); + make_path("$box->{root}/install/debian12.5/x86_64/dists/bookworm"); + $box->write('work/image/rootimg/lib/modules/fixture/modules.dep', ''); + + my $file = "profile.debian12.5.x86_64.$extension"; + my $selected = $custom ? "/$customdir/profile.$extension" + : "share/xcat/netboot/debian/$file"; + my $content = $extension eq 'postinstall' + ? "#!/bin/sh\nprintf '%s\\n' \"\$0\" \"\$@\" > /work/selected\nexit 23\n" + : "selected-package\n"; + my $target = $box->write("$shipped/$file", $custom ? "wrong-package\n" : $content); + chmod(0755, $target) or die "chmod: $!"; + if ($custom) { + $target = $box->write("$customdir/profile.$extension", $content); + chmod(0755, $target) or die "chmod: $!"; + } + + $box->command('debootstrap', $extension eq 'pkglist' ? <<'SH' : 'exit 0'); +printf '%s\n' "$@" > /work/selected +exit 23 +SH + $box->command('yum', <<'SH'); +printf '%s\n' "$@" > /work/selected +exit 23 +SH + $box->write("$shipped/profile.pkglist", '') if $extension eq 'otherpkgs.pkglist'; + + my @args = ('-o', 'debian12.5', '-a', 'x86_64', '-p', 'profile', + '-i', 'eth0', '-n', 'fixture', '-k', 'fixture', + '--rootimgdir', '/work/image', '--noupdate'); + push @args, '--onlyinitrd' if $extension eq 'postinstall'; + my ($rc, $output, $error) = $box->run('env', 'PERL5LIB=', 'XCATROOT=/nonexistent', + 'perl', 'share/xcat/netboot/debian/genimage', @args); + is($rc, 1, 'caller stops at the selected external command failure') or diag($output, $error); + my $observed = -f "$box->{root}/work/selected" ? $box->read('work/selected') : ''; + if ($extension eq 'postinstall') { + is($observed, "$selected\n/work/image/rootimg\ndebian12.5\nx86_64\nprofile\n", + 'postinstall gets the unchanged path spelling and arguments'); + like($output, qr/postinstall script \Q$selected\E failed/, 'caller reports the selected postinstall path'); + } elsif ($extension eq 'pkglist') { + like($observed, qr/^--include=selected-package$/m, 'debootstrap receives the selected package'); + unlike($observed, qr/wrong-package/, 'custom directory takes precedence over a shipped exact match'); + like($output, qr/apt invocation failed/, 'caller reaches the bootstrap failure'); + } else { + like($observed, qr/^selected-package$/m, 'extra-package installation consumes the selected list'); + unlike($observed, qr/wrong-package/, 'custom directory takes precedence over a shipped exact match'); + like($output, qr/yum invocation failed/, 'caller reaches the extra-package failure'); + } + }; + } +} + +subtest 'missing package list' => sub { + my $box = standalone_image(); + $box->write('install/debian12.5/x86_64/Packages.gz', 'index'); + make_path("$box->{root}/install/debian12.5/x86_64/dists/bookworm"); + my ($rc, $output, $error) = $box->run('env', 'PERL5LIB=', 'XCATROOT=/nonexistent', + 'perl', 'share/xcat/netboot/debian/genimage', + '-o', 'debian12.5', '-a', 'x86_64', '-p', 'missing', '-n', 'fixture', '-i', 'eth0', + '--rootimgdir', '/work/image'); + is($rc, 1, 'missing package list stops image creation') or diag($output, $error); + like($output, qr/Unable to find package list for missing!/, 'original missing-list diagnostic remains'); +}; + +subtest 'standalone explicit image definition' => sub { + my $box = standalone_image(); + my $postinstall = $box->write('work/postinstall', "#!/bin/sh\necho explicit > /work/selected\nexit 23\n"); + chmod(0755, $postinstall) or die "chmod: $!"; + $box->write('work/image/rootimg/lib/modules/fixture/modules.dep', ''); + my ($rc, $output, $error) = $box->run('env', 'PERL5LIB=', 'XCATROOT=/nonexistent', + 'perl', 'share/xcat/netboot/debian/genimage', '--onlyinitrd', + '-o', 'debian12.5', '-a', 'x86_64', '-p', 'profile', '-n', 'fixture', '-i', 'eth0', + '-k', 'fixture', '--postinstall', '/work/postinstall', '--rootimgdir', '/work/image', 'explicit-image'); + is($rc, 1, 'standalone command reaches the explicit postinstall failure') or diag($output, $error); + is(-f "$box->{root}/work/selected" ? $box->read('work/selected') : '', "explicit\n", + 'an explicit image definition runs without installed xCAT modules'); + like($output, qr/postinstall script \/work\/postinstall failed/, 'failure comes from the explicit postinstall'); +}; + +done_testing(); diff --git a/xCAT-test/unit/fixtures/debian_profile_lookup.pl b/xCAT-test/unit/fixtures/debian_profile_lookup.pl new file mode 100644 index 0000000000..be78aaf3ab --- /dev/null +++ b/xCAT-test/unit/fixtures/debian_profile_lookup.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +use JSON::PP qw(encode_json); + +BEGIN { + *CORE::GLOBAL::exit = sub { die "genimage exit $_[0]\n" }; +} + +my ($script, $osver, $profile, $arch, $base, $ext) = @ARGV; +@ARGV = ('-o', $osver, '-p', $profile, '-a', $arch); +my $startup; +{ + local $0 = $script; + local *STDOUT; + open STDOUT, '>', \$startup or die "capture stdout: $!"; + do $script; + die "genimage did not stop at argument validation: $@ $!\n" + unless $@ eq "genimage exit 1\n"; +} +print encode_json([main::get_profile_def_filename($base, $ext)]); diff --git a/xCAT-test/unit/profile_asset_lookup.t b/xCAT-test/unit/profile_asset_lookup.t new file mode 100644 index 0000000000..54185b263f --- /dev/null +++ b/xCAT-test/unit/profile_asset_lookup.t @@ -0,0 +1,95 @@ +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../perl-xCAT", + "$FindBin::Bin/../../xCAT-server/lib/perl", + "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Cwd qw(getcwd realpath); +use File::Path qw(make_path); +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use JSON::PP qw(decode_json); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Process qw(run_command); +use imgutils; + +my $root = tempdir(CLEANUP => 1); +my $original_dir = getcwd(); +chdir($root) or die "chdir $root: $!"; +make_path('assets'); +symlink('assets', 'alias') or die "symlink: $!"; + +sub lookup { + my ($owner, $version, $arch, $base, $extension) = @_; + return imgutils::get_profile_def_filename($version, 'compute', $arch, $base, $extension) + if $owner eq 'imgutils'; + local $ENV{PERL5LIB} = ''; + local $ENV{XCATROOT} = '/nonexistent'; + my ($rc, $output) = run_command($^X, + repo_path('xCAT-test/unit/fixtures/debian_profile_lookup.pl'), + repo_path('xCAT-server/share/xcat/netboot/debian/genimage'), + $version, 'compute', $arch, $base, $extension); + die "Debian lookup failed ($rc): $output" if $rc; + return decode_json($output)->[0]; +} + +for my $owner (qw(debian imgutils)) { + for my $arch (qw(x86_64 ppc64le s390x)) { + for my $extension (qw(pkglist otherpkgs.pkglist postinstall)) { + subtest "$owner $arch $extension priority" => sub { + my @names = ( + "compute.debian12.5.$arch.$extension", + "compute.debian12.$arch.$extension", + "compute.$arch.$extension", + "compute.debian12.5.$extension", + "compute.debian12.$extension", + "compute.$extension", + ); + write_text("assets/$_", "fixture\n") for @names; + for my $name (@names) { + for my $base ('assets', './alias', realpath('assets')) { + my $expected_base = $owner eq 'debian' ? $base : realpath($base); + is(lookup($owner, 'debian12.5', $arch, $base, $extension), + "$expected_base/$name", "selects $name through $base"); + } + unlink("assets/$name") or die "unlink $name: $!"; + } + is(lookup($owner, 'debian12.5', $arch, 'assets', $extension), '', 'miss returns an empty string'); + is(lookup($owner, 'debian12.5', $arch, 'missing', $extension), '', 'missing directory returns an empty string'); + SKIP: { + skip 'root can read mode-0000 files', 1 unless $>; + write_text("assets/$names[0]", 'unreadable'); + chmod(0000, "assets/$names[0]") or die "chmod: $!"; + write_text("assets/$names[-1]", 'readable'); + is(lookup($owner, 'debian12.5', $arch, 'assets', $extension), + ($owner eq 'debian' ? 'assets' : realpath('assets')) . "/$names[-1]", + 'an unreadable exact match does not hide the generic asset'); + unlink(map { "assets/$_" } @names[0, -1]) == 2 or die "unlink: $!"; + } + }; + } + } +} + +for my $case ( + ['debian', 'debian12.5', 'compute.debian12.x86_64.pkglist', 'compute.debian12.4.x86_64.pkglist'], + ['debian', 'debian12.5.1', 'compute.debian12.5.x86_64.pkglist', 'compute.debian12.x86_64.pkglist'], + ['imgutils', 'rocky9.6', 'compute.rocky9.5.x86_64.pkglist', 'compute.rocky9.x86_64.pkglist'], + ['imgutils', 'ubuntu24.04', 'compute.pkglist', 'compute.ubuntu24.x86_64.pkglist'], + ['imgutils', 'sles11sp1', 'compute.sles11.x86_64.pkglist', 'compute.pkglist'], + ['imgutils', 'leap15.6', 'compute.sle15.x86_64.pkglist', 'compute.x86_64.pkglist'], + ['imgutils', 'leap15.6', 'compute.sle15.pkglist', 'compute.pkglist'], + ['debian', 'debian12', 'compute.debian12.x86_64.pkglist', 'compute.pkglist'], +) { + my ($owner, $version, $wanted, $other) = @$case; + write_text("assets/$_", "fixture\n") for ($wanted, $other); + is(lookup($owner, $version, 'x86_64', 'assets', 'pkglist'), + ($owner eq 'debian' ? 'assets' : realpath('assets')) . "/$wanted", + "$owner retains its $version fallback policy"); + unlink("assets/$wanted", "assets/$other") == 2 or die "unlink: $!"; +} + +chdir($original_dir) or die "chdir $original_dir: $!"; +done_testing(); From c35aa3f9ed836a6c587d311c874f69c27fd41980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:16:07 -0300 Subject: [PATCH 12/45] fix(build): preserve binaries in source-only runs Source-only signing modified retained binary RPMs and repository signatures while leaving the binary index unchanged. It also removed and recreated the bootstrap alias. Limit signing to the source repository in this mode and leave the existing binary alias unchanged. --- buildrpms.pl | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/buildrpms.pl b/buildrpms.pl index 95c7655691..9ac5c76758 100755 --- a/buildrpms.pl +++ b/buildrpms.pl @@ -696,7 +696,7 @@ sub index_repo { # The stable bootstrap filename is a direct-download convenience, not a # second package. Keep it out of repository metadata. - unlink $alias if -f $alias; + unlink $alias if !$opts{source_only} && -f $alias; say "Creating repository $repodir"; # Drop the top-level stray src.rpm and the mock logs (build.log/root.log/...) # that mock leaves in the resultdir, so the dir is directly deployable (upstream @@ -719,6 +719,7 @@ sub update_repo { sub write_release_alias { my ($repodir) = @_; + return if $opts{source_only}; my $alias = "$repodir/xCAT-release-latest.noarch.rpm"; # glob() returns a wildcard-free pattern verbatim even when the file does not exist, so @@ -737,14 +738,12 @@ sub sign_rpms { sign_repo_dir("dist/$target/rpms", $opts{gpg_key_name}); } -# Sign every rpm in a core repo dir -- the top-level binaries AND SRPMS/*.src.rpm -- -# then re-index (signing rewrites the rpms, invalidating checksums) and detach-sign -# + export the key into BOTH the binary and the SRPMS repodata dirs. +# Source-only runs sign and index only SRPMS; normal runs also update the binary repository. sub sign_repo_dir { my ($repodir, $key_name) = @_; say "Signing RPMs in $repodir"; - my @bin = glob("$repodir/*.rpm"); + my @bin = $opts{source_only} ? () : glob("$repodir/*.rpm"); if (@bin) { sh_or_die(qq(rpmsign --define "%_gpg_name $key_name" --addsign ) . join(" ", map { qq("$_") } @bin), @@ -760,7 +759,7 @@ sub sign_repo_dir { # Signing can change RPM bytes without changing the size or timestamp used by the metadata cache. index_repo($repodir, 1); - for my $rd ("$repodir/repodata", + for my $rd (($opts{source_only} ? () : ("$repodir/repodata")), (-d "$repodir/SRPMS/repodata" ? ("$repodir/SRPMS/repodata") : ())) { my $repomd = "$rd/repomd.xml"; next unless -f $repomd; @@ -865,10 +864,7 @@ sub merge_core_repos { "Failed to rsync '$in' into '$out'\n"); } - # Index, sign (when --gpg-sign), write the final repository metadata, then create the - # xCAT-release-latest stable bootstrap alias. The alias MUST be created AFTER the final - # metadata pass so write_release_alias can unlink it before createrepo and keep it out of - # the repository index. + # Create the bootstrap alias after the final index pass so it does not enter repository metadata. index_repo($out); if ($opts{gpg_sign}) { $ENV{GNUPGHOME} = $opts{gpg_home} if $opts{gpg_home}; @@ -1198,11 +1194,10 @@ C<--rebuild> is skipped. ./buildrpms.pl --target alma+epel-9-x86_64 --source-only The srpms land in CtargetE/rpms/SRPMS/> and that index is regenerated. -The binary metadata under CtargetE/rpms/> is deliberately left as the -last binary build wrote it: re-indexing a directory with no binaries in it would -replace working metadata with metadata for an empty repository. For the same reason -no C<.repo> file or buildinfo is emitted, since both describe an installable binary -repo that this mode does not produce. With C<--gpg-sign> the srpms are signed. +Repository finalization leaves existing binary RPMs, metadata, signatures, +public keys and the bootstrap alias unchanged. No C<.repo> file or buildinfo is +emitted, since both describe an installable binary repo that this mode does not +produce. With C<--gpg-sign>, the source RPMs and their repository metadata are signed. Cannot be combined with C<--merge-core-repos>, which assembles already-built per-arch binary trees. @@ -1311,11 +1306,13 @@ Builds all selected package/target combinations. =item 2. -Runs C for each selected target under C. +Indexes repositories for each selected target under C. With C<--source-only>, +only the SRPM repository is indexed. =item 3. If C<--gpg-sign> is set, signs RPMs and C for each target. +With C<--source-only>, only source RPMs and their repository metadata are signed. =item 4. From a289434ae801421915c2e28b0f46caf33b4cd01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:16:08 -0300 Subject: [PATCH 13/45] test(build): cover source-only repository preservation Run the real finalization command with empty, unsigned and differently signed binary repositories, including absent and retained aliases. Check binary bytes, modes and timestamps across unsigned and repeated signed runs. Verify source package checksums and signatures with a separate source key. --- xCAT-test/native/README.md | 6 ++ xCAT-test/native/release_repository.t | 111 +++++++++++++++++++++++--- 2 files changed, 105 insertions(+), 12 deletions(-) diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index d3089e6ff3..1f072b0b33 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -63,6 +63,12 @@ they do not qualify package installation on every target architecture. On EL8, install both `python36` and `python3-rpm` to provide the interpreter and its RPM bindings. +The release case also runs source-only finalization with unsigned and signed +binary RPMs, empty binary trees, and absent, retained and standalone aliases. +It checks that binary files and aliases retain their bytes, modes and timestamps +while source RPMs and metadata use a different signing key. This covers cached +source RPMs; it does not run mock or publish a repository. + The Debian probe permission test has a separate pull-request CI step. It needs Debian build tools, BATS, bubblewrap, fakeroot, reprepro and libfile-slurper-perl. Run it as an ordinary user on a Debian or Ubuntu host diff --git a/xCAT-test/native/release_repository.t b/xCAT-test/native/release_repository.t index a1e072eb57..3e07b70bae 100644 --- a/xCAT-test/native/release_repository.t +++ b/xCAT-test/native/release_repository.t @@ -4,7 +4,8 @@ use warnings; use Digest::SHA qw(sha256_hex); use File::Basename qw(dirname); use File::Copy qw(copy); -use File::Path qw(make_path); +use File::Find qw(find); +use File::Path qw(make_path remove_tree); use File::Slurper qw(read_binary write_text); use File::Temp qw(tempdir); use FindBin; @@ -117,6 +118,73 @@ my $schedule = command("$root/work", 'unshare', '--user', '--map-root-user', '-- is(scalar(grep { $_ eq "scheduled xCAT-release-$target" } split /\n/, $schedule), 1, 'default build schedules the release package once'); +command($root, 'gpg', '--batch', '--pinentry-mode', 'loopback', '--passphrase', '', + '--quick-generate-key', 'Source Test ', 'rsa2048', 'sign', '0'); +my $source_key = command($root, 'gpg', '--armor', '--export', 'source@example.test'); +write_text("$root/source.key", $source_key); +command($root, 'rpm', '--dbpath', "$root/source-rpmdb", '--import', "$root/source.key"); +command($root, 'gpg', '--output', "$root/source-keyring.gpg", '--export', 'source@example.test'); +for my $state (qw(empty unsigned signed no-alias alias-only)) { + subtest "source-only with $state binaries" => sub { + remove_tree($cached); + make_path("$cached/SRPMS"); + copy("$root/SRPMS/$srpm", "$cached/SRPMS/$srpm") or die $!; + if ($state ne 'empty' && $state ne 'alias-only') { + command($root, 'cp', '-a', "$root/output/.", $cached); + copy("$root/SRPMS/$srpm", "$cached/SRPMS/$srpm") or die $!; + if ($state eq 'unsigned') { + copy("$root/RPMS/noarch/$rpm", "$cached/$rpm") or die $!; + command($root, 'createrepo_c', '--excludes', 'SRPMS/*', + '--excludes', 'xCAT-release-latest.noarch.rpm', $cached); + command($root, 'gpg', '--batch', '--yes', '--armor', '--detach-sign', + '--default-key', 'package@example.test', "$cached/repodata/repomd.xml"); + } + check_package_index($cached, $rpm, 'initial binary repository'); + } + if ($state eq 'no-alias') { + unlink "$cached/xCAT-release-latest.noarch.rpm" or die $!; + } elsif ($state ne 'empty') { + # Keep an older alias to detect replacement even when the versioned RPM still exists. + copy("$root/RPMS/noarch/$rpm", "$cached/xCAT-release-latest.noarch.rpm") or die $!; + chmod 0600, "$cached/xCAT-release-latest.noarch.rpm" or die $!; + utime 1600000000, 1600000000, "$cached/xCAT-release-latest.noarch.rpm" or die $!; + } + my $before = binary_snapshot($cached); + for my $attempt (0, 1, 2) { + my $signed = $attempt > 0 ? 1 : 0; + my $label = "$state source-only signed=$signed run=$attempt"; + my ($rc, $out, $err) = run_in("$root/work", 'unshare', '--user', '--map-root-user', '--mount', + 'bash', repo_path('xCAT-test/native/fixtures/buildrpms-namespace.sh'), + 'sh', '-c', 'trap \'gpgconf --homedir "$GNUPGHOME" --kill gpg-agent\' EXIT; "$@"', + 'source-test', $^X, 'buildrpms.pl', '--package', 'xCAT-release', '--target', $target, + '--release', '1', '--nproc', '1', '--source-only', + $signed ? ('--gpg-sign', '--gpg-key-name', 'source@example.test') : ()); + unless (is($rc, 0, "$label completes")) { + diag($out, $err); + return; + } + is_deeply(binary_snapshot($cached), $before, + "$label preserves all binary file bytes, modes and mtimes"); + check_package_index("$cached/SRPMS", $srpm, $label); + if ($signed) { + my $signature = command($root, 'rpmkeys', '--dbpath', "$root/source-rpmdb", + '--checksig', "$cached/SRPMS/$srpm"); + like($signature, qr/\bsignatures OK\b/, "$label verifies the source RPM signature"); + command($root, 'gpgv', '--keyring', "$root/source-keyring.gpg", + "$cached/SRPMS/repodata/repomd.xml.asc", + "$cached/SRPMS/repodata/repomd.xml"); + is(read_binary("$cached/SRPMS/repodata/repomd.xml.key"), $source_key, + "$label exports the source signing key"); + isnt(read_binary("$cached/SRPMS/$srpm"), read_binary("$root/SRPMS/$srpm"), + "$label signs the source RPM"); + } else { + is(read_binary("$cached/SRPMS/$srpm"), read_binary("$root/SRPMS/$srpm"), + "$label leaves the source RPM unsigned"); + } + } + }; +} + unlink "$root/input/$rpm" or die $!; command("$root/work", $^X, 'buildrpms.pl', '--merge-core-repos', '--target', $target, '--release', '1', '--output-dir', "$root/output", @@ -156,6 +224,35 @@ sub package_stats { return {map { $_ => [(stat("$directory/$_"))[7, 9]] } ($rpm, "SRPMS/$srpm")}; } +sub binary_snapshot { + my ($directory) = @_; + my %files; + find({no_chdir => 1, wanted => sub { + if ($File::Find::name eq "$directory/SRPMS") { + $File::Find::prune = 1; + return; + } + return unless -f $File::Find::name; + my $relative = substr($File::Find::name, length($directory) + 1); + $files{$relative} = [sha256_hex(read_binary($File::Find::name)), (stat($File::Find::name))[2, 9]]; + }}, $directory); + return \%files; +} + +sub check_package_index { + my ($repo, $filename, $label) = @_; + my @indexed = primary_packages($repo); + is(scalar(@indexed), 1, "$label indexes one $filename"); + for my $package (@indexed) { + my ($location) = $package->findnodes('./*[local-name()="location"]'); + is($location->getAttribute('href'), $filename, "$label locates $filename"); + my ($checksum) = $package->findnodes('./*[local-name()="checksum"]'); + is($checksum->getAttribute('type'), 'sha256', "$label uses SHA256 for $filename"); + is($checksum->textContent, sha256_hex(read_binary("$repo/$filename")), + "$label metadata matches final $filename bytes"); + } +} + sub check_repository { my ($directory, $signed, $label, $before) = @_; is_deeply(package_stats($directory), $before, "$label signing preserves package sizes and mtimes") @@ -165,17 +262,7 @@ sub check_repository { is(read_binary($alias), read_binary("$directory/$rpm"), "$label alias has final RPM bytes"); is((stat($alias))[2] & 0777, 0644, "$label alias is readable"); for my $entry ([$directory, $rpm], ["$directory/SRPMS", $srpm]) { - my ($repo, $filename) = @$entry; - my @indexed = primary_packages($repo); - is(scalar(@indexed), 1, "$label indexes one $filename"); - for my $package (@indexed) { - my ($location) = $package->findnodes('./*[local-name()="location"]'); - is($location->getAttribute('href'), $filename, "$label locates $filename"); - my ($checksum) = $package->findnodes('./*[local-name()="checksum"]'); - is($checksum->getAttribute('type'), 'sha256', "$label uses SHA256 for $filename"); - is($checksum->textContent, sha256_hex(read_binary("$repo/$filename")), - "$label metadata matches final $filename bytes"); - } + check_package_index(@$entry, $label); } if ($signed) { for my $repo ($directory, "$directory/SRPMS") { From 8c2ecab18c8300b601817a5b361c430fb7ae938f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:27:17 -0300 Subject: [PATCH 14/45] fix(xcat-test): scapy is a hard Depends on Debian and only a Recommends on EL Only blackboxtest's DHCP steps need scapy. dhcp.py is the single module that imports it, inside scapy_module(), which raises UnsupportedError naming python3-scapy when the import fails -- so xcat-test installs and every other blackboxtest step runs without it. xCAT-test.spec has only ever RECOMMENDED the package, and says why in a comment: a hard Requires: would make xcat-test uninstallable on a management node without EPEL. debian/control answered the same question with Depends:, which is the asymmetry this fixes. The cost is not theoretical. `apt-get install -y xcat-test` installs Recommends by default and python3-scapy recommends matplotlib, scipy and ipython3 -- 54 packages, about 255 MB -- inside a workflow step capped at 1200 seconds. On 2026-10-23 that download stalled and killed xcat_pr_test on xcat-core/#7974 at exactly 1200s, step 21, while a sibling run on another runner did the same install in 19 seconds. The job does 50 to 55 minutes of work against a 60-minute timeout, so a dependency of that size is most of its headroom. Moving it to Recommends does not by itself stop apt pulling it: an installer that wants the small package set has to ask, with --no-install-recommends. What this changes is that xcat-test no longer REQUIRES 255 MB to install, which is what the spec already said and what the code already supported. xcat_test_scapy_optional.t asserts both packagings give the same answer: scapy absent from Depends, present in Recommends, the perl dependency still a Depends, and the spec recommending rather than requiring it. Restoring the hard Depends fails one assertion; deleting the Recommends outright -- the other tempting answer -- fails a different one. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/debian/control | 8 ++- xCAT-test/unit/xcat_test_scapy_optional.t | 59 +++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/unit/xcat_test_scapy_optional.t diff --git a/xCAT-test/debian/control b/xCAT-test/debian/control index 5603e4605c..2ab87adc1d 100644 --- a/xCAT-test/debian/control +++ b/xCAT-test/debian/control @@ -8,7 +8,13 @@ Homepage: https://xcat.org/ Package: xcat-test Architecture: all -Depends: ${perl:Depends}, python3-scapy +Depends: ${perl:Depends} +# Only blackboxtest's DHCP steps need scapy, and dhcp.py imports it inside scapy_module(), +# which raises UnsupportedError naming this package when the import fails. So xcat-test +# installs and every other step runs without it, which is why xCAT-test.spec has only ever +# recommended it. A hard Depends: also pulls scapy's own recommends -- matplotlib, scipy and +# ipython3, about 255 MB over 54 packages -- into a CI step capped at 1200 seconds. +Recommends: python3-scapy Description: xCAT automated test tool Provides automated test tool and buckets to help test xCAT commands automatically. diff --git a/xCAT-test/unit/xcat_test_scapy_optional.t b/xCAT-test/unit/xcat_test_scapy_optional.t new file mode 100644 index 0000000000..9b22576723 --- /dev/null +++ b/xCAT-test/unit/xcat_test_scapy_optional.t @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +# SCAPY IS OPTIONAL, AND THE TWO PACKAGINGS MUST AGREE THAT IT IS. +# +# Only blackboxtest's DHCP steps need scapy. dhcp.py is the single module that imports it, and it +# does so inside scapy_module(), which raises UnsupportedError naming python3-scapy when the import +# fails -- so the package installs and every other blackboxtest step runs without it. +# +# xCAT-test.spec says exactly that and only RECOMMENDS the package, with the reason in a comment: +# a hard Requires: would make xCAT-test uninstallable on a management node without EPEL. +# debian/control said `Depends:`, which is the same claim with the opposite answer. +# +# The cost is not theoretical. `apt-get install -y xcat-test` installs Recommends by default, and +# python3-scapy recommends matplotlib, scipy and ipython3: 54 packages and about 255 MB, inside a +# step the GitHub workflow caps at 1200 seconds. On 2026-10-23 that download stalled and killed +# xcat_pr_test on xcat-core/#7974 at exactly 1200s, while a sibling run on another runner did the +# same install in 19 seconds. +# +# A packaging manifest is the artifact here -- there is nothing to execute and the text is the +# contract -- which is why this asserts on the files rather than on a build. +use strict; +use warnings; +use Test::More; +use FindBin; +use File::Slurper qw(read_text); + +my $root = "$FindBin::Bin/../.."; +my $control = "$root/xCAT-test/debian/control"; +my $spec = "$root/xCAT-test/xCAT-test.spec"; +ok(-f $control, 'xCAT-test/debian/control is present') or die "no control file\n"; +ok(-f $spec, 'xCAT-test/xCAT-test.spec is present') or die "no spec\n"; + +my $ctext = read_text($control); +my $stext = read_text($spec); + +# The xcat-test stanza, not the source stanza: Build-Depends lives above it. +my ($stanza) = $ctext =~ /^Package:\s*xcat-test\s*$(.*?)(?:^Package:|\z)/ms; +ok(defined $stanza && length $stanza, 'the xcat-test binary stanza is found') + or die "cannot isolate the xcat-test stanza\n"; + +my ($depends) = $stanza =~ /^Depends:\s*(.*)$/m; +my ($recommends) = $stanza =~ /^Recommends:\s*(.*)$/m; + +ok(defined $depends, 'xcat-test declares Depends'); +unlike($depends // '', qr/python3-scapy/, + 'python3-scapy is NOT a hard Depends of xcat-test'); +like($recommends // '', qr/python3-scapy/, + 'python3-scapy is Recommended instead'); +# The perl dependency is what makes the package work at all and must survive the change. +like($depends // '', qr/\$\{perl:Depends\}/, 'the perl dependency is still a Depends'); + +# PARITY. The two packagings answer the same question, so they must answer it the same way: the +# spec has recommended it since the tool was added, and the asymmetry is what this fixes. +like($stext, qr/^Recommends:\s*python3-scapy\s*$/m, 'the EL spec recommends python3-scapy'); +unlike($stext, qr/^Requires:[^\n]*python3-scapy/m, '... and does not require it'); + +# The reason belongs next to the decision, in both files, or the next person reverts it. +like($stanza, qr/scapy/i, 'the control stanza explains the choice'); + +done_testing; From 9978ff77e3f2b86812807f4c7b7aa3f2aa02f66f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 05:36:52 -0300 Subject: [PATCH 15/45] test(xcat-test): the machine type the case writes is never checked against the vmhost vm_machine_type_for_arch returns a machine type from a fixed table. Nothing asks the host that runs the guest whether it accepts that name, so a name that the host dropped is written and libvirt refuses the domain. The bats file now stubs virsh and ssh for the vmhost and asserts the name that comes back: the plain alias when the host accepts it, the host's own default when it does not, the alias again when the host cannot be reached, and the architecture and host the probe asks about. ppc64el is covered beside ppc64le because the Ubuntu cells name the architecture that way. Nine tests fail against the current script, which answers machine:pseries-rhel7.6.0 for every ppc64 architecture. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/bats/vm_machine_type.bats | 160 ++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 6 deletions(-) diff --git a/xCAT-test/bats/vm_machine_type.bats b/xCAT-test/bats/vm_machine_type.bats index 22480c09ed..3d37c76d80 100644 --- a/xCAT-test/bats/vm_machine_type.bats +++ b/xCAT-test/bats/vm_machine_type.bats @@ -1,6 +1,8 @@ #!/usr/bin/env bats # vm_machine_type.sh sets machine:invalid, then a valid machine type, then clears it again. # lsdef and chdef are shell functions that read and write vmothersetting of node cn1 in a file. +# virsh is a shell function that answers for the vmhost, and ssh runs the command it is given +# so that function answers it. MACHINES is what that vmhost declares. load 'helpers/shell_source' @@ -14,6 +16,17 @@ setup() LSDEF_FAIL=0 CHDEF_FAIL=0 CHDEF_CALLS=0 + # The vmhost of cn1, and what its libvirt declares. Every plain alias is in the set, so a + # test that does not care which host answers gets the alias. + VMHOST='' + MACHINES='pseries pseries-10.2 pc pc-i440fx-rhel10.0.0 q35 virt virt-10.2' + DEFAULT_MACHINE='' + SSH_FAIL=0 + VIRSH_ABSENT=0 + SSH_TARGETS="${BATS_TEST_TMPDIR}/ssh-targets" + VIRSH_ARCHS="${BATS_TEST_TMPDIR}/virsh-archs" + : >"$SSH_TARGETS" + : >"$VIRSH_ARCHS" } # lsdef prints no line for an attribute without a value. @@ -24,9 +37,16 @@ lsdef() return 1 fi printf 'Object name: %s\n' "$1" - if [ -s "$VMOTHER" ]; then - printf ' vmothersetting=%s\n' "$(cat "$VMOTHER")" - fi + case "$3" in + vmhost) + [ -z "$VMHOST" ] || printf ' vmhost=%s\n' "$VMHOST" + ;; + *) + if [ -s "$VMOTHER" ]; then + printf ' vmothersetting=%s\n' "$(cat "$VMOTHER")" + fi + ;; + esac } chdef() @@ -40,6 +60,56 @@ chdef() CHDEF_CALLS=$((CHDEF_CALLS + 1)) } +# virsh domcapabilities, as libvirt answers it: a --machine the host does not declare is an +# error, and the element names the default machine of the architecture. +virsh() +{ + local arch='' machine='' + + if [ "$VIRSH_ABSENT" -ne 0 ]; then + echo "bash: virsh: command not found" >&2 + return 127 + fi + [ "$1" = domcapabilities ] || return 1 + shift + while [ "$#" -gt 0 ]; do + case "$1" in + --arch) arch="$2"; shift 2 ;; + --machine) machine="$2"; shift 2 ;; + *) return 1 ;; + esac + done + printf '%s\n' "$arch" >>"$VIRSH_ARCHS" + if [ -n "$machine" ] && ! printf '%s\n' $MACHINES | grep -qx -- "$machine"; then + echo "error: invalid argument: the machine '$machine' is not supported by emulator" >&2 + return 1 + fi + echo '' + [ -z "$DEFAULT_MACHINE" ] || printf ' %s\n' "$DEFAULT_MACHINE" + echo '' +} + +# ssh records the host it was asked for and runs the command, so the virsh function above +# answers it. Real ssh joins the command words with spaces for the remote shell. +ssh() +{ + local target='' + + while [ "$#" -gt 0 ]; do + case "$1" in + -o) shift 2 ;; + -*) shift ;; + *) target="$1"; shift; break ;; + esac + done + printf '%s\n' "$target" >>"$SSH_TARGETS" + if [ "$SSH_FAIL" -ne 0 ]; then + echo "ssh: connect to host $target port 22: No route to host" >&2 + return 255 + fi + "$@" +} + set_vmother() { printf '%s' "$1" >"$VMOTHER" @@ -69,9 +139,9 @@ assert_arch() [ "$CHDEF_CALLS" -eq 3 ] } -@test "ppc64le: the case sets and clears pseries-rhel7.6.0" { - assert_arch ppc64le pseries-rhel7.6.0 '' - assert_arch ppc64le pseries-rhel7.6.0 'cpumode:host-passthrough' +@test "ppc64le: the case sets and clears pseries" { + assert_arch ppc64le pseries '' + assert_arch ppc64le pseries 'cpumode:host-passthrough' } @test "x86_64: the case sets and clears pc" { @@ -89,6 +159,84 @@ assert_arch() assert_arch aarch64 virt 'cpumode:host-passthrough' } +# The machine type comes from the vmhost, because the vmhost is what refuses the domain. +# AlmaLinux 10 on the ppc64le vmhost declares pseries-5.0 to pseries-10.2 and no rhel machine +# type at all, so a name from the RHEL 7.6 era is rejected at define time. + +@test "ppc64le: the machine type is the alias the vmhost accepts" { + MACHINES='pseries pseries-10.2 pseries-9.2' + run vm_machine_type_for_arch ppc64le 192.0.2.10 + [ "$status" -eq 0 ] + [ "$output" = 'machine:pseries' ] +} + +@test "ppc64le: the vmhost accepts the machine type that comes back" { + local machine + MACHINES='pseries pseries-10.0 pseries-10.1 pseries-10.2' + machine="$(vm_machine_type_for_arch ppc64le 192.0.2.10)" + [ "${machine#machine:}" != "$machine" ] + run virsh domcapabilities --arch ppc64 --machine "${machine#machine:}" + [ "$status" -eq 0 ] +} + +@test "ppc64le: the libvirt default stands in when the vmhost refuses the alias" { + MACHINES='pseries-10.2' + DEFAULT_MACHINE='pseries-10.2' + run vm_machine_type_for_arch ppc64le 192.0.2.10 + [ "$status" -eq 0 ] + [ "$output" = 'machine:pseries-10.2' ] +} + +@test "ppc64le: the alias stands in when the vmhost cannot be reached" { + SSH_FAIL=1 + run vm_machine_type_for_arch ppc64le 192.0.2.10 + [ "$status" -eq 0 ] + [ "$output" = 'machine:pseries' ] +} + +@test "ppc64le: the alias stands in when the vmhost has no virsh" { + VIRSH_ABSENT=1 + run vm_machine_type_for_arch ppc64le 192.0.2.10 + [ "$status" -eq 0 ] + [ "$output" = 'machine:pseries' ] +} + +@test "ppc64el: the Debian architecture name gets the same machine type" { + MACHINES='pseries pseries-10.2' + run vm_machine_type_for_arch ppc64el 192.0.2.10 + [ "$status" -eq 0 ] + [ "$output" = 'machine:pseries' ] +} + +@test "apply asks the vmhost of the node about architecture ppc64" { + VMHOST=192.0.2.10 + MACHINES='pseries pseries-10.2' + set_vmother '' + vm_machine_type_main invalid cn1 + vm_machine_type_main apply cn1 ppc64le + [ "$(vmother)" = 'machine:pseries' ] + [ "$(sort -u "$SSH_TARGETS")" = '192.0.2.10' ] + [ "$(sort -u "$VIRSH_ARCHS")" = 'ppc64' ] +} + +@test "apply reads the local libvirt when the node names no vmhost" { + MACHINES='pseries pseries-10.2' + set_vmother '' + vm_machine_type_main invalid cn1 + vm_machine_type_main apply cn1 ppc64le + [ "$(vmother)" = 'machine:pseries' ] + [ ! -s "$SSH_TARGETS" ] + [ "$(sort -u "$VIRSH_ARCHS")" = 'ppc64' ] +} + +@test "x86_64: the machine type stays pc, which the vmhost accepts" { + MACHINES='pc pc-i440fx-rhel10.0.0 q35' + DEFAULT_MACHINE='pc-i440fx-rhel10.0.0' + run vm_machine_type_for_arch x86_64 192.0.2.10 + [ "$status" -eq 0 ] + [ "$output" = 'machine:pc' ] +} + # assert_round_trip -- the case ends with the exact value it started with. assert_round_trip() { From b37793400d26dfd0819a191e0712f72b2749ea2e Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 05:38:14 -0300 Subject: [PATCH 16/45] fix(xcat-test): libvirt refuses the compute node machine type pseries-rhel7.6.0 reg_linux_diskless_installation_flat fails on every ppc64le cell. rpower boot leaves the compute node down and libvirt reports "unsupported configuration: Emulator '/usr/bin/qemu-system-ppc64' does not support machine type 'pseries-rhel7.6.0'". vm_machine_type_for_arch in vm_machine_type.sh answered machine:pseries-rhel7.6.0 for every ppc64 architecture. The ppc64le hypervisor runs AlmaLinux 10, whose qemu-system-ppc64 declares pseries-5.0 to pseries-10.2 and no rhel machine type, so the name the case writes cannot be defined there. The function now reads the vmhost of the node and asks that host's libvirt. It writes the plain alias when libvirt accepts it, that libvirt's own default when it does not, and the alias when the vmhost cannot be asked. x86_64 keeps machine:pc, which is an alias and stays valid. xCAT-test/bats/vm_machine_type.bats covers it. Nine of its tests fail on the previous commit, among them "the vmhost accepts the machine type that comes back" and "the machine type is the alias the vmhost accepts". Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../testcase/commoncmd/vm_machine_type.sh | 79 +++++++++++++++++-- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh b/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh index 412a16c771..0f5914bdd2 100755 --- a/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh +++ b/xCAT-test/autotest/testcase/commoncmd/vm_machine_type.sh @@ -33,17 +33,84 @@ vm_machine_type_private_dir() fi } -vm_machine_type_for_arch() +# alias -- the machine name qemu keeps pointed at the newest machine of a family. +vm_machine_type_alias() { case "$1" in - ppc64*) echo 'machine:pseries-rhel7.6.0' ;; - x86_64) echo 'machine:pc' ;; - riscv64) echo 'machine:virt' ;; - aarch64) echo 'machine:virt' ;; + ppc64*) echo 'pseries' ;; + x86_64) echo 'pc' ;; + riscv64) echo 'virt' ;; + aarch64) echo 'virt' ;; *) return 1 ;; esac } +# libvirt and qemu call the ppc64le guest architecture ppc64. A node on an +# Ubuntu cell names it ppc64el. +vm_machine_type_libvirt_arch() +{ + case "$1" in + ppc64*) echo 'ppc64' ;; + x86_64) echo 'x86_64' ;; + riscv64) echo 'riscv64' ;; + aarch64) echo 'aarch64' ;; + *) return 1 ;; + esac +} + +# virsh on , or here when is empty. kvm.pm reaches the vmhost over +# qemu+ssh://root@/system, so root can ssh there from this node. +vm_machine_type_virsh() +{ + local host="$1" + shift + if [ -n "$host" ]; then + ssh -o BatchMode=yes -o ConnectTimeout=10 -n "$host" virsh "$@" + else + virsh "$@" + fi +} + +# supported -- whether libvirt on accepts . +vm_machine_type_supported() +{ + vm_machine_type_virsh "$1" domcapabilities --arch "$2" --machine "$3" >/dev/null 2>&1 +} + +# default -- the machine type libvirt on uses for . +vm_machine_type_default() +{ + vm_machine_type_virsh "$1" domcapabilities --arch "$2" 2>/dev/null | + sed -n 's|.*\(.*\).*|\1|p' | head -n 1 +} + +# for_arch [] -- the machine type to write, as "machine:". +# +# The vmhost is what refuses the domain, so its libvirt picks the name: the plain +# alias when that libvirt accepts it, its own default when it does not, and the +# alias again when the vmhost cannot be asked. A versioned name does not survive +# a host upgrade -- no qemu on AlmaLinux 10 has a pseries-rhel machine type. +vm_machine_type_for_arch() +{ + local arch="$1" vmhost="${2-}" generic libvirt_arch name + + generic="$(vm_machine_type_alias "$arch")" || return 1 + libvirt_arch="$(vm_machine_type_libvirt_arch "$arch")" || return 1 + if vm_machine_type_supported "$vmhost" "$libvirt_arch" "$generic"; then + printf 'machine:%s\n' "$generic" + return + fi + name="$(vm_machine_type_default "$vmhost" "$libvirt_arch")" + printf 'machine:%s\n' "${name:-$generic}" +} + +# vmhost -- the host whose libvirt runs the guest, empty when unset. +vm_machine_type_vmhost() +{ + lsdef "$1" -i vmhost 2>/dev/null | + sed -n 's/^[[:space:]]*vmhost=//p' | head -n 1 +} + vm_machine_type_get() { local out @@ -109,7 +176,7 @@ vm_machine_type_apply() chdef "$node" "vmothersetting=$original" return fi - if ! machine="$(vm_machine_type_for_arch "$arch")"; then + if ! machine="$(vm_machine_type_for_arch "$arch" "$(vm_machine_type_vmhost "$node")")"; then echo "vm_machine_type.sh: no machine type for arch '$arch'" >&2 return 1 fi From 1d52b46e29bb96258a1221ba32e90d338e84f5ab Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 10:01:16 -0300 Subject: [PATCH 17/45] test(xcat-core): the Ubuntu Genesis image can ship mawk as its awk The Genesis image runs allowcred.awk, minixcatd.awk and udpcat.awk under its own /usr/bin/awk. All three open a TCP stream with the gawk |& coprocess and the /inet/ special file, which mawk rejects at parse time. The Ubuntu dracut module stages /usr/bin/awk from the build root, and on Ubuntu that alternative is mawk. genesis_ubuntu_awk.bats drives install() from dracut_105/ubuntu/module-setup.sh with the dracut helpers replaced by stubs, and reads back what the module installs and where awk in the image points. genesis_ubuntu_build_root.t asks the build root for a gawk package. genesis_payload_verification.t gives XCAT::GenesisPayload a payload whose awk names itself mawk. All three fail on this commit: 3 of 3 bats assertions, 2 of 18 in the build-root test, 3 of 33 in the payload test. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/bats/genesis_ubuntu_awk.bats | 69 +++++++++++++++++++ xCAT-test/unit/genesis_payload_verification.t | 32 +++++++++ xCAT-test/unit/genesis_ubuntu_build_root.t | 4 ++ 3 files changed, 105 insertions(+) create mode 100644 xCAT-test/bats/genesis_ubuntu_awk.bats diff --git a/xCAT-test/bats/genesis_ubuntu_awk.bats b/xCAT-test/bats/genesis_ubuntu_awk.bats new file mode 100644 index 0000000000..5bb1606a7d --- /dev/null +++ b/xCAT-test/bats/genesis_ubuntu_awk.bats @@ -0,0 +1,69 @@ +#!/usr/bin/env bats +# +# The awk the Ubuntu Genesis image carries. +# +# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& coprocess +# and the /inet/ special file. mawk rejects both at parse time, and mawk is the awk +# alternative on a Debian or Ubuntu build root, so the module cannot stage the host's +# /usr/bin/awk. + +load 'helpers/shell_source' + +setup() +{ + MODULE="$(repo_path 'xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh')" + [ -r "$MODULE" ] || skip "$MODULE is required" + export MODULE +} + +# Run install() from the dracut module with the dracut helpers replaced by stubs. Sets +# INSTALLED to one installed name per line, and INITDIR to the staged image root. +run_install() +{ + local dir="${BATS_TEST_TMPDIR}/module" + + rm -rf "$dir" + mkdir -p "$dir/initdir/usr/bin" "$dir/initdir/bin" + + # No "set -u": _dracut_install_opt() in the module reads $2 unset, which real dracut + # allows. + cat >"$dir/drive.sh" <<'SH' +initdir="$1" +record="$2" +moddir=/dev/null +kernel= +dracut_install() { for name in "$@"; do printf '%s\n' "$name" >>"$record"; done; } +instmods() { :; } +inst() { :; } +inst_script() { :; } +inst_dir() { :; } +inst_hook() { :; } +inst_symlink() { :; } +. "$MODULE" +install >/dev/null 2>&1 +SH + + /bin/bash "$dir/drive.sh" "$dir/initdir" "$dir/installed" || true + INSTALLED="$(read_file_or_empty "$dir/installed")" + INITDIR="$dir/initdir" +} + +@test "the module installs gawk by name" { + run_install + printf '%s\n' "$INSTALLED" | grep -qx 'gawk' +} + +@test "the module does not stage the build host's awk alternative" { + # On Ubuntu /usr/bin/awk resolves to mawk, so staging it ships an awk that cannot parse + # the Genesis awk programs. + run_install + refute_grep -qx '/usr/bin/awk' <(printf '%s\n' "$INSTALLED") + refute_grep -qx 'awk' <(printf '%s\n' "$INSTALLED") +} + +@test "awk in the image points at gawk" { + # The awk programs start with #!/usr/bin/awk -f, so the name awk has to be gawk. + run_install + [ -L "$INITDIR/usr/bin/awk" ] + [ "$(readlink "$INITDIR/usr/bin/awk")" = 'gawk' ] +} diff --git a/xCAT-test/unit/genesis_payload_verification.t b/xCAT-test/unit/genesis_payload_verification.t index 2d8ee7b6c2..60b293e2e4 100644 --- a/xCAT-test/unit/genesis_payload_verification.t +++ b/xCAT-test/unit/genesis_payload_verification.t @@ -19,6 +19,12 @@ use XCAT::GenesisPayload qw(module_commands missing_paths check_payload); my $OPENSSH_99 = "OpenSSH_9.9p1\n/usr/libexec/openssh/sshd-session\n"; my $OPENSSH_80 = "OpenSSH_8.0p1\n"; +# The two awk programs name themselves in their own binary. +my $GAWK = "GNU Awk 5.2.2, API 3.2\n"; +my $MAWK = "mawk 1.3.4 20240123\n"; +my $AWK_NOT_GAWK = + 'usr/bin/awk is not gawk (allowcred.awk opens its TCP stream with the gawk /inet/ coprocess)'; + # A complete payload: OpenSSH 9.9 sshd plus its session helper, tmux plus a UTF-8 locale. my @COMPLETE = qw( usr/sbin/sshd usr/libexec/openssh/sshd-session usr/bin/tmux @@ -72,6 +78,18 @@ is_deeply([ missing_paths(all_but('usr/libexec/openssh/sshd-session'), sshd => $ is_deeply([ missing_paths(all_but('usr/lib/locale/C.utf8/LC_CTYPE', 'usr/bin/tmux'), sshd => $OPENSSH_99) ], [], 'a payload without tmux needs no locale'); +# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& coprocess +# and the /inet/ special file. mawk rejects both at parse time, so the node asks for no +# credential and reports no flag, and nothing in the build says why. +is_deeply([ missing_paths(carries(@COMPLETE), sshd => $OPENSSH_99, awk => $GAWK) ], + [], 'a payload whose awk is gawk passes'); +is_deeply([ missing_paths(carries(@COMPLETE), sshd => $OPENSSH_99, awk => $MAWK) ], + [$AWK_NOT_GAWK], 'a payload whose awk is mawk fails and says so'); + +# An awk with no name in it is not gawk either. busybox awk has no /inet/ support. +is_deeply([ missing_paths(carries(@COMPLETE), sshd => $OPENSSH_99, awk => "busybox\n") ], + [$AWK_NOT_GAWK], 'an awk that is neither gawk nor mawk fails too'); + # dracut_install reports a missing binary and returns, so every name the dracut module # installs has to be checked against the payload. A name starting with "/" is installed at # that same path; the rest are commands. @@ -149,6 +167,20 @@ is_deeply([ check_payload($nohelper) ], [ 1, "verify-genesis-payload: $nohelper is incomplete:\n" . " usr/libexec/openssh/sshd-session (this sshd execs it for every connection)\n" ], 'the command line reads usr/sbin/sshd to decide on sshd-session'); + +my $mawk = payload_tree(@COMPLETE); +write_text("$mawk/usr/sbin/sshd", $OPENSSH_99); +write_text("$mawk/usr/bin/awk", $MAWK); +is_deeply([ check_payload($mawk) ], + [ 1, "verify-genesis-payload: $mawk is incomplete:\n $AWK_NOT_GAWK\n" ], + 'the command line reads usr/bin/awk back out of the payload'); + +my $gawk = payload_tree(@COMPLETE); +write_text("$gawk/usr/sbin/sshd", $OPENSSH_99); +write_text("$gawk/usr/bin/awk", $GAWK); +is_deeply([ check_payload($gawk) ], + [ 0, "verify-genesis-payload: $gawk is complete\n" ], + 'a payload whose awk is gawk passes on the command line'); is_deeply([ check_payload('--commands-from', $module, $nodhcp) ], [ 0, "verify-genesis-payload: $nodhcp is complete\n" ], '--commands-from does not require a name installed under a condition'); diff --git a/xCAT-test/unit/genesis_ubuntu_build_root.t b/xCAT-test/unit/genesis_ubuntu_build_root.t index e04a746957..977f7b249d 100755 --- a/xCAT-test/unit/genesis_ubuntu_build_root.t +++ b/xCAT-test/unit/genesis_ubuntu_build_root.t @@ -31,6 +31,10 @@ my %PACKAGES_FOR = ( dhclient => ['isc-dhcp-client'], ifenslave => ['ifenslave'], hwclock => [ 'util-linux-extra', 'util-linux' ], + + # mawk is the awk alternative on a Debian or Ubuntu root, and it rejects the gawk + # /inet/ coprocess at parse time, so the module names gawk rather than awk. + gawk => ['gawk'], ); # A release carries exactly the names in its list. From c14d79790aca51df8225dccf511f2a3e8b563f5c Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 10:04:15 -0300 Subject: [PATCH 18/45] fix(xcat-core): the Ubuntu Genesis image runs its awk programs under mawk An Ubuntu compute node booted into legacy Genesis never reports a destiny. The console shows doxcat reach "Getting initial certificate", then: awk: 8: unexpected character '&' awk: /usr/bin/allowcred.awk: line 14: syntax error at or near } and the node stays in powering-on until the case times out. The payload built on 2026-10-23 carries /usr/bin/awk as a symlink to mawk, with no gawk. allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& coprocess and the /inet/ special file. mawk rejects both at parse time. install() in dracut_105/ubuntu/module-setup.sh staged /usr/bin/awk from the build root, and on Ubuntu that alternative is mawk, so the image got an awk that cannot parse its own programs. The EL payload is unaffected: there /usr/bin/awk is gawk. install() now installs gawk by name and points usr/bin/awk at it, the build root carries gawk, and XCAT::GenesisPayload reads usr/bin/awk back and refuses a payload whose awk is not gawk. dracut_install reports a missing command and returns, and awk is a symlink the module makes itself, so nothing in the build said why. genesis_ubuntu_awk.bats, genesis_ubuntu_build_root.t and genesis_payload_verification.t fail on the parent commit and pass on this one. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../dracut_105/ubuntu/module-setup.sh | 8 +++- .../lib/XCAT/GenesisBuildRoot.pm | 2 +- xCAT-genesis-base/lib/XCAT/GenesisPayload.pm | 43 ++++++++++++++++--- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh b/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh index 367439ce4f..65893b6221 100755 --- a/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh +++ b/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh @@ -49,7 +49,13 @@ install() { _dracut_install_opt mstflint dracut_install netstat # broadcom update requires dracut_install uniq # mellanox update requires - dracut_install grep ip hostname /usr/bin/awk egrep grep dirname expr + dracut_install grep ip hostname egrep grep dirname expr + + # allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& + # coprocess and the /inet/ special file. mawk rejects both at parse time, and mawk is + # the awk alternative on this build root, so name gawk and point awk at it. + dracut_install gawk + ln -sf gawk "$initdir/usr/bin/awk" dracut_install mount.nfs sshd vi reboot lspci parted screen mkfs mkfs.ext4 mkfs.btrfs #dracut_install libvirtd /usr/share/libvirt/cpu_map.xml /usr/bin/qemu-img /usr/libexec/qemu-kvm dracut_install mkswap df ifenslave ssh-keygen scp clear diff --git a/xCAT-genesis-base/lib/XCAT/GenesisBuildRoot.pm b/xCAT-genesis-base/lib/XCAT/GenesisBuildRoot.pm index 58c981a3fd..b6afd8dc0d 100644 --- a/xCAT-genesis-base/lib/XCAT/GenesisBuildRoot.pm +++ b/xCAT-genesis-base/lib/XCAT/GenesisBuildRoot.pm @@ -14,7 +14,7 @@ my @BASE_PACKAGES = qw( openssh-server openssh-client rsyslog chrony nfs-common rpcbind pciutils usbutils parted dosfstools e2fsprogs lvm2 mdadm net-tools - bc psmisc rsync wget cpio + bc psmisc rsync wget cpio gawk isc-dhcp-client ifenslave systemd-sysv hwdata btrfs-progs netcat-openbsd iputils-ping fdisk ncurses-term dpkg-dev debhelper fakeroot devscripts vim-tiny diff --git a/xCAT-genesis-base/lib/XCAT/GenesisPayload.pm b/xCAT-genesis-base/lib/XCAT/GenesisPayload.pm index 135bd925e0..366fc26dbc 100644 --- a/xCAT-genesis-base/lib/XCAT/GenesisPayload.pm +++ b/xCAT-genesis-base/lib/XCAT/GenesisPayload.pm @@ -67,6 +67,7 @@ sub module_commands { path is looked for under the payload root. source: the module the commands came from, for the message sshd: the content of usr/sbin/sshd, or undef without one + awk: the content of usr/bin/awk, or undef without one Returns: one " ()" string per missing item, in the order checked. An empty list means the payload is complete. @@ -106,6 +107,15 @@ sub missing_paths { "usr/libexec/openssh/sshd-session (this sshd execs it for every connection)"; } + # allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& + # coprocess and the /inet/ special file. mawk rejects both at parse time and the node + # then asks for no credential, so read the binary back. gawk carries its own name. An + # empty file carries no name and is not a program, so there is nothing to read. + if (length($opt{awk} // '') && index($opt{awk}, 'GNU Awk') < 0) { + push @missing, + 'usr/bin/awk is not gawk (allowcred.awk opens its TCP stream with the gawk /inet/ coprocess)'; + } + # tmux exits under the C locale. The hook then runs doxcat directly, but a Genesis # shell without tmux loses the console attach. if ($have->('usr/bin/tmux') && !$have->('usr/lib/locale/C.utf8/LC_CTYPE')) { @@ -157,17 +167,13 @@ sub check_payload { return (2, $@) if $@; } - my $sshd; - if (open(my $fh, '<:raw', "$payload/usr/sbin/sshd")) { - local $/; - $sshd = <$fh> // ''; - close($fh); - } + my ($sshd, $awk) = (slurp("$payload/usr/sbin/sshd"), slurp("$payload/usr/bin/awk")); my @missing = missing_paths(sub { -e "$payload/$_[0]" }, required => \@args, commands => \@commands, source => $commands_from, - sshd => $sshd); + sshd => $sshd, + awk => $awk); return (1, "$ME: $payload is incomplete:" . join('', map { "\n $_" } @missing) . "\n") if @missing; return (0, "$ME: $payload is complete\n"); @@ -175,6 +181,29 @@ sub check_payload { #------------------------------------------------------------------------------- +=head3 slurp + + Descriptions: read a file whole, in raw mode. usr/bin/awk and usr/sbin/sshd are + binaries, and both are read to tell one program from another. + Arguments: + $path: the path to read + Returns: + the content, or undef when the file cannot be read + +=cut + +#------------------------------------------------------------------------------- +sub slurp { + my ($path) = @_; + open(my $fh, '<:raw', $path) or return undef; + local $/; + my $content = <$fh> // ''; + close($fh); + return $content; +} + +#------------------------------------------------------------------------------- + =head3 main Descriptions: run check_payload and print its message: on STDOUT when the From 3dd7c2a590c5fa864faaec701dea07844d8be0bb Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:27:04 -0300 Subject: [PATCH 19/45] fix(xcat-core): a node-initiated request is dropped when only its reverse lookup fails xcatd fills _xcat_clienthost and _xcat_clientfqdn from a reverse lookup of the client socket, so both are empty when that lookup fails, however good the client credentials are. A plugin that asks only for the peer host therefore cannot identify a node whose certificate names it correctly. xCAT::DiscoveryUtils::request_client_names returns the names a request offers, most trustworthy first: the peer host, its fully qualified form, then _xcat_authname, which is the name in the validated client certificate and does not depend on name resolution. The request's own node attribute is excluded on purpose -- a client sends it, so it states what the client wants to be rather than what it proved it is, and postscripts carry the cluster root ssh key. xCAT-test/unit/getpostscript_client_identity.t drives the routine directly: the request hash is its only input and a list of names its only output. It fails on five mutants of the routine, each naming the assertion it breaks -- the certificate name dropped (2 checks), the empty-name guard dropped (1), the client-supplied node offered (3), the de-duplication dropped (2), and the array-ref guard dropped (1). Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- perl-xCAT/xCAT/DiscoveryUtils.pm | 35 ++++++++ .../unit/getpostscript_client_identity.t | 83 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 xCAT-test/unit/getpostscript_client_identity.t diff --git a/perl-xCAT/xCAT/DiscoveryUtils.pm b/perl-xCAT/xCAT/DiscoveryUtils.pm index e5c17cfca5..867293f4de 100644 --- a/perl-xCAT/xCAT/DiscoveryUtils.pm +++ b/perl-xCAT/xCAT/DiscoveryUtils.pm @@ -120,4 +120,39 @@ sub update_discovery_data { } } +#------------------------------------------------------------------------------- + +=head3 request_client_names + + Descriptions: The names a node-initiated request offers for correlating it to a node, most + trustworthy first. + + xcatd fills _xcat_clienthost and _xcat_clientfqdn from a reverse lookup of the + peer socket, so both are empty when that lookup fails, however good the client + credentials are. _xcat_authname is the name in the validated client certificate + and does not depend on name resolution. + + The request's own node attribute is NOT a candidate. A client sends it, so it + states what the client wants to be rather than what it proved it is. + + Arguments : $request - the request hash xcatd built + Returns : the candidate names, without duplicates; an empty list when there are none + +=cut + +#------------------------------------------------------------------------------- +sub request_client_names { + my ($request) = @_; + return () unless ref($request) eq 'HASH'; + my @names; + foreach my $key (qw(_xcat_clienthost _xcat_clientfqdn _xcat_authname)) { + my $value = $request->{$key}; + next unless ref($value) eq 'ARRAY'; + my $name = $value->[0]; + next unless defined $name && $name ne ''; + push @names, $name unless grep { $_ eq $name } @names; + } + return @names; +} + 1; diff --git a/xCAT-test/unit/getpostscript_client_identity.t b/xCAT-test/unit/getpostscript_client_identity.t new file mode 100644 index 0000000000..04c6c6a4ac --- /dev/null +++ b/xCAT-test/unit/getpostscript_client_identity.t @@ -0,0 +1,83 @@ +#!/usr/bin/env perl +# A diskless node that boots and cannot be correlated to a node gets no postscripts, and that +# costs the whole provision: remoteshell never installs root's authorized_keys, so every xdsh and +# ssh answers "Permission denied (publickey)" on a node that answers ping, and nothing ever +# reports "booted". +# +# Measured on xcat59-mn, an openEuler 22.03sp4 management node, on 2026-10-24. xcatd logged +# "xCAT: Allowing getpostscript xcat59-cn" with no "from " and then "Received malformed +# getpostscript requesting, ignore it." -- 100 times, 0 "Sending scripts data" in the whole log, +# against 3 sends and 0 malformed on the green openEuler 24.03sp4 cell beside it. The client +# certificate named the node correctly; only the reverse lookup of the peer socket failed, and +# getpostscript.pm looked at nothing else. +# +# So the identity a request offers is its own decision, and this is it. The request hash is the +# only input and a list of names is the only output, so it is driven directly. +use strict; +use warnings; + +use FindBin; +use File::Spec; +use Test::More; +use lib File::Spec->catdir($FindBin::Bin, '..', '..', 'perl-xCAT'), + File::Spec->catdir($FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'perl'); +use xCAT::DiscoveryUtils; + +sub names_for { return xCAT::DiscoveryUtils::request_client_names($_[0]) } + +# The resolved peer stays first, so a management node whose reverse lookup works behaves exactly +# as it did. +is_deeply([ names_for({ _xcat_clienthost => ['xcat58-cn'], + _xcat_clientfqdn => ['xcat58-cn.xcat58.lab'], + _xcat_authname => ['xcat58-cn'] }) ], + [ 'xcat58-cn', 'xcat58-cn.xcat58.lab' ], + 'the resolved peer host comes first, and the certificate name adds no duplicate'); + +# The failure measured on xcat59-mn: xcatd set the peer host to the empty string, because the +# reverse lookup returned nothing. An empty name is not a name. +is_deeply([ names_for({ _xcat_clienthost => [''], + _xcat_clientfqdn => [''], + _xcat_authname => ['xcat59-cn'] }) ], + [ 'xcat59-cn' ], + 'an empty peer host is skipped and the certificate name is offered instead'); + +# The same request with the keys absent rather than empty. +is_deeply([ names_for({ _xcat_authname => ['xcat59-cn'] }) ], [ 'xcat59-cn' ], + 'a request carrying only a certificate name still identifies its node'); + +# The fqdn alone is enough when the short name did not resolve. +is_deeply([ names_for({ _xcat_clientfqdn => ['xcat59-cn.xcat59.lab'] }) ], + [ 'xcat59-cn.xcat59.lab' ], + 'the fully qualified peer name is offered when the short name is missing'); + +# The node attribute is client-supplied: it says what the client wants to be. Offering it would +# let any host that can reach port 3001 ask for another node's postscripts, which carry the +# cluster's root ssh key. +for my $request ({ node => ['xcat59-cn'] }, + { node => ['xcat59-cn'], _xcat_clienthost => [''] }, + { node => ['some-other-node'], _xcat_authname => ['xcat59-cn'] }) { + my @got = names_for($request); + ok(!grep({ $_ eq ($request->{node}->[0]) } @got), + "the request's own node attribute is never offered as an identity (" + . join(',', @got) . ')'); +} + +# Nothing to go on is an empty list, not an empty name: the caller must be able to tell the +# difference and say so. +is_deeply([ names_for({}) ], [], 'a request with no identity at all offers no name'); +is_deeply([ names_for(undef) ], [], 'an undefined request offers no name'); +is_deeply([ names_for('string') ], [], 'a request that is not a hash offers no name'); +# Wrapped in eval, because without the guard the sub DIES here rather than returning a wrong +# answer, and a test that dies names no assertion -- it reports as a count discrepancy that is +# easy to skim past in a prove summary. +my @unwrapped = eval { names_for({ _xcat_clienthost => 'xcat59-cn' }) }; +is($@, '', 'a value xcatd did not wrap in an array ref does not kill the lookup'); +is_deeply(\@unwrapped, [], 'and is ignored rather than dereferenced'); + +# Duplicates would make the caller try the same noderange twice and log the same failure twice. +is_deeply([ names_for({ _xcat_clienthost => ['xcat59-cn'], + _xcat_clientfqdn => ['xcat59-cn'], + _xcat_authname => ['xcat59-cn'] }) ], + [ 'xcat59-cn' ], 'the same name arriving three ways is offered once'); + +done_testing(); From 6dfcdcbc48601cd040925ef65f7df448e01b6267 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:27:04 -0300 Subject: [PATCH 20/45] fix(xcat-core): getpostscript serves no node when the management node cannot reverse-resolve it A diskless openEuler 22.03sp4 node netbooted, took a lease, reached a login prompt and answered ping, and then every xdsh and ssh answered "root@xcat59-cn: Permission denied (publickey)" while the node never reported "booted". reg_linux_diskless_installation_flat failed after 7072 s. xcatd on that management node logged "xCAT: Allowing getpostscript xcat59-cn" with no "from ", then "Received malformed getpostscript requesting, ignore it." -- 100 times, with 0 "Sending scripts data" in the whole log. The green openEuler 24.03sp4 cell beside it logged 3 sends and 0 malformed. The client certificate named the node correctly; only the reverse lookup of the peer socket failed. getpostscript read _xcat_clienthost and nothing else, so it dropped every request. No postscript ran: remoteshell never installed root's authorized_keys, which is the ssh failure, and nothing updated node status, which is the stuck "powering-on". One cause, both symptoms. process_request now tries each name xCAT::DiscoveryUtils::request_client_names offers and takes the first that correlates to a node. A request that offers no name at all, and one whose names correlate to nothing, are now reported as what they are; the old message said the request was malformed, which sent two investigations into DNS and the netboot image. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-server/lib/xcat/plugins/getpostscript.pm | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/getpostscript.pm b/xCAT-server/lib/xcat/plugins/getpostscript.pm index 2ba655dd35..130ee1ba61 100644 --- a/xCAT-server/lib/xcat/plugins/getpostscript.pm +++ b/xCAT-server/lib/xcat/plugins/getpostscript.pm @@ -11,6 +11,7 @@ package xCAT_plugin::getpostscript; use xCAT::Utils; use xCAT::MsgUtils; use xCAT::NodeRange; +use xCAT::DiscoveryUtils; 1; #------------------------------------------------------- @@ -57,23 +58,31 @@ sub process_request my $client; + my @candidates; if ($::XCATSITEVALS{nodeauthentication}) { #if requiring node authentication, this request will have a certificate associated with it, use it instead of name resolution unless (ref $request->{username}) { return; } #TODO: log an attempt without credentials? - $client = $request->{username}->[0]; + @candidates = ($request->{username}->[0]); } else { - unless ($request->{'_xcat_clienthost'}->[0]) { - - #ERROR? malformed request - xCAT::MsgUtils->trace(0, 'E', "Received malformed getpostscript requesting, ignore it."); + # The peer host and fqdn are a reverse lookup of the client socket, so both are empty when + # that lookup fails, however good the client credentials are. Asking only for the peer host + # cost every postscript of an openEuler 22.03sp4 node on 2026-10-24: the certificate named + # the node, the reverse lookup did not, and 100 requests were dropped while 0 were served. + # request_client_names adds the certificate name, and excludes the request's own node + # attribute, which the client sends and has not proved. + @candidates = xCAT::DiscoveryUtils::request_client_names($request); + unless (@candidates) { + xCAT::MsgUtils->trace(0, 'E', "Received getpostscript from a client this request does not identify: it carries no peer name and no client certificate name. Ignoring it."); return; } - $client = $request->{'_xcat_clienthost'}->[0]; } - my $origclient = $client; - if ($client) { ($client) = noderange($client) } + foreach my $candidate (@candidates) { + next unless defined $candidate && $candidate ne ''; + my ($node) = noderange($candidate); + if ($node) { $client = $node; last; } + } unless ($client) { #Not able to do identify the host in question - xCAT::MsgUtils->trace(0, "E", "Received getpostscript from $origclient, which couldn't be correlated to a node (domain mismatch?)"); + xCAT::MsgUtils->trace(0, "E", "Received getpostscript from " . join(', ', @candidates) . ", none of which could be correlated to a node (domain mismatch?)"); return; } my $state; From 1435077a4b3348cfe07098fcc59ce229ef0493d1 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:21:39 -0300 Subject: [PATCH 21/45] test(xcat-core): the client-identity test does not say which tree it measured Ninety xCAT modules carry BEGIN { $::XCATROOT = $ENV{XCATROOT} || '/opt/xcat' } use lib "$::XCATROOT/lib/perl"; so the first xCAT module a test loads can put an installed product in front of the checkout in @INC. A build host has one: xcat-master carries /opt/xcat/lib/perl/xCAT/DiscoveryUtils.pm. A run that loaded that copy would pass while measuring a product built weeks ago, and nothing in the test said otherwise. The test now reports the file that answered, refuses one under /opt/xcat, and asserts the routine exists. A stale copy winning @INC lacks it, so the file goes red instead of passing on three assertions that never ran against this change. Measured both ways: on a host with no xCAT the module resolves to perl-xCAT/xCAT/DiscoveryUtils.pm, and on xcat-master, which has an installed copy, it still resolves to the checkout -- so the use lib does win today and this holds that down rather than fixing a live fault. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/getpostscript_client_identity.t | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xCAT-test/unit/getpostscript_client_identity.t b/xCAT-test/unit/getpostscript_client_identity.t index 04c6c6a4ac..5cd005ef8f 100644 --- a/xCAT-test/unit/getpostscript_client_identity.t +++ b/xCAT-test/unit/getpostscript_client_identity.t @@ -23,6 +23,17 @@ use lib File::Spec->catdir($FindBin::Bin, '..', '..', 'perl-xCAT'), File::Spec->catdir($FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'perl'); use xCAT::DiscoveryUtils; +# Which tree is under test. Ninety xCAT modules carry +# BEGIN { $::XCATROOT = $ENV{XCATROOT} || '/opt/xcat' } use lib "$::XCATROOT/lib/perl"; +# so the first xCAT module a test loads can put an INSTALLED product in front of the checkout in +# @INC, and a build host has one: /opt/xcat/lib/perl/xCAT/DiscoveryUtils.pm exists on xcat-master. +# A test that loaded that copy would pass while measuring a product built weeks ago, so say which +# file answered rather than assuming the use lib above won. +my $under_test = $INC{'xCAT/DiscoveryUtils.pm'} // ''; +ok(length $under_test, 'xCAT::DiscoveryUtils was loaded at all'); +unlike($under_test, qr{^/opt/xcat/}, "the module under test is this checkout's, not an installed one ($under_test)"); +can_ok('xCAT::DiscoveryUtils', 'request_client_names'); + sub names_for { return xCAT::DiscoveryUtils::request_client_names($_[0]) } # The resolved peer stays first, so a management node whose reverse lookup works behaves exactly From 91e667211022b3bc7eaa27169d5820bda9053b8c Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:36:08 -0300 Subject: [PATCH 22/45] fix(xcat-test): the diskless cases fail when the kernel mounts binfmt_misc The diskless cases snapshot the mount table before genimage and after it and require the two to be identical, ignoring only fusectl. The comparison is there to catch a bind mount genimage leaves inside the root image, which is worth catching. It also fails for mounts the kernel makes on its own. binfmt_misc is an autofs stub that becomes a real mount the first time a process reads /proc/sys/fs/binfmt_misc, and tracefs appears under /sys/kernel/debug the first time anything opens debugfs tracing. On openeuler22.03sp4 both appeared during genimage and failed reg_linux_diskless_installation_flat four minutes into a 1168 second case, while the provisioning that followed succeeded and the node reached booted. The single fusectl exclusion shows the same class was met once before and patched by name. mount_snapshot.sh drops the mounts whose mount POINT is under /proc or /sys, which is where the kernel keeps its on-demand mounts, and the three cases take their snapshots through it. Dropping them by filesystem TYPE would hide the leak the comparison exists for, because a leaked genimage bind is itself a proc or sysfs mount. fusectl needs no exclusion of its own any more. mount_snapshot.bats covers both directions. Taking the filter out fails the two ignore-the-kernel assertions and keeps both leak assertions; filtering by type instead of by mount point fails only the leaked-bind assertion. A test-only commit would skip rather than fail, because require_repo_file skips when the script is absent, so the proof is those two mutations. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../testcase/commoncmd/mount_snapshot.sh | 30 ++++++++ .../installation/SN_diskless_setup_case | 6 +- .../reg_linux_diskless_installation_flat | 12 +-- ...kless_installation_flat_postscripts_failed | 6 +- xCAT-test/bats/mount_snapshot.bats | 74 +++++++++++++++++++ 5 files changed, 116 insertions(+), 12 deletions(-) create mode 100755 xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh create mode 100644 xCAT-test/bats/mount_snapshot.bats diff --git a/xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh b/xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh new file mode 100755 index 0000000000..75460dc94c --- /dev/null +++ b/xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# +# mount_snapshot.sh [] +# +# Print the mount table without the kernel's own on-demand mounts, so the diskless cases can +# compare a snapshot taken before genimage with one taken after it. +# +# genimage bind mounts /proc, /sys and /dev inside the root image. A bind it fails to remove +# leaves the next image built on top of the host, so comparing the two snapshots is worth doing. +# +# What the comparison must not assert is that nothing else mounted anything meanwhile. +# binfmt_misc is an autofs stub that becomes a real mount the first time a process reads +# /proc/sys/fs/binfmt_misc, and tracefs appears under /sys/kernel/debug the first time anything +# opens debugfs tracing. Both are the kernel's doing and both can happen during genimage. On one +# openEuler 22.03 run both did, and the case failed four minutes in while the provisioning that +# followed succeeded. +# +# Filtering by filesystem type would hide the leak this guards, because a leaked genimage bind IS +# a proc or sysfs mount. The mount POINT separates them: the kernel keeps its on-demand mounts +# inside /proc and /sys, and a leaked bind sits under the root image directory. +# +# With a file argument, filter that file instead of asking the kernel, so the filter is testable. + +set -e + +if [ $# -ge 1 ]; then + cat -- "$1" +else + mount +fi | awk '$3 !~ /^\/(proc|sys)(\/|$)/' | sort diff --git a/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case b/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case index 9efe3f987d..d0e7b6d344 100644 --- a/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case +++ b/xCAT-test/autotest/testcase/installation/SN_diskless_setup_case @@ -74,13 +74,13 @@ check:rc==0 cmd:osimage="__GETNODEATTR($$SN,os)__-__GETNODEATTR($$SN,arch)__-netboot-service";otherpkglist=$(lsdef -t osimage $osimage -i otherpkglist -c|awk -F"=" '{print $2}'); cat $otherpkglist cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:genimage __GETNODEATTR($$SN,os)__-__GETNODEATTR($$SN,arch)__-netboot-service check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new -cmd:diff -y /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new +cmd:diff -y /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput diff --git a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat index b736721928..a38545435b 100644 --- a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat +++ b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat @@ -31,16 +31,16 @@ cmd:if [[ -f /test.synclist ]] ;then mv -f /test.synclist /test.synclist.bak;fi; cmd:echo "/test.synclist -> /test.synclist" > /test.synclist;chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute synclists=/test.synclist check:rc==0 cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:cat /tmp/mountoutput/file.org cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu18.04.2" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ ppc64(el|le) ]] && [[ "__GETNODEATTR($$CN,mgt)__" =~ "kvm" ]] ; then mkdir -p /install/custom/netboot/ubuntu; sed -e 's@linux-image-generic-hwe-18.04@linux-image-generic@g' /install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute pkglist=/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; fi cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new cmd:cat /tmp/mountoutput/file.new -cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput cmd:packimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute @@ -148,16 +148,16 @@ cmd:if [[ -f /test.synclist ]] ;then mv -f /test.synclist /test.synclist.bak;fi; cmd:echo "/test.synclist -> /test.synclist" > /test.synclist;chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute synclists=/test.synclist check:rc==0 cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:cat /tmp/mountoutput/file.org cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu18.04.2" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ ppc64(el|le) ]] && [[ "__GETNODEATTR($$CN,mgt)__" =~ "kvm" ]] ; then mkdir -p /install/custom/netboot/ubuntu; sed -e 's@linux-image-generic-hwe-18.04@linux-image-generic@g' /install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute pkglist=/install/custom/netboot/ubuntu/compute.ubuntu18.04.2.ppc64el.pkglist; fi cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new cmd:cat /tmp/mountoutput/file.new -cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput diff --git a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed index 41391a68f0..57064246ed 100644 --- a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed +++ b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_flat_postscripts_failed @@ -35,15 +35,15 @@ cmd:rootimgdir=`lsdef -t osimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arc check:rc==0 cmd:if [ ! -d /tmp/mountoutput ]; then mkdir -p /tmp/mountoutput; fi -cmd:mount |sort > /tmp/mountoutput/file.org +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.org cmd:cat /tmp/mountoutput/file.org cmd:if [[ "__GETNODEATTR($$CN,os)__" =~ "ubuntu16.04.5" ]] && [[ "__GETNODEATTR($$CN,arch)__" =~ "x86" ]]; then chdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute -p pkgdir="http://archive.ubuntu.com/ubuntu xenial universe main,http://archive.ubuntu.com/ubuntu xenial-updates universe main,http://security.ubuntu.com/ubuntu xenial-security main restricted";fi cmd:lsdef -t osimage -o __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute cmd:genimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute check:rc==0 -cmd:mount |sort > /tmp/mountoutput/file.new +cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/mount_snapshot.sh > /tmp/mountoutput/file.new cmd:cat /tmp/mountoutput/file.new -cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new --ignore-matching-lines="fusectl" +cmd:diff /tmp/mountoutput/file.org /tmp/mountoutput/file.new check:rc==0 cmd:rm -rf /tmp/mountoutput cmd:packimage __GETNODEATTR($$CN,os)__-__GETNODEATTR($$CN,arch)__-netboot-compute diff --git a/xCAT-test/bats/mount_snapshot.bats b/xCAT-test/bats/mount_snapshot.bats new file mode 100644 index 0000000000..b2b1fffc4d --- /dev/null +++ b/xCAT-test/bats/mount_snapshot.bats @@ -0,0 +1,74 @@ +#!/usr/bin/env bats +# +# Drive mount_snapshot.sh, which the diskless cases use to compare the mount table before and +# after genimage. The comparison exists to catch a bind mount genimage leaves inside the root +# image, and it must keep catching one. +# +# The snapshots below are real lines from an openEuler 22.03 management node. On that run +# binfmt_misc and tracefs appeared between the two snapshots and failed the case, so the first +# test holds down that they are ignored. The second test is the one that matters: a leaked +# genimage bind must still be reported, which is why filtering by filesystem type is wrong. + +load 'helpers/shell_source' + +ROOTIMG=/install/netboot/openeuler22.03sp4/x86_64/compute/rootimg + +setup() +{ + SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/mount_snapshot.sh')" + BEFORE="${BATS_TEST_TMPDIR}/file.org" + AFTER="${BATS_TEST_TMPDIR}/file.new" + + cat >"$BEFORE" <>"$AFTER" <>"$AFTER" + + run diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER") + [ "$status" -ne 0 ] + [[ "$output" == *"$ROOTIMG/proc"* ]] +} + +# An ordinary mount outside /proc and /sys is the other half of the same requirement. +@test "an NFS mount left behind is still reported" { + cp "$BEFORE" "$AFTER" + printf '192.0.2.1:/install on /mnt/install type nfs4 (rw,relatime)\n' >>"$AFTER" + + run diff <("$SCRIPT" "$BEFORE") <("$SCRIPT" "$AFTER") + [ "$status" -ne 0 ] + [[ "$output" == *"/mnt/install"* ]] +} + +@test "the snapshot keeps the real mounts and drops only the kernel's own" { + run "$SCRIPT" "$BEFORE" + [ "$status" -eq 0 ] + [[ "$output" == *" on / type xfs"* ]] + [[ "$output" == *" on /run type tmpfs"* ]] + [[ "$output" == *" on /dev type devtmpfs"* ]] + refute_grep -q ' on /proc ' <<<"$output" + refute_grep -q ' on /sys ' <<<"$output" + refute_grep -q '/sys/kernel/tracing' <<<"$output" +} From 0e957e654caaaeb38585fdaa50a48f560e969c23 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 21:00:06 -0300 Subject: [PATCH 23/45] test(xcat-test): one lost ICMP sample makes retry_install reinstall a working node retry_install.sh declares a provision successful only when tobooted, pingable and canruncmd are all 0. pingable came from a single `ping -c 2`, and ICMP to a node is lossy for a few seconds after it finishes booting. Measured on an openSUSE Leap 15.6 cluster: one sample reported "2 packets transmitted, 0 received" while `xdsh date` returned the node's own clock a second later, so the node was up and answering SSH. The conjunction failed on ICMP alone, the case ran a second full rinstall, and that cost 401 of the 404 seconds between two runs of the same cell. The second run lost 2 of 3 packets at a moment that was not the decision point and passed first try. The difference between the two runs was which side of a two-packet sample landed, not the state of either node. The probe is tested in bats, because it is shell. It is driven with a stubbed ping, so what is measured is how many times the probe asks and what it answers, not whether the build host can reach anything. All five assertions fail on this commit, because node_pingable does not exist yet and sourcing the script still runs lsdef. The graded evidence is the mutation recorded in the fix commit. `run` is used rather than a bare call: bats fails a test on any non-zero command in its body and `set +e` does not suppress that, so asserting on a non-zero return without `run` aborts the test instead of measuring it. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../bats/retry_install_transient_icmp.bats | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 xCAT-test/bats/retry_install_transient_icmp.bats diff --git a/xCAT-test/bats/retry_install_transient_icmp.bats b/xCAT-test/bats/retry_install_transient_icmp.bats new file mode 100644 index 0000000000..bbfa3851df --- /dev/null +++ b/xCAT-test/bats/retry_install_transient_icmp.bats @@ -0,0 +1,102 @@ +#!/usr/bin/env bats +# +# retry_install.sh decides a provision succeeded only if all three of tobooted, pingable and +# canruncmd are 0. pingable came from a single `ping -c 2`, and ICMP to a node is lossy for a few +# seconds after it finishes booting. +# +# Measured on an openSUSE Leap 15.6 cluster: one sample reported "2 packets transmitted, 0 +# received" while `xdsh date` returned the node's own clock a second later, so the node was +# up and answering SSH. The conjunction failed on ICMP alone and the case did a second full +# rinstall, which cost 401 of the 404 seconds between two runs of the same cell. The second run +# lost 2 of 3 packets at a moment that was not the decision point and passed first try. The +# difference between the runs was which side of a two-packet sample landed. +# +# node_pingable asks again before concluding. These tests drive it with a stubbed ping, because +# what matters is how many times it asks and what it answers -- not whether this host can reach +# anything. +# +# The discriminator is "a node that never answers still reports non-pingable". Removing the +# retry must fail the transient case and leave that one passing, or the change cannot be told +# apart from deleting the check -- which would turn a flaky probe into one that cannot fail. + +load 'helpers/shell_source' + +NODE=cn01 + +setup() +{ + SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/retry_install.sh')" + COUNT="${BATS_TEST_TMPDIR}/ping-calls" + : >"$COUNT" + # No sleeping: the retry interval is not what these tests are about. + export PING_RETRY_SLEEP=0 + export PING_TRIES=5 +} + +# Replaces the ping(8) the function calls. Answers non-zero for the first $1 calls, then zero. +# A negative count never answers. +stub_ping() +{ + FAIL_FIRST="$1" + ping() + { + local n + n=$(( $(read_file_or_empty "$COUNT" | wc -l) + 1 )) + echo "call $n" >>"$COUNT" + if [ "$FAIL_FIRST" -lt 0 ] || [ "$n" -le "$FAIL_FIRST" ]; then + return 1 + fi + return 0 + } +} + +ping_calls() +{ + read_file_or_empty "$COUNT" | wc -l | tr -d ' ' +} + +@test "sourcing retry_install.sh defines node_pingable and runs no provisioning" { + # The main-guard. Without it, sourcing runs lsdef and the rinstall loop. + run bash -c "source '$SCRIPT'; type -t node_pingable" + [ "$status" -eq 0 ] + [ "$output" = "function" ] +} + +# `run` is required, not stylistic: bats fails a test on any non-zero command in its body, and +# `set +e` does not suppress that. Asserting on a non-zero return without `run` aborts the test +# instead of measuring it -- which made the veto assertion below fail under a mutation for the +# wrong reason, so it could not discriminate. +@test "a node whose first samples are lost is pingable once it answers" { + # xcat20-mn, exactly: ICMP lost in the window after the boot, then fine. + source "$SCRIPT" + stub_ping 2 + run node_pingable "$NODE" + [ "$status" -eq 0 ] + [ "$(ping_calls)" -eq 3 ] +} + +@test "a node that never answers is still not pingable, so a real defect keeps vetoing" { + # THE DISCRIMINATOR, and it asserts ONE thing on purpose. Bundling the ask count in here made + # it fail under the mutation as a retry property, which is the opposite of discriminating: + # this assertion exists to show the change is not "delete the check", so it has to pass + # whether or not the retry is present. + source "$SCRIPT" + stub_ping -1 + run node_pingable "$NODE" + [ "$status" -ne 0 ] +} + +@test "a node that never answers is asked PING_TRIES times before giving up" { + source "$SCRIPT" + stub_ping -1 + run node_pingable "$NODE" + [ "$(ping_calls)" -eq "$PING_TRIES" ] +} + +@test "a node that answers at once costs no extra asks" { + # The happy path must not get slower: one ask, as before. + source "$SCRIPT" + stub_ping 0 + node_pingable "$NODE" + [ "$(ping_calls)" -eq 1 ] +} From 1e8a935ca309ff0cb84dc4c27e98e0fbe695361f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 21:00:06 -0300 Subject: [PATCH 24/45] fix(xcat-test): a transient ICMP loss vetoes a node that answers SSH node_pingable asks ICMP up to PING_TRIES times and stops at the first answer, so a few seconds of loss after a node boots no longer forces a second full rinstall. A node that never answers still reports non-pingable, and the caller still vetoes it: the signal is kept, not removed. The probe is lifted into a function with a main-guard rather than left inline, so a bats test can drive it without running a provisioning loop or needing an xCAT database. Nothing sources this script -- all nine callers execute it -- so the guard changes no caller. The happy path is unchanged at one ask. A node that never answers now costs PING_TRIES asks before the verdict, which is under a minute against the six minutes of the reinstall it decides. retry_install_transient_icmp.bats passes 5 of 5. Removing the bounded retry fails assertions 2 and 4, which are the retry properties, and leaves assertion 3 passing -- a node that never answers is still not pingable. That assertion is the discriminator: without it the change could not be told apart from deleting the check, which would turn a flaky probe into one that cannot fail. xCAT-test/bats is 596 passed, 19 failed. All 19 are xcatroot_rootimg_checksum.bats, which reports 0 passed and 19 failed on upstream master with none of this branch applied. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../testcase/commoncmd/retry_install.sh | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/xCAT-test/autotest/testcase/commoncmd/retry_install.sh b/xCAT-test/autotest/testcase/commoncmd/retry_install.sh index d4589e6734..172bcbad93 100755 --- a/xCAT-test/autotest/testcase/commoncmd/retry_install.sh +++ b/xCAT-test/autotest/testcase/commoncmd/retry_install.sh @@ -1,5 +1,47 @@ #!/bin/bash +# How many times to ask ICMP, and how long to wait between asks. Overridable so a test can drive +# node_pingable without sleeping. +PING_TRIES=${PING_TRIES:-5} +PING_RETRY_SLEEP=${PING_RETRY_SLEEP:-2} + +#--- node_pingable +# Descriptions: whether the node answers ICMP, asked more than once. +# +# ICMP to a node is lossy for a few seconds after it finishes booting. One sample on an +# openSUSE Leap 15.6 cluster lost 2 of 2 packets while xdsh to the same node succeeded a second +# later; the caller ANDs both answers, so that one sample forced a second full rinstall and cost +# 401 seconds. A second run of the same cell lost 2 of 3 packets at a moment that was not the +# decision point and passed. The difference between the two runs was which side of a +# two-packet sample landed, not the state of the node. +# +# So ask again before concluding. A node that never answers still reports non-pingable, because +# that is a real defect and the caller must keep vetoing it. +# Arguments: $1 - the node +# Returns: 0 if the node answered, non-zero if it never did +#--- +node_pingable() { + local node=$1 + local i + for (( i = 1; i <= PING_TRIES; ++i )); do + if ping -c 2 "$node"; then + return 0 + fi + echo "[$i/$PING_TRIES] $node did not answer ICMP; asking again" + if [ "$i" -lt "$PING_TRIES" ]; then + sleep "$PING_RETRY_SLEEP" + fi + done + return 1 +} + +# Sourcing stops here. BASH_SOURCE[0] differs from $0 only when this file is sourced, so a bats +# test can drive node_pingable without running a provisioning loop -- and without the lsdef below, +# which needs an xCAT database. +if [ "${BASH_SOURCE[0]}" != "${0}" ]; then + return 0 +fi + declare -i installsuccess=0 declare -i a=0 declare -i tryreinstall=1 @@ -64,7 +106,7 @@ do tobooted=$? echo "The tobooted is $tobooted" - ping -c 2 $node + node_pingable $node pingable=$? echo "The pingable is $pingable" From 0aefdb479b49ac4fec0350fd9bfc0b4c72e6391a Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:13:33 -0300 Subject: [PATCH 25/45] test(xcat-test): a harness path beside an xCAT directory counts as an xCAT denial selinux_avc_check.sh decides which SELinux denials xCAT answers for by matching the audit record's path against XCAT_AVC_PATH. The match treats each entry as a string prefix, so a sibling directory whose name merely starts with one of them is kept. On build 2 of xcat-test-el10-x86_64-selinux the one denial the run attributed to xCAT was xcatd executing the CI's own notification hook under /var/lib/xcat-cluster-test, and selinux_cn_diskful_enforcing failed on it. The new bats test classifies that record and asserts nothing is kept. Two more assert the directories themselves and a file under one are still kept, so an over-anchored match does not pass silently. Without the fix 1 of 18 fails, and it is the sibling-path test. The other two pass before and after. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/bats/selinux_avc_check.bats | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/xCAT-test/bats/selinux_avc_check.bats b/xCAT-test/bats/selinux_avc_check.bats index 060ec143b0..614a3c7135 100644 --- a/xCAT-test/bats/selinux_avc_check.bats +++ b/xCAT-test/bats/selinux_avc_check.bats @@ -66,6 +66,31 @@ SSH_RECORD='type=AVC msg=audit(1759000002.333:444): avc: denied { siginh } for [[ "$output" == *'comm="genimage"'* ]] } +# The hook cluster-test.pl registers with regnotif, executed by an xcatd worker. The +# harness wrote this file, not xCAT, and /var/lib/xcat-cluster-test is not /var/lib/xcat. +# Captured on build 2 of xcat-test-el10-x86_64-selinux, where it was the one denial the +# run attributed to xCAT and selinux_cn_diskful_enforcing failed on it. +HARNESS_RECORD='type=AVC msg=audit(1792858690.329:3003): avc: denied { execute_no_trans } for pid=51342 comm=78636174643A204442204163636573 path="/var/lib/xcat-cluster-test/event-notify.pl" dev="vda4" ino=75521321 scontext=system_u:system_r:xcat_t:s0 tcontext=unconfined_u:object_r:var_lib_t:s0 tclass=file permissive=1' + +@test "a path that merely starts with the name of an xCAT directory is not kept" { + run classify "$HARNESS_RECORD" + [ -z "$output" ] +} + +@test "an xCAT directory is kept when the path names the directory itself" { + local record='type=AVC msg=audit(1759000005.666:777): avc: denied { search } for pid=6789 comm="httpd" path="/install" dev="vda2" ino=56 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=dir permissive=0' + run classify "$record" + [ "$status" -eq 0 ] + [[ "$output" == *'path="/install"'* ]] +} + +@test "a file under an xCAT directory is kept" { + local record='type=AVC msg=audit(1759000006.777:888): avc: denied { read } for pid=7890 comm="httpd" path="/var/lib/xcat/cert/server-cert.pem" dev="vda2" ino=57 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_lib_t:s0 tclass=file permissive=0' + run classify "$record" + [ "$status" -eq 0 ] + [[ "$output" == *'/var/lib/xcat/cert/server-cert.pem'* ]] +} + @test "a program whose name merely contains a kept word is not matched by accident" { local record='type=AVC msg=audit(1759000004.555:666): avc: denied { execute } for pid=5678 comm="systemd-udevd" scontext=system_u:system_r:udev_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=file permissive=0' run classify "$record" From af66f78dfd05adc488e8e89d4d1dfc66c6267911 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:35:07 -0300 Subject: [PATCH 26/45] fix(xcat-core): Genesis on Ubuntu answers no ssh, so every case that reaches a node fails A compute node booted into legacy Genesis on Ubuntu refuses every ssh connection: [xcat100-mn]: xcat100-cn: ssh: connect to host xcat100-cn port 22: Connection refused and on the node's own console, once per boot: Missing privilege separation directory Debian and Ubuntu build sshd with --with-privsep-path=/run/sshd. The payload's own sshd carries that path and the format string "Missing privilege separation directory: %s", and the image ships /run holding only rpcbind. So sshd exits at startup and the node is unreachable. nodeset_shell, nodeset_cmdline, nodeset_runimg and genesis_boot_proof_legacy all fail on it, while seq_discovery, which needs no ssh, passes. doxcat already does this for the other family: it creates /usr/share/empty.sshd, the EL privsep path, with the comment "On some systems /usr/share/empty.sshd needs to be created before calling sshd". The Debian path was never added, although the tree knows about it twice -- remoteshell says "prepare the /var/run/sshd for ubuntu" and etc/init.d/functions creates it. This adds the same lines for /run/sshd and /var/run/sshd. Created immediately before sshd starts, not baked into the image: /run is a tmpfs on a running system, so a directory under it does not survive the mount. The mode is set whether or not the directory had to be created, because sshd refuses a group or world writable privsep directory with the SAME message as an absent one, so a wrong mode is indistinguishable from this bug. genesis_sshd_privsep.bats asserts what sshd imposes -- the path is a directory, owned by the user that will run sshd, and not group or world writable -- read at the moment sshd runs. The recorder is bound over /usr/sbin/sshd because doxcat calls that absolute path, and because recording from a later command cannot see the ORDER: with the recorder on a PATH command instead, moving the directories after the sshd line still passed. Five mutations, each red: removing the loop fails 2, never setting the mode fails 1, dropping /var/run/sshd fails 2, a group-writable mode fails 2, and creating the directories after sshd starts fails 2. The whole bats suite goes from 21 failures to 19 with this change, the difference being these two tests; the other 19 are unrelated and fail on the base. doxcat_sandbox.bash gains chmod, and a third test keeps the next one from being missed. The sandbox curates PATH without /usr/bin, so a command it does not copy resolves to nothing and fails SILENTLY: doxcat's chmod did nothing under test for as long as this sandbox has existed, and any assertion about a mode could never pass. The guard installs bash's command_not_found_handle through BASH_ENV and fails naming whatever doxcat invoked and could not resolve, so it needs no list to keep current. With chmod removed again it reports exactly "chmod". Its reach is the commands doxcat runs on the path the test drives, which is a floor rather than a completeness check on the helper's list. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-genesis-scripts/usr/bin/doxcat | 12 ++ xCAT-test/bats/genesis_sshd_privsep.bats | 138 +++++++++++++++++++++ xCAT-test/bats/helpers/doxcat_sandbox.bash | 5 +- 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/bats/genesis_sshd_privsep.bats diff --git a/xCAT-genesis-scripts/usr/bin/doxcat b/xCAT-genesis-scripts/usr/bin/doxcat index 2338e3337b..0e451050c2 100755 --- a/xCAT-genesis-scripts/usr/bin/doxcat +++ b/xCAT-genesis-scripts/usr/bin/doxcat @@ -100,6 +100,18 @@ fi if [ ! -e /usr/share/empty.sshd ]; then mkdir -p /usr/share/empty.sshd fi +# Debian and Ubuntu build sshd with --with-privsep-path=/run/sshd, and sshd exits with +# "Missing privilege separation directory" when it is absent. The image carries /run and not +# /run/sshd, so Genesis on Ubuntu answered no ssh and every case that reaches a booted node +# over xdsh failed. Created here rather than baked into the image: /run is a tmpfs on a +# running system, and a directory under it does not survive the mount. +# The mode is set whether or not the directory had to be created: sshd refuses a privsep +# directory that is group or world writable, with the same message, so a wrong mode looks +# exactly like an absent one. +for sshd_privsep in /run/sshd /var/run/sshd; do + mkdir -p "$sshd_privsep" + chmod 0755 "$sshd_privsep" +done echo 'Protocol 2' >> /etc/ssh/sshd_config /usr/sbin/sshd mkdir -p /etc/xcat diff --git a/xCAT-test/bats/genesis_sshd_privsep.bats b/xCAT-test/bats/genesis_sshd_privsep.bats new file mode 100644 index 0000000000..25f2f48f7f --- /dev/null +++ b/xCAT-test/bats/genesis_sshd_privsep.bats @@ -0,0 +1,138 @@ +#!/usr/bin/env bats +# +# The privilege separation directory sshd needs, at the moment doxcat starts sshd. +# +# Debian and Ubuntu build sshd with --with-privsep-path=/run/sshd. The Genesis image carries +# /run and not /run/sshd, so sshd exited with "Missing privilege separation directory" and the +# node answered no ssh at all. Every legacy Genesis case that reaches a booted node over xdsh +# failed on "Connection refused" while sequential discovery, which needs no ssh, passed. +# +# doxcat already did this for the other family -- it creates /usr/share/empty.sshd, the EL +# privsep path -- so this is the same line for Debian. The assertions are what SSHD IMPOSES, +# read at the moment sshd runs: the path is a directory, its owner is the user that will run +# sshd, and it is not group or world writable. sshd refuses a loose mode with the same message +# as an absent directory, so a wrong mode is indistinguishable from the bug. +# +# Read from inside the sandbox on purpose. /run there is a tmpfs, exactly as it is on a running +# system, so a directory made before that mount -- or baked into the image -- is not there when +# sshd starts and cannot be seen from outside afterwards. + +load 'helpers/doxcat_sandbox' + +PRIVSEP_PATHS='/run/sshd /var/run/sshd' + +# Record what each privsep path looks like AT THE MOMENT sshd runs. +# +# doxcat runs sshd as /usr/sbin/sshd, an absolute path, so a stub on PATH is never reached and +# the recorder is bound over that path instead. Recording from a later PATH command instead -- +# openssl is the next one -- cannot see the ORDER: moving the directories after the sshd line +# then passes, which is the one mutation that matters most here. +record_privsep() +{ + local stub="${BATS_TEST_TMPDIR}/sshd-recorder" + + cat >"$stub" <>/run/fixture/sshd-privsep + else + printf '%s absent\n' "\$d" >>/run/fixture/sshd-privsep + fi +done +exit 0 +SH + chmod 0755 "$stub" + sandbox+=(--ro-bind "$stub" /usr/sbin/sshd) +} + +seen() +{ + local path="$1" + awk -v p="$path" '$1 == p { print; exit }' "$fixture/sshd-privsep" +} + +@test "doxcat makes every privilege separation directory before it starts sshd" { + setup_doxcat + record_privsep + add_doxcat_link eth0 BROADCAST,MULTICAST,UP ether 02:bb:cc:dd:ee:ff + run_genesis 0 --setenv BOOTIF 01-02-bb-cc-dd-ee-ff + + # The recording ran, so it happened one statement after sshd was started. + [ -s "$fixture/sshd-privsep" ] + + for path in $PRIVSEP_PATHS; do + local line mode owner + line=$(seen "$path") + [ -n "$line" ] + [ "$(printf '%s\n' "$line" | cut -d' ' -f2)" = dir ] + mode=$(printf '%s\n' "$line" | cut -d' ' -f3) + owner=$(printf '%s\n' "$line" | cut -d' ' -f4) + # Owned by whoever runs sshd: root in Genesis, the invoking user here. ls in + # the sandbox has no passwd lookup, so the owner comes back numeric. + [ "$owner" = "$(id -u)" ] + # sshd refuses a group or world writable privsep directory. Positions 6 and 9 of the + # mode string are the group and other write bits. + [ "$(printf '%s\n' "$mode" | cut -c6)" = - ] + [ "$(printf '%s\n' "$mode" | cut -c9)" = - ] + done +} + +@test "a privilege separation directory left group writable is corrected, not kept" { + # The directory can already exist from an earlier boot with a mode sshd will not accept, + # and that failure prints the same message as an absent one. So the mode is set whether or + # not doxcat had to create the directory. + setup_doxcat + record_privsep + add_doxcat_link eth0 BROADCAST,MULTICAST,UP ether 02:bb:cc:dd:ee:ff + # /var is bound from the fixture, so this one survives into the sandbox. + mkdir -p "$fixture/var/run/sshd" + chmod 0777 "$fixture/var/run/sshd" + run_genesis 0 --setenv BOOTIF 01-02-bb-cc-dd-ee-ff + + local mode + mode=$(printf '%s\n' "$(seen /var/run/sshd)" | cut -d' ' -f3) + [ -n "$mode" ] + [ "$(printf '%s\n' "$mode" | cut -c6)" = - ] + [ "$(printf '%s\n' "$mode" | cut -c9)" = - ] +} + +@test "every command doxcat runs resolves inside the sandbox" { + # The sandbox curates PATH and does NOT include /usr/bin, so a command it does not copy + # resolves to nothing. That fails silently: doxcat's chmod did nothing under test for as + # long as this sandbox has existed, and an assertion about a mode could never pass. The + # mode half of the privsep fix was unmeasurable until chmod was added to the helper. + # + # Derived, not a list: bash calls command_not_found_handle for anything it cannot resolve, + # so this records whatever doxcat actually invokes and goes missing. A list here would go + # stale the next time doxcat gains a command. + # + # Its reach is the commands doxcat runs ON THE PATH THIS TEST DRIVES, which is not every + # command in the script -- a branch this boot does not take is not covered. It is a floor, + # not a completeness check on the helper's list. + setup_doxcat + record_privsep + local env_file="${BATS_TEST_TMPDIR}/bash_env" + cat >"$env_file" <<'SH' +command_not_found_handle() +{ + printf '%s\n' "$1" >>/run/fixture/not-found + return 127 +} +SH + sandbox+=(--ro-bind "$env_file" /run/bash_env --setenv BASH_ENV /run/bash_env) + add_doxcat_link eth0 BROADCAST,MULTICAST,UP ether 02:bb:cc:dd:ee:ff + run_genesis 0 --setenv BOOTIF 01-02-bb-cc-dd-ee-ff + + # The handler was installed, so an absence would have been recorded. + [ -s "$fixture/sshd-privsep" ] + if [ -e "$fixture/not-found" ]; then + printf 'doxcat runs commands the sandbox does not provide:\n%s\n' \ + "$(sort -u "$fixture/not-found")" >&2 + return 1 + fi +} diff --git a/xCAT-test/bats/helpers/doxcat_sandbox.bash b/xCAT-test/bats/helpers/doxcat_sandbox.bash index cbab15c095..559de3aa81 100644 --- a/xCAT-test/bats/helpers/doxcat_sandbox.bash +++ b/xCAT-test/bats/helpers/doxcat_sandbox.bash @@ -10,8 +10,11 @@ setup_doxcat() fips=$(repo_path xCAT-genesis-scripts/usr/lib/xcat/fips.sh) [ -r "$fips" ] mkdir -p "$fixture"/{etc/ssh,etc/pki/tls,real,links,addrs} + # chmod is in this list because doxcat runs it: the sandbox has no /usr/bin on PATH, so a + # command that is missing here is a command that silently does nothing under test. doxcat's + # chmod of the sshd privilege separation directory was not exercised until it was added. for utility in bash sh cat cp awk grep sed sort tr tail rm wc cut head uname \ - timeout env ls mkdir touch readlink basename sleep; do + timeout env ls mkdir touch readlink basename sleep chmod; do cp -L "$(PATH=/usr/bin:/bin type -P "$utility")" "$fixture/bin/$utility" done if [ -x /usr/bin/coreutils ]; then From 65f4de2c6b34d452df05d7a26687e772cbf81a32 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:13:46 -0300 Subject: [PATCH 27/45] fix(xcat-test): a path that only starts with an xCAT directory name is counted as xCAT selinux_avc_classify matched the entries of XCAT_AVC_PATH as string prefixes, with [^"]* before the alternation and no boundary after it. A directory name is not a string prefix: /var/lib/xcat-cluster-test is not /var/lib/xcat, and /installer is not /install. The CI writes its regnotif notification hook to /var/lib/xcat-cluster-test/event-notify.pl. xcatd executes it, the file carries var_lib_t, and xcat_t has no execute_no_trans on it, so the audit log holds the record. The classifier kept it on the strength of the prefix, the count read XCAT_AVC=1, and selinux_cn_diskful_enforcing failed on a file the product does not ship. The policy was confining xcat_t correctly. The path half of the pattern now starts at the opening quote and ends at a / or at the closing quote, so a listed directory matches itself and the files under it, and nothing else. The subject half is unchanged: a denial by an xCAT program is still kept whatever the path. selinux_avc_check.bats covers it. Reverting the boundary group fails the sibling-path test alone; requiring a trailing / fails the bare-directory test alone. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/autotest/testcase/commoncmd/selinux_avc_check.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xCAT-test/autotest/testcase/commoncmd/selinux_avc_check.sh b/xCAT-test/autotest/testcase/commoncmd/selinux_avc_check.sh index ffe4357bd1..9968a0c254 100755 --- a/xCAT-test/autotest/testcase/commoncmd/selinux_avc_check.sh +++ b/xCAT-test/autotest/testcase/commoncmd/selinux_avc_check.sh @@ -40,9 +40,13 @@ XCAT_AVC_COMM='xcatd|genimage|packimage|nodeset|mknb|makedhcp|makedns|makehosts|makeknownhosts|copycds|liteimg|xdsh|xdcp|xcatprobe|xcatconfig' XCAT_AVC_PATH='/opt/xcat|/xcatpost|/tftpboot|/install|/var/log/xcat|/etc/xcat|/var/lib/xcat' +# The path must be one of those directories, or a file under one. A directory name is +# not a string prefix: /var/lib/xcat-cluster-test holds the CI's own notification hook, +# and matching it as /var/lib/xcat put an xcatd denial on a harness file into the count. +# So the name starts at the quote and ends at a / or at the closing quote. selinux_avc_classify() { - grep -E "(comm|exe)=\"[^\"]*(${XCAT_AVC_COMM})[^\"]*\"|(path|name)=\"[^\"]*(${XCAT_AVC_PATH})" + grep -E "(comm|exe)=\"[^\"]*(${XCAT_AVC_COMM})[^\"]*\"|(path|name)=\"(${XCAT_AVC_PATH})(/|\")" } # Report the denials ausearch answered with. An error message is not a clean window: From cd0a7fd8a98943412dcb9acf9dfaa06bf06e4d60 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:50:59 -0300 Subject: [PATCH 28/45] test(xcat-core): the Genesis payload carries no openssl config, so no certificate is requested A node boots Genesis, prints "Getting initial certificate --> MN:3001" and goes no further. xcatd records no credential request, the node status stays at powering-on, and every case that waits for the node fails. genesis_openssl_config.bats drives each dracut module's install() with the dracut helpers replaced by a recorder, so it reads what the module asks the payload to carry. genesis_getcert_missing_openssl.bats gains one case: the give up message must repeat what openssl printed, because a message naming only certkey.pem sends the reader to a key that is intact. Three of the six cases fail on this commit: both module cases, and the message case. stub_dir defaulted count to the empty string, which left "{ ; exit 1; }" in the openssl stub. That is a syntax error, so the stub failed for the wrong reason and reported bash's message instead of openssl's. The default is now a no-op command. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../bats/genesis_getcert_missing_openssl.bats | 16 +++++- xCAT-test/bats/genesis_openssl_config.bats | 57 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 xCAT-test/bats/genesis_openssl_config.bats diff --git a/xCAT-test/bats/genesis_getcert_missing_openssl.bats b/xCAT-test/bats/genesis_getcert_missing_openssl.bats index f88914eda6..a683dbd60c 100644 --- a/xCAT-test/bats/genesis_getcert_missing_openssl.bats +++ b/xCAT-test/bats/genesis_getcert_missing_openssl.bats @@ -24,7 +24,9 @@ write_stub() # A PATH directory holding the commands getcert runs. openssl is absent unless it is asked for. stub_dir() { - local with_openssl="${1:-0}" count="" + # count defaults to a no-op: an empty value leaves "{ ; exit 1; }", which is a syntax + # error, so the stub would fail for the wrong reason and report bash's message. + local with_openssl="${1:-0}" count=":" local dir="${BATS_TEST_TMPDIR}/bin" rm -rf "$dir" @@ -35,7 +37,7 @@ stub_dir() write_stub "$dir" sleep 'exec /bin/sleep "$@"' if [ "$with_openssl" = 1 ]; then [ -n "${COUNT_REQUESTS:-}" ] && count="echo req >> '$COUNTER'" - write_stub "$dir" openssl "[ \"\$1\" = req ] && { $count ; exit 1; } + write_stub "$dir" openssl "[ \"\$1\" = req ] && { $count ; echo \"\${OPENSSL_REQ_ERROR:-}\" >&2 ; exit 1; } exit 0" fi printf '%s\n' "$dir" @@ -70,3 +72,13 @@ run_getcert() [ -f "$COUNTER" ] && tries="$(grep -c req "$COUNTER")" [ "$tries" -gt 1 ] } + +@test "the give up message repeats what openssl printed" { + # OPENSSLDIR/openssl.cnf is absent more often than the key is broken, and the key is + # usually intact. A message that names only certkey.pem sends the reader to the wrong file. + export OPENSSL_REQ_ERROR="Can't open \"/usr/lib/ssl/openssl.cnf\" for reading, No such file or directory" + run run_getcert "$(stub_dir 1)" 30 5 + [ "$status" -ne 124 ] + [ "$status" -ne 0 ] + [[ "$output" == *openssl.cnf* ]] +} diff --git a/xCAT-test/bats/genesis_openssl_config.bats b/xCAT-test/bats/genesis_openssl_config.bats new file mode 100644 index 0000000000..5eb4f4328f --- /dev/null +++ b/xCAT-test/bats/genesis_openssl_config.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats +# +# The Genesis payload must carry the openssl config file. openssl req reads +# OPENSSLDIR/openssl.cnf and exits 1 when it is absent, so getcert makes no certificate +# request and the node never reports a destiny. + +load 'helpers/shell_source' + +setup() +{ + HOST_CNF="$(openssl version -d 2>/dev/null | sed -e 's/^OPENSSLDIR: *"*//' -e 's/"*$//')/openssl.cnf" + [ -e "$HOST_CNF" ] || skip "this host has no $HOST_CNF to install" + export HOST_CNF +} + +# Run the module's install() with every dracut helper replaced by a recorder, so the test reads +# what the module asks the payload to carry rather than matching the module's source. +record_install() +{ + local module="$1" log="$2" + : >"$log" + ( + for helper in dracut_install inst inst_simple inst_multiple inst_binary inst_script \ + inst_symlink inst_dir inst_hook inst_rules instmods; do + eval "$helper() { printf '%s\n' \"\$@\" >>'$log'; return 0; }" + done + # Anything the module calls that this host lacks must not stop install(). + command_not_found_handle() { return 0; } + dfatal() { printf 'dfatal %s\n' "$*" >>"$log"; } + moddir="${BATS_TEST_TMPDIR}"; hostonly=''; dracutsysrootdir=''; srcmods='' + . "$module" >/dev/null 2>&1 || true + install >/dev/null 2>&1 || true + ) +} + +@test "the ubuntu module installs the openssl config its own openssl names" { + module="$(repo_path 'xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh')" + [ -r "$module" ] || skip "$module is required" + record_install "$module" "${BATS_TEST_TMPDIR}/ubuntu.log" + [ -s "${BATS_TEST_TMPDIR}/ubuntu.log" ] + grep -q "$HOST_CNF" "${BATS_TEST_TMPDIR}/ubuntu.log" +} + +@test "the el module installs the openssl config its own openssl names" { + module="$(repo_path 'xCAT-genesis-base/dracut_105/el/module-setup.sh')" + [ -r "$module" ] || skip "$module is required" + record_install "$module" "${BATS_TEST_TMPDIR}/el.log" + [ -s "${BATS_TEST_TMPDIR}/el.log" ] + grep -q "$HOST_CNF" "${BATS_TEST_TMPDIR}/el.log" +} + +@test "openssl itself is still installed, so the config is an addition" { + module="$(repo_path 'xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh')" + [ -r "$module" ] || skip "$module is required" + record_install "$module" "${BATS_TEST_TMPDIR}/u2.log" + grep -qx 'openssl' "${BATS_TEST_TMPDIR}/u2.log" +} From 6980a71de565b49724b8e619101bbbaddbba1dac Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:51:23 -0300 Subject: [PATCH 29/45] fix(xcat-core): Genesis node stops at "Getting initial certificate" openssl req reads the config file at OPENSSLDIR/openssl.cnf and exits 1 when it is absent. install() in xCAT-genesis-base/dracut_105/{ubuntu,el}/module-setup.sh runs dracut_install openssl, which copies the program and its shared libraries and nothing else. OPENSSLDIR is /usr/lib/ssl on Ubuntu and /etc/pki/tls on EL, so the one file doxcat writes serves EL alone, and getcert loops on openssl req until it gives up. Measured on an Ubuntu compute node: /usr/lib/ssl did not exist, the image carried /etc/pki/tls/openssl.cnf, and the key verified "RSA key ok". Supplying a config turned the same command into a 1602 byte certificate request. Each module now installs the config file that its own openssl names, and the image build stops when that file is absent. getcert reports what openssl printed beside the key it used, and reads the file with bash builtins so it needs no external command. Two mutations, each failing only the cases that name it: dropping the install call fails both module cases and keeps the other four; restoring the old message fails the message case alone. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-genesis-base/dracut_105/el/module-setup.sh | 15 +++++++++++++++ .../dracut_105/ubuntu/module-setup.sh | 15 +++++++++++++++ xCAT-genesis-scripts/usr/bin/getcert | 10 ++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/xCAT-genesis-base/dracut_105/el/module-setup.sh b/xCAT-genesis-base/dracut_105/el/module-setup.sh index 131dadb344..5c113a41f6 100755 --- a/xCAT-genesis-base/dracut_105/el/module-setup.sh +++ b/xCAT-genesis-base/dracut_105/el/module-setup.sh @@ -40,10 +40,25 @@ _dracut_install_opt() { fi } +# openssl req reads the config file at OPENSSLDIR/openssl.cnf and exits 1 without it, so the +# node makes no certificate request. dracut_install copies the program and its libraries only. +# OPENSSLDIR is /usr/lib/ssl on Ubuntu and /etc/pki/tls on EL, so ask openssl where it looks. +_dracut_install_openssl_config() { + local dir cnf + dir=$(openssl version -d 2>/dev/null | sed -e 's/^OPENSSLDIR: *"*//' -e 's/"*$//') + cnf="${dir:-/etc/ssl}/openssl.cnf" + if [ ! -e "$cnf" ]; then + dfatal "xcat: no openssl config at $cnf; Genesis cannot request a certificate" + exit 1 + fi + dracut_install "$cnf" +} + install() { local genesis_openeuler=0 timezone timezone_files locale_file locale_files [[ -f /etc/openEuler-release ]] && genesis_openeuler=1 dracut_install wget openssl tar mstflint ipmitool cpio gzip lsmod ethtool modprobe touch echo cut wc bash + _dracut_install_openssl_config dracut_install netstat # broadcom update requires dracut_install uniq # mellanox update requires dracut_install grep ip hostname /usr/bin/awk egrep grep dirname expr diff --git a/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh b/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh index 367439ce4f..325807bcd3 100755 --- a/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh +++ b/xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh @@ -40,12 +40,27 @@ _dracut_install_opt() { fi } +# openssl req reads the config file at OPENSSLDIR/openssl.cnf and exits 1 without it, so the +# node makes no certificate request. dracut_install copies the program and its libraries only. +# OPENSSLDIR is /usr/lib/ssl on Ubuntu and /etc/pki/tls on EL, so ask openssl where it looks. +_dracut_install_openssl_config() { + local dir cnf + dir=$(openssl version -d 2>/dev/null | sed -e 's/^OPENSSLDIR: *"*//' -e 's/"*$//') + cnf="${dir:-/etc/ssl}/openssl.cnf" + if [ ! -e "$cnf" ]; then + dfatal "xcat: no openssl config at $cnf; Genesis cannot request a certificate" + exit 1 + fi + dracut_install "$cnf" +} + install() { # Ubuntu multiarch triplet for architecture-specific library paths local TRIPLET TRIPLET=$(dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null || echo x86_64-linux-gnu) dracut_install wget openssl tar ipmitool cpio gzip lsmod ethtool modprobe touch echo cut wc bash + _dracut_install_openssl_config _dracut_install_opt mstflint dracut_install netstat # broadcom update requires dracut_install uniq # mellanox update requires diff --git a/xCAT-genesis-scripts/usr/bin/getcert b/xCAT-genesis-scripts/usr/bin/getcert index 7bad27285e..fd71c7694c 100755 --- a/xCAT-genesis-scripts/usr/bin/getcert +++ b/xCAT-genesis-scripts/usr/bin/getcert @@ -21,9 +21,15 @@ fi # requests fail. An emulated node needs minutes for that key. CSR_TIMEOUT=${GETCERT_CSR_TIMEOUT:-600} CSR_DEADLINE=$((SECONDS + CSR_TIMEOUT)) -while ! openssl req -new -key /etc/xcat/certkey.pem -out /tmp/tls.csr -subj "/CN=$(hostname)" >& /dev/null; do +CSR_ERROR=/tmp/getcert.csr.err +while ! openssl req -new -key /etc/xcat/certkey.pem -out /tmp/tls.csr -subj "/CN=$(hostname)" > /dev/null 2> $CSR_ERROR; do if [ "$SECONDS" -ge "$CSR_DEADLINE" ]; then - give_up "no certificate request after ${CSR_TIMEOUT}s; /etc/xcat/certkey.pem is not usable" + # Name the key that was used AND what openssl printed: the key is usually intact and + # the absent file is OPENSSLDIR/openssl.cnf. + # Read and flatten with bash builtins. The Genesis payload is a minimal initramfs + # and need not carry tr or cat. + csr_error=$(< $CSR_ERROR) + give_up "no certificate request after ${CSR_TIMEOUT}s using /etc/xcat/certkey.pem: ${csr_error//$'\n'/ }" fi sleep 1 done From d6392081dbc4c54206ddf6e4aee904bc4015ec4f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:02:47 -0300 Subject: [PATCH 30/45] docs(xcat-core): the getpostscript comment retells an incident The comment carried a date, a node, and the request counts from one run. The code standard keeps bug history out of source comments: the fact a reader needs is that the peer host is a reverse lookup and can be empty, which the remaining two sentences state. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-server/lib/xcat/plugins/getpostscript.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/getpostscript.pm b/xCAT-server/lib/xcat/plugins/getpostscript.pm index 130ee1ba61..229040c045 100644 --- a/xCAT-server/lib/xcat/plugins/getpostscript.pm +++ b/xCAT-server/lib/xcat/plugins/getpostscript.pm @@ -64,9 +64,7 @@ sub process_request @candidates = ($request->{username}->[0]); } else { # The peer host and fqdn are a reverse lookup of the client socket, so both are empty when - # that lookup fails, however good the client credentials are. Asking only for the peer host - # cost every postscript of an openEuler 22.03sp4 node on 2026-10-24: the certificate named - # the node, the reverse lookup did not, and 100 requests were dropped while 0 were served. + # that lookup fails, however good the client credentials are. # request_client_names adds the certificate name, and excludes the request's own node # attribute, which the client sends and has not proved. @candidates = xCAT::DiscoveryUtils::request_client_names($request); From 35f333a05a15c76e8ad9c24e916ca61000d409af Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:43:24 -0300 Subject: [PATCH 31/45] test(xcat-core): xCAT cannot be installed on either openSUSE node Both openSUSE test cells fail the install step: leap15.6: nothing provides 'perl-DB_File' needed by xCAT-server sles12: nothing provides (/usr/sbin/dhcpd if openEuler-release else ((kea and kea-hooks) if (system-release >= 10) else /usr/sbin/dhcpd)) needed by xCAT Both requirements are written for EL and have no answer on openSUSE. No package named perl-DB_File exists on Leap 15.6 or 42.3. The dhcpd expression is a rich dependency, and the sles12 management node is openSUSE 42.3 with rpm 4.11, which has none. The test states what the openSUSE branch of each spec must ask for, and that no rich dependency reaches an openSUSE build. It also holds down that EL and openEuler keep the expressions they have. Four of its nine assertions fail because no spec has an openSUSE branch for these requirements yet. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/opensuse_mn_requires.t | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 xCAT-test/unit/opensuse_mn_requires.t diff --git a/xCAT-test/unit/opensuse_mn_requires.t b/xCAT-test/unit/opensuse_mn_requires.t new file mode 100755 index 0000000000..43446b8efa --- /dev/null +++ b/xCAT-test/unit/opensuse_mn_requires.t @@ -0,0 +1,110 @@ +#!/usr/bin/env perl +# xCAT cannot be installed on either openSUSE management node: +# +# leap15.6: nothing provides 'perl-DB_File' needed by xCAT-server +# sles12: nothing provides (/usr/sbin/dhcpd if openEuler-release else +# ((kea and kea-hooks) if (system-release >= 10) else /usr/sbin/dhcpd)) +# needed by xCAT +# +# Both requirements are written for EL and have no answer on openSUSE. +# +# perl-DB_File: no package of that name exists on Leap 15.6 or 42.3. Leap 15.6 calls it +# perl-core-DB_File and 42.3 has no such package either, but BOTH provide the capability +# perl(DB_File), so the capability is the portable name. +# +# The dhcpd expression: the sles12 cell is an openSUSE 42.3 management node whose rpm is 4.11, +# which has no rich dependencies -- it reports the whole expression as a capability nothing +# provides. Neither Leap release carries kea, and both carry chrony, ntp and ISC dhcpd, so the +# plain names are what these expressions resolve to on openSUSE anyway. +# +# A spec is a packaging manifest: the text IS the contract, there is nothing to execute, and +# these assertions are on package names in it. The build that proves the requirements resolve is +# the openSUSE core build plus the install step on each management node. +use strict; +use warnings; + +use FindBin qw($RealBin); +use Test::More; +use File::Slurper qw(read_text); + +my $root = "$RealBin/../.."; + +# Each entry: the spec, and what its openSUSE branch must and must not ask for. +my @cases = ( + { + spec => 'xCAT/xCAT.spec', + require => [ 'chrony', '/usr/sbin/dhcpd' ], + }, + { + spec => 'xCATsn/xCATsn.spec', + require => [ '/usr/sbin/dhcpd' ], + }, + { + spec => 'xCAT-server/xCAT-server.spec', + require => [ 'perl(DB_File)' ], + }, +); + +for my $c (@cases) { + my $path = "$root/$c->{spec}"; + ok(-f $path, "$c->{spec} exists") or next; + my $text = read_text($path); + + # The openSUSE branch is the region guarded by %if 0%{?suse_version}. Collect those regions + # so an assertion cannot be satisfied by a line that only EL ever sees. + my @suse; + my $depth = 0; + for my $line (split /\n/, $text) { + if ($line =~ /^\s*%if\s+0%\{\?suse_version\}/) { $depth = 1; next } + if ($depth) { + if ($line =~ /^\s*%(?:endif|else)/) { $depth = 0; next } + push @suse, $line; + } + } + my $suse = join "\n", @suse; + + for my $want (@{ $c->{require} }) { + my $q = quotemeta $want; + like($suse, qr/^\s*Requires:\s*(?:\S+\s+)*\Q$want\E\s*$/m, + "$c->{spec} asks openSUSE for $want"); + } +} + +subtest 'no rich dependency reaches an openSUSE build' => sub { + # rpm 4.11 on the sles12 management node cannot evaluate one, and a single core build serves + # both the sles15 and sles12 cells, so the openSUSE branch must carry none. + for my $spec (qw(xCAT/xCAT.spec xCATsn/xCATsn.spec)) { + my $path = "$root/$spec"; + my $text = read_text($path); + my @suse; + my $depth = 0; + for my $line (split /\n/, $text) { + if ($line =~ /^\s*%if\s+0%\{\?suse_version\}/) { $depth = 1; next } + if ($depth) { + if ($line =~ /^\s*%(?:endif|else)/) { $depth = 0; next } + push @suse, $line; + } + } + my @rich = grep { /^\s*Requires:\s*\(/ } @suse; + is(scalar @rich, 0, "$spec gives openSUSE no rich dependency"); + diag("rich dependency in the openSUSE branch: $_") for @rich; + } +}; + +# The EL and openEuler expressions must survive: this is an addition for openSUSE, not a +# replacement of the behaviour every other platform has today. +subtest 'EL and openEuler keep the expressions they have' => sub { + my $xcat = read_text("$root/xCAT/xCAT.spec"); + like($xcat, qr/\Qif openEuler-release else\E/, + 'xCAT.spec still carries the openEuler/EL10 dhcpd expression'); + like($xcat, qr/\Q(chrony or ntp)\E/, + 'xCAT.spec still offers EL the choice of chrony or ntp'); + my $sn = read_text("$root/xCATsn/xCATsn.spec"); + like($sn, qr/\Qif openEuler-release else\E/, + 'xCATsn.spec still carries the openEuler/EL10 dhcpd expression'); + my $srv = read_text("$root/xCAT-server/xCAT-server.spec"); + like($srv, qr/^\s*Recommends:\s*perl-DB_File\s*$/m, + 'xCAT-server.spec still asks EL10 weakly for perl-DB_File'); +}; + +done_testing(); From 844a5ba350b31638bb0b3c76a5f157132775859b Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 11:44:53 -0300 Subject: [PATCH 32/45] fix(xcat-core): xCAT cannot be installed on either openSUSE node Both openSUSE test cells fail the install step: leap15.6: nothing provides 'perl-DB_File' needed by xCAT-server sles12: nothing provides (/usr/sbin/dhcpd if openEuler-release else ((kea and kea-hooks) if (system-release >= 10) else /usr/sbin/dhcpd)) needed by xCAT Two requirements are written for EL and have no answer on openSUSE. xCAT-server asks for perl-DB_File. No package of that name exists on Leap 15.6 or 42.3: 15.6 calls it perl-core-DB_File and 42.3 has neither. Both provide the capability perl(DB_File), so openSUSE asks for the capability. xCAT and xCATsn ask for dhcpd through a rich dependency. The sles12 cell is an openSUSE 42.3 management node whose rpm is 4.11, which has no rich dependencies and reports the whole expression as an unprovided capability. Neither Leap release carries kea and both carry chrony and ISC dhcpd, so openSUSE takes the plain names the expressions resolve to there anyway. One core build serves both openSUSE cells, so the openSUSE branch must emit no rich dependency at all. Verified per platform with rpmspec. openSUSE now gets perl(DB_File), /usr/sbin/dhcpd and chrony; EL9 keeps perl-DB_File and both expressions; EL10 keeps perl-DB_File as a Recommends; openEuler keeps both expressions. xCAT-test/unit/opensuse_mn_requires.t fails on the commit before this one. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-server/xCAT-server.spec | 6 ++++++ xCAT/xCAT.spec | 11 ++++++++++- xCATsn/xCATsn.spec | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/xCAT-server/xCAT-server.spec b/xCAT-server/xCAT-server.spec index 8fc21abee1..43ab9e20a9 100644 --- a/xCAT-server/xCAT-server.spec +++ b/xCAT-server/xCAT-server.spec @@ -58,13 +58,19 @@ Requires: perl-Net-Telnet perl-Net-DNS perl-Crypt-CBC perl-Crypt-Rijndael # and skipped where it cannot. The dependency generator still turns that "use DB_File" # into a hard perl(DB_File) requirement; drop it there too, appending to any filter the # build root already set. Every other platform keeps the hard requirement it has today. +# openSUSE has no package of that name: Leap 15.6 calls it perl-core-DB_File and 42.3 has +# neither, but both provide the capability, so ask for the capability there. %if 0%{?rhel} >= 10 Recommends: perl-DB_File %global __requires_exclude %{?__requires_exclude:%{__requires_exclude}|}^perl\\(DB_File\\)$ %else +%if 0%{?suse_version} +Requires: perl(DB_File) +%else Requires: perl-DB_File %endif %endif +%endif Obsoletes: atftp-xcat %endif diff --git a/xCAT/xCAT.spec b/xCAT/xCAT.spec index ee174a1cb0..b5f9c4c1c9 100644 --- a/xCAT/xCAT.spec +++ b/xCAT/xCAT.spec @@ -78,9 +78,18 @@ Requires: net-tools Requires: /usr/bin/killall # makentp/setupntp configure the MN as an NTP server for its compute nodes and support chronyd/ntpd # only. chrony is the default on EL7+/SLES15+ (and the only option on EL8+); ntp covers the rest. -Requires: (chrony or ntp) # openEuler's system-release version does not identify an EL release. +# +# openSUSE takes plain names. The sles12 cell is an openSUSE 42.3 node whose rpm is 4.11, which +# has no rich dependencies and reports the whole expression as an unprovided capability. Neither +# Leap release carries kea, so these expressions resolve to chrony and ISC dhcpd there anyway. +%if 0%{?suse_version} +Requires: chrony +Requires: /usr/sbin/dhcpd +%else +Requires: (chrony or ntp) Requires: (/usr/sbin/dhcpd if openEuler-release else ((kea and kea-hooks) if (system-release >= 10) else /usr/sbin/dhcpd)) +%endif # On RHEL this pulls in openssh-server, on SLES it pulls in openssh Requires: /usr/bin/ssh %if %nots390x diff --git a/xCATsn/xCATsn.spec b/xCATsn/xCATsn.spec index cea6eeda81..ea25966fd5 100644 --- a/xCATsn/xCATsn.spec +++ b/xCATsn/xCATsn.spec @@ -63,7 +63,14 @@ Requires: /usr/bin/killall # yaboot-xcat is pulled in so any SN can manage ppc nodes Requires: httpd nfs-utils nmap bind # openEuler's system-release version does not identify an EL release. +# +# openSUSE takes the plain name: rpm 4.11 on the sles12 node has no rich dependencies, and +# neither Leap release carries kea, so the expression resolves to ISC dhcpd there anyway. +%if 0%{?suse_version} +Requires: /usr/sbin/dhcpd +%else Requires: (/usr/sbin/dhcpd if openEuler-release else ((kea and kea-hooks) if (system-release >= 10) else /usr/sbin/dhcpd)) +%endif # On RHEL this pulls in openssh-server, on SLES it pulls in openssh Requires: /usr/bin/ssh %ifnarch s390x From 2c56d3d2e8a3e7b2e0103d0f86f39634a0aadba6 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 17:52:34 -0300 Subject: [PATCH 33/45] test(xcat-core): xcattest skips every case on an openSUSE management node xCAT::Test::OS::current_os returns undef on openSUSE. /etc/os-release carries ID="opensuse-leap" and the word sles appears nowhere in it, so the os-release arm falls through to its own return undef, and Leap ships none of /etc/redhat-release, /etc/lsb-release or /etc/SuSE-release to reach another arm. xcattest then warns "Use of uninitialized value $currentos" four times per case and rejects all of them: "Test case reg_linux_diskfull_installation_flat has an invalid OS option - Linux" and "There is no valid case to run". 328 of the shipped cases declare os:Linux, so an openSUSE management node runs none of them. The message blames the case, and the cases are skipped rather than failed, which reports no result at all. Measured 2026-10-24 on xcat20-mn, an openSUSE Leap 15.6 management node: current_os answered UNDEF, /etc/os-release holds ID="opensuse-leap" and VERSION_ID="15.6", and none of the three fallback files exist. Five assertions fail on this commit: Leap is recognised, at any Leap version, the older ID="opensuse" spelling, Tumbleweed, and a Leap node matching an os:Linux case. The fourteen that already existed pass, including the one that holds the change down -- a distribution whose os-release names neither sles nor openSUSE is still not recognised. The same bug was fixed on 2026-09-18 in f7be54a1b, against the chain of greps xcattest carried before xCAT::Test::OS existed. That branch was never merged, 3582c6ab1 rewrote the routine as a module without it, and its test lifted the routine out of xcattest with a regex. This test loads the module instead. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/xcattest_os_selection.t | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/xCAT-test/unit/xcattest_os_selection.t b/xCAT-test/unit/xcattest_os_selection.t index eed16fc128..9b55327cac 100644 --- a/xCAT-test/unit/xcattest_os_selection.t +++ b/xCAT-test/unit/xcattest_os_selection.t @@ -60,6 +60,56 @@ is(xCAT::Test::OS::current_os(a_system('lsb-release' => "DISTRIB_ID=Ubuntu\n")), 'Ubuntu is named from lsb-release'); is(xCAT::Test::OS::current_os(a_system('os-release' => qq{ID="sles"\nVERSION="15-SP6"\n})), 'sles', 'SLES is named from os-release'); + +# openSUSE. /etc/os-release carries ID="opensuse-leap" and no "sles" anywhere, and Leap ships +# none of redhat-release, lsb-release or SuSE-release, so current_os fell through its os-release +# arm and returned undef. xcattest then warned "Use of uninitialized value $currentos" four +# times per case and rejected every one: "Test case reg_linux_diskfull_installation_flat has an +# invalid OS option - Linux / There is no valid case to run". 328 of the shipped cases declare +# os:Linux, so an openSUSE management node ran none of them, and the two cases were skipped +# rather than failed -- no result at all. +# +# Measured 2026-10-24 on xcat20-mn, an openSUSE Leap 15.6 management node: current_os answered +# UNDEF, /etc/os-release holds ID="opensuse-leap" and VERSION_ID="15.6", and none of the three +# fallback files exist. +# +# openSUSE answers with the SLE family rather than a name of its own, which was decided on +# 2026-09-18 for the same bug against the routine xcattest carried before xCAT::Test::OS +# existed. Leap and SLE of the same major share a package set, sles.pm claims leap15, and +# xcat.org publishes the Leap dependencies under sles15. It also lets the 18 cases written +# os:sles select a Leap node, which a separate name would not. +my $LEAP_OS_RELEASE = <<'REL'; +NAME="openSUSE Leap" +VERSION="15.6" +ID="opensuse-leap" +ID_LIKE="suse opensuse" +VERSION_ID="15.6" +PRETTY_NAME="openSUSE Leap 15.6" +REL + +is(xCAT::Test::OS::current_os(a_system('os-release' => $LEAP_OS_RELEASE)), 'sles', + 'openSUSE Leap is the SLE family whose package set it shares'); + +my $leap16 = $LEAP_OS_RELEASE; +$leap16 =~ s/15\.6/16.0/g; +is(xCAT::Test::OS::current_os(a_system('os-release' => $leap16)), 'sles', + 'at any Leap version, so a new release needs no change here'); + +# Leap 42.3, which the sles12 cell runs, spells its ID without the -leap suffix. +my $leap42 = $LEAP_OS_RELEASE; +$leap42 =~ s/ID="opensuse-leap"/ID="opensuse"/; +$leap42 =~ s/15\.6/42.3/g; +is(xCAT::Test::OS::current_os(a_system('os-release' => $leap42)), 'sles', + 'the older spelling, ID="opensuse", is recognised too'); + +is(xCAT::Test::OS::current_os( + a_system('os-release' => qq{NAME="openSUSE Tumbleweed"\nID="opensuse-tumbleweed"\n})), + 'sles', 'Tumbleweed answers rather than falling through silently'); + +# The thing that actually broke: an empty answer matches no os: restriction at all. +my @linux = xCAT::Test::OS::linux_aliases(); +ok(scalar(grep { xCAT::Test::OS::current_os(a_system('os-release' => $LEAP_OS_RELEASE)) =~ /$_/i } @linux), + 'an openSUSE Leap management node matches an os:Linux case'); is(xCAT::Test::OS::current_os(a_system()), 'aix', 'a system with none of the release files is aix, as before'); From 12ac35da0375a9cfc1ce85b4c31894bbc41cfe17 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:47:32 -0300 Subject: [PATCH 34/45] test(xcat-core): xcatd does not start on an openSUSE node With the install dependencies resolved, xCAT installs on the leap15.6 node and the install gate still fails: [install] GATE: xcatd running + reachable with NO xcatconfig GATE FAIL: xcatd not active GATE FAIL: lsdef cannot reach xcatd GATE FAIL: site.xcatdport not seeded journalctl for xcatd has no entries at all, and loading the library by hand on the node says why: Can't locate JSON.pm in @INC ... (@INC contains: /opt/xcat/lib/perl ...) openSUSE has no perl-generators, so no perl(...) requirement is generated for any xCAT package and nothing installs the modules the code loads. Measured on xcat20-mn against the 85 external modules the EL build auto-requires: five are absent -- Date::Parse, Expect, HTML::Form, JSON and SNMP -- and the other 80 are present. The test names, per spec, the modules that package's openSUSE branch must ask for, mirroring what EL's generator emits for it. Nine assertions fail because no spec names them yet. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/opensuse_mn_requires.t | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/xCAT-test/unit/opensuse_mn_requires.t b/xCAT-test/unit/opensuse_mn_requires.t index 43446b8efa..cc81411b5b 100755 --- a/xCAT-test/unit/opensuse_mn_requires.t +++ b/xCAT-test/unit/opensuse_mn_requires.t @@ -40,8 +40,23 @@ my @cases = ( require => [ '/usr/sbin/dhcpd' ], }, { + # openSUSE has no perl-generators, so no perl(...) requirement is auto-generated and the + # modules each package loads must be named. Measured on xcat20-mn after a successful + # install: xcatd stayed inactive because xCAT::Table dies loading JSON, and Date::Parse, + # Expect, HTML::Form and SNMP were absent too. The other 80 modules the EL build + # auto-requires were present. Each list below mirrors what EL's generator emits for that + # package. spec => 'xCAT-server/xCAT-server.spec', - require => [ 'perl(DB_File)' ], + require => [ 'perl(DB_File)', + 'perl(Date::Parse)', 'perl(Expect)', 'perl(JSON)', 'perl(SNMP)' ], + }, + { + spec => 'perl-xCAT/perl-xCAT.spec', + require => [ 'perl(Expect)', 'perl(HTML::Form)', 'perl(JSON)', 'perl(SNMP)' ], + }, + { + spec => 'xCAT-client/xCAT-client.spec', + require => [ 'perl(Expect)' ], }, ); @@ -64,9 +79,9 @@ for my $c (@cases) { my $suse = join "\n", @suse; for my $want (@{ $c->{require} }) { - my $q = quotemeta $want; - like($suse, qr/^\s*Requires:\s*(?:\S+\s+)*\Q$want\E\s*$/m, - "$c->{spec} asks openSUSE for $want"); + # a Requires: line may name several capabilities, so match the token anywhere on it + my $found = grep { /^\s*Requires:/ && /(?:^|\s)\Q$want\E(?:\s|$)/ } @suse; + ok($found, "$c->{spec} asks openSUSE for $want"); } } From f47541e19b839b4cf3196e58ef7576d14a5e9d4f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 17:52:34 -0300 Subject: [PATCH 35/45] fix(xcat-core): an openSUSE management node is not recognised, so no case runs current_os reads /etc/os-release and returns undef for openSUSE. The word sles appears nowhere in Leap's os-release -- ID is opensuse-leap on 15.x and opensuse on 42.3 -- and Leap ships none of /etc/redhat-release, /etc/lsb-release or /etc/SuSE-release, so no other arm is reached. xcattest rejects every case on the resulting undef, and 328 of the shipped cases declare os:Linux. openSUSE now answers with the SLE family whose package set it shares, which is the answer decided on 2026-09-18 for the same bug: sles.pm claims leap15 and xcat.org publishes the Leap dependencies under sles15. It also lets the 18 cases written os:sles select a Leap node, which a name of its own would not. current_os has one consumer -- the os: comparison at xcattest:1052 -- so the answer affects nothing else. The match is on the whole file rather than on ID alone, because Leap 42.3 spells its ID opensuse and Tumbleweed opensuse-tumbleweed. It is placed after the sles test, so a real SLES node is unaffected. xcattest_os_selection.t passes, 19 of 19. Reverting this file alone fails its five openSUSE assertions and nothing else. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/lib/xCAT/Test/OS.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xCAT-test/lib/xCAT/Test/OS.pm b/xCAT-test/lib/xCAT/Test/OS.pm index 7bb05c0539..b50076881d 100644 --- a/xCAT-test/lib/xCAT/Test/OS.pm +++ b/xCAT-test/lib/xCAT/Test/OS.pm @@ -49,6 +49,13 @@ sub current_os { if (-f "$root/etc/os-release") { my $text = _slurp("$root/etc/os-release") // ''; return 'sles' if $text =~ /sles/; + # openSUSE answers with the SLE family whose package set it shares: sles.pm claims + # leap15 and xcat.org publishes the Leap dependencies under sles15. Leap's os-release + # says ID="opensuse-leap" and carries no SLES string, and Leap ships no + # /etc/SuSE-release, so without this arm the sub returns undef -- which matches no + # case's os: restriction, so xcattest skips every os-restricted case and reports it as + # "has an invalid OS option", blaming the case. + return 'sles' if $text =~ /opensuse/i; if ($text =~ /^ID\s*=\s*"?openeuler"?\s*$/mi) { my ($version) = $text =~ /^VERSION\s*=\s*"?([^"\n]+?)"?\s*$/mi; my $release = _openeuler_release($version); From ef7989112f615550599ff164c73388cfecdfc9a7 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:48:00 -0300 Subject: [PATCH 36/45] fix(xcat-core): xcatd does not start on an openSUSE node xCAT installs on the leap15.6 node and the install gate still fails: GATE FAIL: xcatd not active GATE FAIL: lsdef cannot reach xcatd GATE FAIL: site.xcatdport not seeded journalctl for xcatd has no entries, and loading the library by hand on the node says why: Can't locate JSON.pm in @INC ... (@INC contains: /opt/xcat/lib/perl ...) openSUSE has no perl-generators. Nothing generates a perl(...) requirement for any xCAT package there, so no spec installs the modules its code loads, and perl-xCAT names no Requires at all. Measured on xcat20-mn against the 85 external modules the EL build auto-requires: five are absent -- Date::Parse, Expect, HTML::Form, JSON and SNMP -- and the other 80 are present. Each openSUSE branch now names the modules EL's generator emits for that package, as capabilities, so the same core build serves the sles15 and sles12 cells: both Leap releases provide all five, from perl-TimeDate, perl-Expect, perl-HTML-Form, perl-JSON and perl-SNMP. Verified with rpmspec that only openSUSE gets these; EL and openEuler are unchanged and keep generating them. xCAT-test/unit/opensuse_mn_requires.t fails on the commit before this one. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- perl-xCAT/perl-xCAT.spec | 9 +++++++++ xCAT-client/xCAT-client.spec | 6 ++++++ xCAT-server/xCAT-server.spec | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/perl-xCAT/perl-xCAT.spec b/perl-xCAT/perl-xCAT.spec index aad2d042e9..d97f7dfb73 100644 --- a/perl-xCAT/perl-xCAT.spec +++ b/perl-xCAT/perl-xCAT.spec @@ -16,6 +16,15 @@ BuildArch: noarch BuildRequires: perl perl-DBI perl-JSON # Do not need the SOAP rpm require, because rpm will generate it automatically if hpoa.pm is included #Requires: perl-SOAP-Lite +# openSUSE has no perl-generators, so no perl(...) requirement is generated here and nothing +# installs the modules this code loads. xcatd stays inactive without them: xCAT::Table dies +# loading JSON. EL and openEuler generate these automatically and need no list. +%if 0%{?suse_version} +Requires: perl(Expect) +Requires: perl(HTML::Form) +Requires: perl(JSON) +Requires: perl(SNMP) +%endif %endif %description diff --git a/xCAT-client/xCAT-client.spec b/xCAT-client/xCAT-client.spec index 2f6b71e288..6c0daf8df1 100644 --- a/xCAT-client/xCAT-client.spec +++ b/xCAT-client/xCAT-client.spec @@ -31,6 +31,12 @@ BuildArch: noarch Requires: perl-xCAT = 4:%{version}-%{release} Requires: cpio +# openSUSE has no perl-generators, so no perl(...) requirement is generated here and nothing +# installs the modules this code loads. xcatd stays inactive without them: xCAT::Table dies +# loading JSON. EL and openEuler generate these automatically and need no list. +%if 0%{?suse_version} +Requires: perl(Expect) +%endif # fping or nmap is needed by pping (in case xCAT-client is installed by itself on a remote client) %ifos linux diff --git a/xCAT-server/xCAT-server.spec b/xCAT-server/xCAT-server.spec index 43ab9e20a9..f1d94acb5e 100644 --- a/xCAT-server/xCAT-server.spec +++ b/xCAT-server/xCAT-server.spec @@ -52,6 +52,15 @@ Requires: perl-IO-Socket-SSL perl-XML-Simple perl-XML-Parser perl-Digest-SHA1 pe # Time::HiRes and Text::Balanced) are not pulled in transitively by perl-xCAT # either. List them here or the affected subcommands die at load time. Requires: perl-Net-Telnet perl-Net-DNS perl-Crypt-CBC perl-Crypt-Rijndael +# openSUSE has no perl-generators, so no perl(...) requirement is generated here and nothing +# installs the modules this code loads. xcatd stays inactive without them: xCAT::Table dies +# loading JSON. EL and openEuler generate these automatically and need no list. +%if 0%{?suse_version} +Requires: perl(Date::Parse) +Requires: perl(Expect) +Requires: perl(JSON) +Requires: perl(SNMP) +%endif # DB_File is only used by the Confluent client (lib/xcat/Confluent/Client.pm). EL10 # dropped libdb: EPEL still carries perl-DB_File for x86_64 and ppc64le, but riscv64 has # no EPEL at all, so on EL10 ask for the module weakly -- it is installed where it exists From a09fd53acd60beac5a3a9147186ea52a7da997ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:44:52 -0300 Subject: [PATCH 37/45] fix(boot): bound recursive node-template replacements --- perl-xCAT/xCAT/BootUtils.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/perl-xCAT/xCAT/BootUtils.pm b/perl-xCAT/xCAT/BootUtils.pm index 98e3654ed3..95399a3ee8 100644 --- a/perl-xCAT/xCAT/BootUtils.pm +++ b/perl-xCAT/xCAT/BootUtils.pm @@ -47,13 +47,25 @@ sub expand_node_template { my ($node, $text, $on_error) = @_; return $text unless defined($text); + # Each initial token contributes to its pass's shared replacement budget. + my $replacements_per_token = 16; + my $remaining = $replacements_per_token * (() = $text =~ /#NODEATTRIB:[^:#]+:[^:#]+#/g); while ($text =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { + unless ($remaining--) { + $on_error->("Node template expansion exceeded its replacement limit at #NODEATTRIB:$1:$2#"); + return; + } my $table = xCAT::Table->new($1); my $entry = $table->getNodeAttribs($node, [$2]); my $value = $entry->{$2} // ''; $text =~ s/#NODEATTRIB:([^:#]+):([^:#]+)#/$value/; } + $remaining = $replacements_per_token * (() = $text =~ /#TABLE:[^:#]+:[^:#]+:[^:#]+#/g); while ($text =~ /#TABLE:([^:#]+):([^:#]+):([^:#]+)#/) { + unless ($remaining--) { + $on_error->("Node template expansion exceeded its replacement limit at #TABLE:$1:$2:$3#"); + return; + } my ($table_name, $key, $column) = ($1, $2, $3); if ($key =~ /THISNODE/ or $key =~ /\$NODE/) { my $table = xCAT::Table->new($table_name); From ef5ae328918d387f85a6bffb50e6209c56a7f601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:44:58 -0300 Subject: [PATCH 38/45] test(boot): reject cyclic node-template values --- xCAT-test/unit/boot_node_template.t | 184 ++++++++++++++++++---------- 1 file changed, 116 insertions(+), 68 deletions(-) diff --git a/xCAT-test/unit/boot_node_template.t b/xCAT-test/unit/boot_node_template.t index 3baac23444..4013eb68f7 100644 --- a/xCAT-test/unit/boot_node_template.t +++ b/xCAT-test/unit/boot_node_template.t @@ -52,6 +52,16 @@ sub render { nested => '#NODEATTRIB:hosts:ip#', table => '#TABLE:hosts:THISNODE:ip#', special => 'a$1\\b&c', + selfref => '#NODEATTRIB:hosts:selfref#', + tableself => '#TABLE:hosts:THISNODE:tableself#', + cycle_a => '#NODEATTRIB:hosts:cycle_b#', + cycle_b => '#NODEATTRIB:hosts:cycle_a#', + table_a => '#TABLE:hosts:THISNODE:table_b#', + table_b => '#TABLE:hosts:THISNODE:table_a#', + growing => 'x#NODEATTRIB:hosts:growing#', + tablegrow => 'x#TABLE:hosts:THISNODE:tablegrow#', + (map { ("depth$_" => $_ == 16 ? $node : '#NODEATTRIB:hosts:depth' . ($_ + 1) . '#') } 0 .. 16), + (map { ("tabledepth$_" => $_ == 16 ? $node : '#TABLE:hosts:THISNODE:tabledepth' . ($_ + 1) . '#') } 0 .. 16), }}, ); for my $other (@nodes) { @@ -70,6 +80,7 @@ sub render { } no warnings qw(redefine once); local @ARGV; + local $::myxcatname = 'mn.example'; local *xCAT::Table::new = sub { my ($class, $table) = @_; die "Unexpected table $table" unless exists $rows{$table}; @@ -86,7 +97,8 @@ sub render { local *xCAT::NetworkUtils::checkNodeIPaddress = sub { return {ip => $_[1]}; }; local *xCAT::MsgUtils::trace = sub { return; }; my $callback = sub { - push @responses, dclone($_[0]) if @responses < 5; + die "too many callback responses\n" if @responses == 5; + push @responses, dclone($_[0]); }; my $completed = eval { local $SIG{ALRM} = sub { die "template expansion timed out\n"; }; @@ -132,6 +144,16 @@ my @cases = ( ['empty and zero', 'a=#NODEATTRIB:hosts:empty# b=#NODEATTRIB:hosts:zero#', 'a= b=0', 'quiet a= b=0 '], ['repeat', '#NODEATTRIB:hosts:ip#,#NODEATTRIB:hosts:ip#', '192.0.2.10,192.0.2.10', 'quiet 192.0.2.10,192.0.2.10 '], ['nested node', '#NODEATTRIB:hosts:nested#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['node replacement limit', '#NODEATTRIB:hosts:depth1#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['table replacement limit', '#TABLE:hosts:THISNODE:tabledepth1#', '192.0.2.10', 'quiet 192.0.2.10 '], + ['shared node budget', '#NODEATTRIB:hosts:depth0#,#NODEATTRIB:hosts:ip#', + '192.0.2.10,192.0.2.10', 'quiet 192.0.2.10,192.0.2.10 '], + ['shared table budget', '#TABLE:hosts:THISNODE:tabledepth0#,#TABLE:hosts:THISNODE:ip#', + '192.0.2.10,192.0.2.10', 'quiet 192.0.2.10,192.0.2.10 '], + ['many independent nodes', join(',', ('#NODEATTRIB:hosts:ip#') x 20), + join(',', ('192.0.2.10') x 20), 'quiet ' . join(',', ('192.0.2.10') x 20) . ' '], + ['many independent tables', join(',', ('#TABLE:hosts:THISNODE:ip#') x 20), + join(',', ('192.0.2.10') x 20), 'quiet ' . join(',', ('192.0.2.10') x 20) . ' '], ['node then table', '#NODEATTRIB:hosts:table#', '192.0.2.10', 'quiet 192.0.2.10 '], ['table recursion', '#TABLE:hosts:THISNODE:table#', '192.0.2.10', 'quiet 192.0.2.10 '], ['table does not restart node pass', '#TABLE:hosts:THISNODE:nested#', '#NODEATTRIB:hosts:ip#', 'quiet #NODEATTRIB:hosts:ip# '], @@ -186,77 +208,103 @@ for my $method (qw(pxe xnba ipxe boottarget)) { }; } +my @failures; +for my $position (0, 1, 2) { + for my $existing (0, 1) { + push @failures, [$position, $existing, 'unsupported key', + 'before=#NODEATTRIB:hosts:ip# #TABLE:hosts:unsupported:ip# #TABLE:hosts:other:ip#', + 'Table key of unsupported not yet supported by boottarget mini-template']; + } +} +for my $case ( + ['node self-reference', '#NODEATTRIB:hosts:selfref#'], + ['table self-reference', '#TABLE:hosts:THISNODE:tableself#'], + ['node cycle', '#NODEATTRIB:hosts:cycle_a#'], + ['table cycle', '#TABLE:hosts:THISNODE:table_a#'], + ['growing node', '#NODEATTRIB:hosts:growing#'], + ['growing table', '#TABLE:hosts:THISNODE:tablegrow#'], + ['node over limit', '#NODEATTRIB:hosts:depth0#', '#NODEATTRIB:hosts:depth16#'], + ['table over limit', '#TABLE:hosts:THISNODE:tabledepth0#', '#TABLE:hosts:THISNODE:tabledepth16#'], + ['node budget stays separate', '#NODEATTRIB:hosts:depth0#,#TABLE:hosts:THISNODE:ip#', + '#NODEATTRIB:hosts:depth16#'], + ['table budget stays separate', '#NODEATTRIB:hosts:ip#,#TABLE:hosts:THISNODE:tabledepth0#', + '#TABLE:hosts:THISNODE:tabledepth16#'], +) { + my ($name, $input, $token) = @$case; + $token //= $input; + push @failures, [1, 1, $name, $input, + "Node template expansion exceeded its replacement limit at $token"]; +} + for my $method (qw(pxe xnba ipxe boottarget)) { - for my $position (0, 1, 2) { - for my $existing (0, 1) { - subtest "$method unsupported key at $position existing=$existing" => sub { - my @nodes = qw(192.0.2.20 192.0.2.21 192.0.2.22); - my $bad = $nodes[$position]; - for my $good (grep { $_ ne $bad } @nodes) { - next if $method eq 'boottarget'; + for my $failure (@failures) { + my ($position, $existing, $name, $input, $message) = @$failure; + subtest "$method $name at $position existing=$existing" => sub { + my @nodes = qw(192.0.2.20 192.0.2.21 192.0.2.22); + my $bad = $nodes[$position]; + for my $good (grep { $_ ne $bad } @nodes) { + next if $method eq 'boottarget'; + my $file = $method eq 'pxe' ? "$tftp/pxelinux.cfg/$good" + : "$tftp/xcat/$method/nodes/$good"; + write_text($file, "previous boot configuration\n"); + } + my @files = $method eq 'pxe' ? ("$tftp/pxelinux.cfg/$bad") + : $method eq 'boottarget' ? () + : map { "$tftp/xcat/$method/nodes/$bad$_" } ('', '.pxelinux', '.uefi', '.elilo'); + for my $file (@files) { + if ($existing) { + write_text($file, "previous boot configuration\n"); + } else { + unlink($file) or die "unlink $file: $!" if -e $file; + } + } + my $link; + if ($method eq 'pxe') { + $link = "$tftp/pxelinux.cfg/" . sprintf('%02X%02X%02X%02X', split(/\./, $bad)); + unlink($link) or die "unlink $link: $!" if -e $link || -l $link; + symlink($bad, $link) or die "symlink $link: $!" if $existing; + } + my $exception = render($method, 'marker=#NODEATTRIB:hosts:ip#', + nodes => \@nodes, bad_node => $bad, + bad_input => $input); + is($exception, '', 'request completes before the timeout'); + my @expected = ({node => [{name => [$bad], errorcode => [1], error => [$message]}]}); + push @expected, {errorcode => [1], error => + ['Failed to generate xnba configurations for some node(s) on mn.example. Check xCAT log file for more details.']} + if $method eq 'xnba' || $method eq 'ipxe'; + is_deeply(\@responses, \@expected, + 'responses contain the node error and only the caller-required summary'); + for my $file (@files) { + if ($existing) { + ok(-f $file, 'failure keeps the existing artifact') or next; + is(read_text($file), "previous boot configuration\n", 'failure preserves the existing artifact'); + } else { + ok(!-e $file, 'failure creates no artifact'); + } + } + if ($link) { + if ($existing) { + ok(-l $link, 'failure preserves the existing boot symlink'); + is(readlink($link), $bad, 'failure preserves the boot symlink target'); + } else { + ok(!-e $link && !-l $link, 'failure creates no boot symlink'); + } + } + if ($method eq 'boottarget') { + ok(!exists($written{$bad}), 'failure does not update bootparams'); + } else { + is($kernels{$bad}{kcmdline}, 'quiet', 'failure does not append a partial expansion'); + } + for my $good (grep { $_ ne $bad } @nodes) { + if ($method eq 'boottarget') { + is($written{$good}{kcmdline}, "marker=$good", 'other nodes still update bootparams'); + } else { my $file = $method eq 'pxe' ? "$tftp/pxelinux.cfg/$good" : "$tftp/xcat/$method/nodes/$good"; - write_text($file, "previous boot configuration\n"); + like(read_text($file), qr/marker=\Q$good\E /, 'other nodes still get boot artifacts'); } - my @files = $method eq 'pxe' ? ("$tftp/pxelinux.cfg/$bad") - : $method eq 'boottarget' ? () - : map { "$tftp/xcat/$method/nodes/$bad$_" } ('', '.pxelinux', '.uefi', '.elilo'); - for my $file (@files) { - if ($existing) { - write_text($file, "previous boot configuration\n"); - } else { - unlink($file) or die "unlink $file: $!" if -e $file; - } - } - my $link; - if ($method eq 'pxe') { - $link = "$tftp/pxelinux.cfg/" . sprintf('%02X%02X%02X%02X', split(/\./, $bad)); - unlink($link) or die "unlink $link: $!" if -e $link || -l $link; - symlink($bad, $link) or die "symlink $link: $!" if $existing; - } - my $exception = render($method, 'marker=#NODEATTRIB:hosts:ip#', - nodes => \@nodes, bad_node => $bad, - bad_input => 'before=#NODEATTRIB:hosts:ip# #TABLE:hosts:unsupported:ip# #TABLE:hosts:other:ip#'); - is($exception, '', 'request completes before the timeout'); - my @node_errors = grep { $_->{errorcode} } - map { @{ $_->{node} || [] } } @responses; - is(scalar @node_errors, 1, 'one node error is reported'); - my $response = $node_errors[0] || {}; - is_deeply($response->{name}, [$bad], 'error identifies the failed node'); - is_deeply($response->{errorcode}, [1], 'response is an error'); - is($response->{error}[0] // '', 'Table key of unsupported not yet supported by boottarget mini-template', - 'error identifies the unsupported table key'); - for my $file (@files) { - if ($existing) { - is(read_text($file), "previous boot configuration\n", 'failure preserves the existing artifact'); - } else { - ok(!-e $file, 'failure creates no artifact'); - } - } - if ($link) { - if ($existing) { - ok(-l $link, 'failure preserves the existing boot symlink'); - is(readlink($link), $bad, 'failure preserves the boot symlink target'); - } else { - ok(!-e $link && !-l $link, 'failure creates no boot symlink'); - } - } - if ($method eq 'boottarget') { - ok(!exists($written{$bad}), 'failure does not update bootparams'); - } else { - is($kernels{$bad}{kcmdline}, 'quiet', 'failure does not append a partial expansion'); - } - for my $good (grep { $_ ne $bad } @nodes) { - if ($method eq 'boottarget') { - is($written{$good}{kcmdline}, "marker=$good", 'other nodes still update bootparams'); - } else { - my $file = $method eq 'pxe' ? "$tftp/pxelinux.cfg/$good" - : "$tftp/xcat/$method/nodes/$good"; - like(read_text($file), qr/marker=\Q$good\E /, 'other nodes still get boot artifacts'); - } - } - }; - } + } + }; } } From 4d5fc2b1b64d358c5915023a547eac954f9f024d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:00:28 -0300 Subject: [PATCH 39/45] test(netboot): support copied profile payload fixtures --- xCAT-test/native/debian_genimage_profile_assets.t | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/xCAT-test/native/debian_genimage_profile_assets.t b/xCAT-test/native/debian_genimage_profile_assets.t index a54728df04..30326fa183 100644 --- a/xCAT-test/native/debian_genimage_profile_assets.t +++ b/xCAT-test/native/debian_genimage_profile_assets.t @@ -5,17 +5,23 @@ use FindBin; use lib "$FindBin::Bin/../lib"; use File::Path qw(make_path); use Test::More; +use XCAT::Test::File qw(repo_path); use XCAT::Test::ImageSandbox; +use XCAT::Test::Process qw(run_command); plan skip_all => 'Linux namespaces are required' unless $^O eq 'linux'; die 'Run image tests as an unprivileged user' unless $>; +my $payload = shift @ARGV; +my $source = $payload // repo_path('xCAT-server/share/xcat/netboot/debian'); + sub standalone_image { my $box = XCAT::Test::ImageSandbox->new(); make_path("$box->{root}/work/share/xcat/netboot"); - my ($rc, $output, $error) = $box->run('cp', '-R', '--no-preserve=mode,ownership', - '/repo/xCAT-server/share/xcat/netboot/debian', '/work/share/xcat/netboot/'); - die "copy Debian scripts: $output $error" if $rc; + my @copy = ('-R', '--no-preserve=mode,ownership'); + push @copy, '-L' unless defined $payload; + my ($rc, $output) = run_command('cp', @copy, $source, "$box->{root}/work/share/xcat/netboot/"); + die "copy Debian scripts: $output" if $rc; return $box; } From 447db00a81eba87339cb9e9958b564447f65243e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:05:40 -0300 Subject: [PATCH 40/45] fix(netboot): keep profile helpers with shared image utilities Shared image utilities must not require the Debian source directory. Keep the profile helper beside imgutils and materialize the Debian copy when building RPM and DEB packages. Source-only Debian copies must follow symlinks; installed Debian directories stay self-contained. --- xCAT-server/debian/rules | 3 +++ .../xcat/netboot/debian/xCAT/ProfileUtils.pm | 18 +----------------- .../share/xcat/netboot/imgutils/imgutils.pm | 3 +-- .../xcat/netboot/imgutils/xCAT/ProfileUtils.pm | 17 +++++++++++++++++ xCAT-server/xCAT-server.spec | 5 +++++ 5 files changed, 27 insertions(+), 19 deletions(-) mode change 100644 => 120000 xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm create mode 100644 xCAT-server/share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm diff --git a/xCAT-server/debian/rules b/xCAT-server/debian/rules index 4e7eb5bb70..42e73c583f 100755 --- a/xCAT-server/debian/rules +++ b/xCAT-server/debian/rules @@ -44,6 +44,9 @@ binary-arch: dh_installdocs # dh_installexamples dh_install -X".svn" + # Debian scripts must remain self-contained when copied from an installed package. + rm -f $(rootdir)/share/xcat/netboot/debian/xCAT/ProfileUtils.pm + install -m 0644 share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm $(rootdir)/share/xcat/netboot/debian/xCAT/ProfileUtils.pm chmod 755 $(rootdir)/bin/* chmod 755 $(rootdir)/sbin/* chmod 644 $(rootdir)/share/xcat/ca/* diff --git a/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm b/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm deleted file mode 100644 index fb6e53e1e2..0000000000 --- a/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm +++ /dev/null @@ -1,17 +0,0 @@ -package xCAT::ProfileUtils; - -use strict; -use warnings; - -sub find_profile_asset { - my ($base, $profile, $arch, $ext, @versions) = @_; - - my @suffixes = ((map { "$_.$arch" } @versions), $arch, @versions, ''); - foreach my $suffix (@suffixes) { - my $file = "$base/$profile" . (length($suffix) ? ".$suffix" : '') . ".$ext"; - return $file if -r $file; - } - return ''; -} - -1; diff --git a/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm b/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm new file mode 120000 index 0000000000..39bd0e65dd --- /dev/null +++ b/xCAT-server/share/xcat/netboot/debian/xCAT/ProfileUtils.pm @@ -0,0 +1 @@ +../../imgutils/xCAT/ProfileUtils.pm \ No newline at end of file diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 73b50343eb..9cc0b35c7b 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -11,8 +11,7 @@ use File::Copy qw(move); use File::Find; use File::Path; use Cwd qw(realpath); -# Debian's standalone builder carries this helper with its copied scripts. -use lib dirname(__FILE__) . '/../debian'; +use lib dirname(__FILE__); use xCAT::ProfileUtils; use xCAT::SvrUtils; diff --git a/xCAT-server/share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm b/xCAT-server/share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm new file mode 100644 index 0000000000..fb6e53e1e2 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm @@ -0,0 +1,17 @@ +package xCAT::ProfileUtils; + +use strict; +use warnings; + +sub find_profile_asset { + my ($base, $profile, $arch, $ext, @versions) = @_; + + my @suffixes = ((map { "$_.$arch" } @versions), $arch, @versions, ''); + foreach my $suffix (@suffixes) { + my $file = "$base/$profile" . (length($suffix) ? ".$suffix" : '') . ".$ext"; + return $file if -r $file; + } + return ''; +} + +1; diff --git a/xCAT-server/xCAT-server.spec b/xCAT-server/xCAT-server.spec index 2bbeaaaad3..ccd3db0837 100644 --- a/xCAT-server/xCAT-server.spec +++ b/xCAT-server/xCAT-server.spec @@ -179,6 +179,11 @@ cp -hpR share/xcat/install/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/install/ cp -hpR share/xcat/netboot/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/ %endif +# Debian scripts must remain self-contained when copied from an installed package. +rm -f $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/debian/xCAT/ProfileUtils.pm +cp share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/debian/xCAT/ProfileUtils.pm +chmod 644 $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/debian/xCAT/ProfileUtils.pm $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/imgutils/xCAT/ProfileUtils.pm + %ifos linux # pwd cp -d sbin/* $RPM_BUILD_ROOT/%{prefix}/sbin From c35fabe185dfc0fa10fe736b7c03e207e0e9b575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:05:41 -0300 Subject: [PATCH 41/45] test(netboot): cover copied profile helper layouts --- xCAT-test/native/profile_package_payload.t | 23 +++++++++++++- xCAT-test/unit/imgutils_standalone.t | 36 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/unit/imgutils_standalone.t diff --git a/xCAT-test/native/profile_package_payload.t b/xCAT-test/native/profile_package_payload.t index b380ccd92e..a97a0da1e7 100644 --- a/xCAT-test/native/profile_package_payload.t +++ b/xCAT-test/native/profile_package_payload.t @@ -48,6 +48,21 @@ my ($status, $output) = run_command($^X, repo_path('xCAT-test/unit/profile_customization.t'), "$root/opt/xcat"); is($status, 0, 'packaged profiles resolve and remain independently customizable') or diag($output); +my $netboot = "$root/opt/xcat/share/xcat/netboot"; +for my $directory (qw(debian imgutils)) { + my $helper = "$netboot/$directory/xCAT/ProfileUtils.pm"; + ok(-f $helper && !-l $helper, "$directory ships a regular profile helper") or next; + is(sprintf('%04o', S_IMODE((stat($helper))[2])), '0644', "$directory helper is readable without write access for others"); +} +for my $case ( + ['unit/imgutils_standalone.t', 'imgutils'], + ['native/debian_genimage_profile_assets.t', 'debian'], +) { + my ($test, $directory) = @$case; + my ($rc, $result) = run_command($^X, repo_path("xCAT-test/$test"), "$netboot/$directory"); + is($rc, 0, "packaged $directory works when copied without sibling directories") or diag($result); +} + if (!-f '/etc/debian_version') { local $ENV{fsm} = 1; my $reduced = tempdir(CLEANUP => 1); @@ -65,7 +80,7 @@ if (!-f '/etc/debian_version') { my $data = 'install/rh/compute.rhels10.riscv64.pkglist'; my $postinstall = 'netboot/rocky/compute.rocky10.riscv64.postinstall'; chmod(oct('0666'), "$profiles/$data") == 1 or die "chmod: $!"; - for my $mask ('0022', '0002') { + for my $mask ('0022', '0002', '0077') { subtest "Debian writable sources with umask $mask" => sub { my $previous = umask oct($mask); my $deb = XCAT::Test::Lifecycle::build_deb('xCAT-server', $fixture); @@ -80,6 +95,12 @@ if (!-f '/etc/debian_version') { my $payload = tempdir(CLEANUP => 1); XCAT::Test::Lifecycle::checked('dpkg-deb', '-x', $deb, $payload); check_assets($payload, '', @assets); + for my $directory (qw(debian imgutils)) { + my $helper = "$payload/opt/xcat/share/xcat/netboot/$directory/xCAT/ProfileUtils.pm"; + ok(-f $helper && !-l $helper, "$directory ships a regular helper with umask $mask"); + is(sprintf('%04o', S_IMODE((stat($helper))[2])), '0644', + "$directory helper retains readable permissions with umask $mask"); + } for my $path (qw(install install/rh netboot netboot/rocky netboot/ubuntu/genimage)) { is(sprintf('%04o', S_IMODE((stat("$payload/opt/xcat/share/xcat/$path"))[2])), '0755', "$path remains executable without group or other write access"); diff --git a/xCAT-test/unit/imgutils_standalone.t b/xCAT-test/unit/imgutils_standalone.t new file mode 100644 index 0000000000..5b8a534733 --- /dev/null +++ b/xCAT-test/unit/imgutils_standalone.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use Cwd qw(realpath); +use File::Path qw(make_path); +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Process qw(run_command); + +my $source = shift @ARGV // repo_path('xCAT-server/share/xcat/netboot/imgutils'); +my $root = tempdir(CLEANUP => 1); +my ($status, $output) = run_command('cp', '-R', $source, "$root/imgutils"); +die "copy imgutils: $output" if $status; +make_path("$root/assets"); +my $assets = realpath("$root/assets"); + +local $ENV{PERL5LIB} = ''; +local $ENV{XCATROOT} = '/nonexistent'; +for my $extension (qw(pkglist otherpkgs.pkglist postinstall)) { + my $selected = "$assets/compute.debian12.x86_64.$extension"; + write_text($selected, "selected\n"); + write_text("$root/assets/compute.$extension", "fallback\n"); + my ($rc, $result) = run_command($^X, + '-I' . repo_path('perl-xCAT'), '-I' . repo_path('xCAT-server/lib/perl'), + '-e', 'require shift @ARGV; print imgutils::get_profile_def_filename(@ARGV)', + "$root/imgutils/imgutils.pm", + 'debian12.5', 'compute', 'x86_64', "$root/assets", $extension); + is($rc, 0, "copied imgutils loads without any sibling distro directory") or diag($result); + is($result, $selected, "copied imgutils selects the $extension version fallback"); +} + +done_testing(); From a2eaa50a7c20ec68de954ffef20972c680aa441e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:06:25 -0300 Subject: [PATCH 42/45] docs(netboot): explain standalone Debian source copies --- docs/source/guides/admin-guides/references/man1/genimage.1.rst | 3 +++ xCAT-client/pods/man1/genimage.1.pod | 3 +++ xCAT-test/native/README.md | 2 ++ 3 files changed, 8 insertions(+) diff --git a/docs/source/guides/admin-guides/references/man1/genimage.1.rst b/docs/source/guides/admin-guides/references/man1/genimage.1.rst index 31022bf893..55399c64f7 100644 --- a/docs/source/guides/admin-guides/references/man1/genimage.1.rst +++ b/docs/source/guides/admin-guides/references/man1/genimage.1.rst @@ -55,6 +55,9 @@ If this does not work or the management node is not the same distro level, copy /opt/xcat/share/xcat/netboot/ to a system that is the proper architecture, and mount /install from the management node to that system. Then change directory to /opt/xcat/share/xcat/netboot/ and run ./genimage. +When copying Debian scripts from a source checkout, use \ **cp -RL**\ to include +the shared profile helper. Installed packages include the helper in the Debian directory. + ********** Parameters diff --git a/xCAT-client/pods/man1/genimage.1.pod b/xCAT-client/pods/man1/genimage.1.pod index 48633e5972..2d1988d395 100644 --- a/xCAT-client/pods/man1/genimage.1.pod +++ b/xCAT-client/pods/man1/genimage.1.pod @@ -38,6 +38,9 @@ If this does not work or the management node is not the same distro level, copy /opt/xcat/share/xcat/netboot/ to a system that is the proper architecture, and mount /install from the management node to that system. Then change directory to /opt/xcat/share/xcat/netboot/ and run ./genimage. +When copying Debian scripts from a source checkout, use B to include +the shared profile helper. Installed packages include the helper in the Debian directory. + =head1 Parameters diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 7814d8d912..bb09bec715 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -50,6 +50,8 @@ isolated filesystem. It checks custom and shipped package lists, extra-package lists and postinstall scripts. Package tools and postinstall scripts stop with deliberate failures after recording the selected input. Only the Debian script directory is copied, with no installed xCAT libraries. +Source-checkout copies follow symlinks. An optional directory argument checks +a package payload without following symlinks. It does not install packages or build an initrd. The pull-request workflow runs these packaging cases explicitly as an ordinary From 001edc1a9f2c4c82adcd065b25cb602ec801815e Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:36:35 -0300 Subject: [PATCH 43/45] fix(xcat-core): package_relations.t expects perl-DB_File on openSUSE xCAT-server now asks for the perl(DB_File) capability on openSUSE, because no openSUSE release ships a package named perl-DB_File. The native package relation test still counted perl-DB_File in the SLES12 and SLES15 requirements, so both checks failed in xcat_pr_test. Expect perl(DB_File) on the SLES platforms and keep perl-DB_File for the others. The test fails against the upstream master spec and passes with this branch. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/native/package_relations.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/package_relations.t b/xCAT-test/native/package_relations.t index a49b6670fc..726a41827e 100644 --- a/xCAT-test/native/package_relations.t +++ b/xCAT-test/native/package_relations.t @@ -46,7 +46,8 @@ for my $platform (@platforms) { like($requires, qr/^perl\(Digest::SHA\)$/m, "$name server s390x=$s390 requires Digest::SHA"); next if $s390; my $recommends = query('xCAT-server', 'x86_64', $macro, '--recommends'); - is(scalar(grep { $_ eq 'perl-DB_File' } split /\n/, $requires), $name eq 'EL10' ? 0 : 1, + my $db_file = $name =~ /^SLES/ ? 'perl(DB_File)' : 'perl-DB_File'; + is(scalar(grep { $_ eq $db_file } split /\n/, $requires), $name eq 'EL10' ? 0 : 1, "$name server hard DB_File dependency"); is(scalar(grep { $_ eq 'perl-DB_File' } split /\n/, $recommends), $name eq 'EL10' ? 1 : 0, "$name server weak DB_File dependency"); From e3429791c66b19a2c55c173c810a5c2b3955748a Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:41:25 -0300 Subject: [PATCH 44/45] fix(xcat-core): getpostscript serves a node's postscripts to a password or token login With nodeauthentication off and no peer name, getpostscript used _xcat_authname as the client identity and expanded it with noderange. becomeuser and tokens set _xcat_authname to an account name, so a user named after a node group received the postscripts of the first node in that group. xcatd now records the CN of the validated client certificate as _xcat_certname, and only while no becomeuser or token replaced it. It deletes any _xcat_certname the client sent. getpostscript uses that name only when it names exactly one node, with no group or range expansion. _xcat_authname is no longer a candidate. getpostscript_client_identity.t drives the plugin with these requests. On the previous head the group and node login checks fail, and dropping the exact match fails the group and range checks. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- perl-xCAT/xCAT/DiscoveryUtils.pm | 81 +++++++++-- xCAT-server/lib/xcat/plugins/getpostscript.pm | 28 ++-- xCAT-server/sbin/xcatd | 6 + .../unit/getpostscript_client_identity.t | 126 +++++++++++------- 4 files changed, 167 insertions(+), 74 deletions(-) diff --git a/perl-xCAT/xCAT/DiscoveryUtils.pm b/perl-xCAT/xCAT/DiscoveryUtils.pm index 867293f4de..4da07036a0 100644 --- a/perl-xCAT/xCAT/DiscoveryUtils.pm +++ b/perl-xCAT/xCAT/DiscoveryUtils.pm @@ -122,18 +122,38 @@ sub update_discovery_data { #------------------------------------------------------------------------------- +=head3 client_certificate_name + + Descriptions: The name xcatd may record as the verified client certificate of a request. + becomeuser and tokens replace the authenticated name with an account name. + A name that differs from the certificate CN is therefore not a certificate name. + + Arguments : $cert_cn - the CN of the client certificate, undef when there is none + $authname - the authenticated name xcatd uses for the request + Returns : $cert_cn when the request is still authenticated by that certificate, else undef + +=cut + +#------------------------------------------------------------------------------- +sub client_certificate_name { + my ($cert_cn, $authname) = @_; + return undef unless defined $cert_cn && $cert_cn ne ''; + return undef unless defined $authname && $authname eq $cert_cn; + return $cert_cn; +} + +#------------------------------------------------------------------------------- + =head3 request_client_names Descriptions: The names a node-initiated request offers for correlating it to a node, most trustworthy first. xcatd fills _xcat_clienthost and _xcat_clientfqdn from a reverse lookup of the - peer socket, so both are empty when that lookup fails, however good the client - credentials are. _xcat_authname is the name in the validated client certificate - and does not depend on name resolution. - - The request's own node attribute is NOT a candidate. A client sends it, so it - states what the client wants to be rather than what it proved it is. + peer socket, so both are empty when that lookup fails. + _xcat_certname is the CN of the validated client certificate. + _xcat_authname is not a candidate: a password or a token can set it. + The request's own node attribute is not a candidate: the client sends it. Arguments : $request - the request hash xcatd built Returns : the candidate names, without duplicates; an empty list when there are none @@ -145,14 +165,53 @@ sub request_client_names { my ($request) = @_; return () unless ref($request) eq 'HASH'; my @names; - foreach my $key (qw(_xcat_clienthost _xcat_clientfqdn _xcat_authname)) { - my $value = $request->{$key}; - next unless ref($value) eq 'ARRAY'; - my $name = $value->[0]; - next unless defined $name && $name ne ''; + foreach my $key (qw(_xcat_clienthost _xcat_clientfqdn _xcat_certname)) { + my $name = _first_value($request, $key); + next unless defined $name; push @names, $name unless grep { $_ eq $name } @names; } return @names; } +#------------------------------------------------------------------------------- + +=head3 request_client_node + + Descriptions: The node a node-initiated request comes from. + A peer name is expanded as before, and the first node it gives is used. + The certificate name must name exactly one node, with no group or range + expansion, because xCAT signs user and node certificates with one CA. + + Arguments : $request - the request hash xcatd built + $expand - code ref that expands a noderange to a node list (noderange) + Returns : the node name, or undef when no candidate names a node + +=cut + +#------------------------------------------------------------------------------- +sub request_client_node { + my ($request, $expand) = @_; + return undef unless ref($request) eq 'HASH' && ref($expand) eq 'CODE'; + foreach my $key (qw(_xcat_clienthost _xcat_clientfqdn)) { + my $name = _first_value($request, $key); + next unless defined $name; + my ($node) = $expand->($name); + return $node if $node; + } + my $cert = _first_value($request, '_xcat_certname'); + return undef unless defined $cert; + my @nodes = $expand->($cert); + return $cert if @nodes == 1 && defined $nodes[0] && $nodes[0] eq $cert; + return undef; +} + +sub _first_value { + my ($request, $key) = @_; + my $value = $request->{$key}; + return undef unless ref($value) eq 'ARRAY'; + my $name = $value->[0]; + return undef unless defined $name && $name ne ''; + return $name; +} + 1; diff --git a/xCAT-server/lib/xcat/plugins/getpostscript.pm b/xCAT-server/lib/xcat/plugins/getpostscript.pm index 229040c045..2bf8a7fb75 100644 --- a/xCAT-server/lib/xcat/plugins/getpostscript.pm +++ b/xCAT-server/lib/xcat/plugins/getpostscript.pm @@ -58,30 +58,24 @@ sub process_request my $client; - my @candidates; if ($::XCATSITEVALS{nodeauthentication}) { #if requiring node authentication, this request will have a certificate associated with it, use it instead of name resolution unless (ref $request->{username}) { return; } #TODO: log an attempt without credentials? - @candidates = ($request->{username}->[0]); + ($client) = noderange($request->{username}->[0]); + unless ($client) { + xCAT::MsgUtils->trace(0, "E", "Received getpostscript from $request->{username}->[0], which couldn't be correlated to a node (domain mismatch?)"); + return; + } } else { - # The peer host and fqdn are a reverse lookup of the client socket, so both are empty when - # that lookup fails, however good the client credentials are. - # request_client_names adds the certificate name, and excludes the request's own node - # attribute, which the client sends and has not proved. - @candidates = xCAT::DiscoveryUtils::request_client_names($request); + my @candidates = xCAT::DiscoveryUtils::request_client_names($request); unless (@candidates) { xCAT::MsgUtils->trace(0, 'E', "Received getpostscript from a client this request does not identify: it carries no peer name and no client certificate name. Ignoring it."); return; } - } - - foreach my $candidate (@candidates) { - next unless defined $candidate && $candidate ne ''; - my ($node) = noderange($candidate); - if ($node) { $client = $node; last; } - } - unless ($client) { #Not able to do identify the host in question - xCAT::MsgUtils->trace(0, "E", "Received getpostscript from " . join(', ', @candidates) . ", none of which could be correlated to a node (domain mismatch?)"); - return; + $client = xCAT::DiscoveryUtils::request_client_node($request, \&noderange); + unless ($client) { #Not able to do identify the host in question + xCAT::MsgUtils->trace(0, "E", "Received getpostscript from " . join(', ', @candidates) . ", none of which could be correlated to a node (domain mismatch?)"); + return; + } } my $state; if ($request->{scripttype}) { $state = $request->{scripttype}->[0]; } diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index 3b7d09658f..3e91785e69 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -50,6 +50,7 @@ use xCAT::TLSPolicy qw(resolve_xcatd_tls_settings); use xCAT::TableUtils; use xCAT::NetworkUtils; use xCAT::MsgUtils; +use xCAT::DiscoveryUtils; use xCAT::RespawnUtils; use xCAT::xcatd; use xCAT::CmdLog; @@ -3027,6 +3028,8 @@ sub service_connection { my $peerhostorg = shift; my $peerip = shift; my $peerport = $sock->peerport; + # becomeuser and tokens replace $peername. Keep the certificate CN to tell the two apart. + my $cert_cn = $peername; # some paranoid measures could reduce a third party abusing stage3 image to attempting to get USER/PASS for BMCs: # -Well, minimally, ignore requests if requesting node is not in spconfig mode (stage3) @@ -3189,6 +3192,9 @@ sub service_connection { $request = ""; if (xCAT::xcatd->validate($peername, $peerhost, $req, $peerhostorg, \@deferredmsgargs)) { $req->{'_xcat_authname'} = [$peername]; + delete $req->{'_xcat_certname'}; + my $certname = xCAT::DiscoveryUtils::client_certificate_name($cert_cn, $peername); + $req->{'_xcat_certname'} = [$certname] if defined $certname; $req->{'_xcat_clienthost'} = [$peerhost]; $req->{'_xcat_clientfqdn'} = [$peerfqdn]; if ($req->{command}->[0] eq 'signx509cert') { diff --git a/xCAT-test/unit/getpostscript_client_identity.t b/xCAT-test/unit/getpostscript_client_identity.t index 5cd005ef8f..5fb0b2a448 100644 --- a/xCAT-test/unit/getpostscript_client_identity.t +++ b/xCAT-test/unit/getpostscript_client_identity.t @@ -1,18 +1,7 @@ #!/usr/bin/env perl -# A diskless node that boots and cannot be correlated to a node gets no postscripts, and that -# costs the whole provision: remoteshell never installs root's authorized_keys, so every xdsh and -# ssh answers "Permission denied (publickey)" on a node that answers ping, and nothing ever -# reports "booted". -# -# Measured on xcat59-mn, an openEuler 22.03sp4 management node, on 2026-10-24. xcatd logged -# "xCAT: Allowing getpostscript xcat59-cn" with no "from " and then "Received malformed -# getpostscript requesting, ignore it." -- 100 times, 0 "Sending scripts data" in the whole log, -# against 3 sends and 0 malformed on the green openEuler 24.03sp4 cell beside it. The client -# certificate named the node correctly; only the reverse lookup of the peer socket failed, and -# getpostscript.pm looked at nothing else. -# -# So the identity a request offers is its own decision, and this is it. The request hash is the -# only input and a list of names is the only output, so it is driven directly. +# getpostscript correlates a node-initiated request to a node. When the reverse lookup of the +# peer socket fails, the CN of the validated client certificate is the only other identity. +# A password or token login, and the request's own node attribute, must never select a node. use strict; use warnings; @@ -23,72 +12,117 @@ use lib File::Spec->catdir($FindBin::Bin, '..', '..', 'perl-xCAT'), File::Spec->catdir($FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'perl'); use xCAT::DiscoveryUtils; -# Which tree is under test. Ninety xCAT modules carry -# BEGIN { $::XCATROOT = $ENV{XCATROOT} || '/opt/xcat' } use lib "$::XCATROOT/lib/perl"; -# so the first xCAT module a test loads can put an INSTALLED product in front of the checkout in -# @INC, and a build host has one: /opt/xcat/lib/perl/xCAT/DiscoveryUtils.pm exists on xcat-master. -# A test that loaded that copy would pass while measuring a product built weeks ago, so say which -# file answered rather than assuming the use lib above won. +# Ninety xCAT modules put "$::XCATROOT/lib/perl" in @INC, so an installed product can shadow +# the checkout. Say which file answered. my $under_test = $INC{'xCAT/DiscoveryUtils.pm'} // ''; ok(length $under_test, 'xCAT::DiscoveryUtils was loaded at all'); unlike($under_test, qr{^/opt/xcat/}, "the module under test is this checkout's, not an installed one ($under_test)"); -can_ok('xCAT::DiscoveryUtils', 'request_client_names'); +can_ok('xCAT::DiscoveryUtils', qw(request_client_names request_client_node client_certificate_name)); sub names_for { return xCAT::DiscoveryUtils::request_client_names($_[0]) } -# The resolved peer stays first, so a management node whose reverse lookup works behaves exactly -# as it did. +# --- client_certificate_name: what xcatd records as _xcat_certname ------------------------- + +is(xCAT::DiscoveryUtils::client_certificate_name('xcat59-cn', 'xcat59-cn'), 'xcat59-cn', + 'a request authenticated by its certificate records the certificate CN'); +is(xCAT::DiscoveryUtils::client_certificate_name(undef, 'compute'), undef, + 'a token or password login without a certificate records no certificate name'); +is(xCAT::DiscoveryUtils::client_certificate_name('root', 'compute'), undef, + 'becomeuser to another account records no certificate name'); +is(xCAT::DiscoveryUtils::client_certificate_name('', ''), undef, + 'an empty certificate CN is not a name'); + +# --- request_client_names: the names logged and tried ------------------------------------- + is_deeply([ names_for({ _xcat_clienthost => ['xcat58-cn'], _xcat_clientfqdn => ['xcat58-cn.xcat58.lab'], - _xcat_authname => ['xcat58-cn'] }) ], + _xcat_certname => ['xcat58-cn'] }) ], [ 'xcat58-cn', 'xcat58-cn.xcat58.lab' ], 'the resolved peer host comes first, and the certificate name adds no duplicate'); -# The failure measured on xcat59-mn: xcatd set the peer host to the empty string, because the -# reverse lookup returned nothing. An empty name is not a name. is_deeply([ names_for({ _xcat_clienthost => [''], _xcat_clientfqdn => [''], - _xcat_authname => ['xcat59-cn'] }) ], + _xcat_certname => ['xcat59-cn'] }) ], [ 'xcat59-cn' ], 'an empty peer host is skipped and the certificate name is offered instead'); -# The same request with the keys absent rather than empty. -is_deeply([ names_for({ _xcat_authname => ['xcat59-cn'] }) ], [ 'xcat59-cn' ], - 'a request carrying only a certificate name still identifies its node'); - -# The fqdn alone is enough when the short name did not resolve. is_deeply([ names_for({ _xcat_clientfqdn => ['xcat59-cn.xcat59.lab'] }) ], [ 'xcat59-cn.xcat59.lab' ], 'the fully qualified peer name is offered when the short name is missing'); -# The node attribute is client-supplied: it says what the client wants to be. Offering it would -# let any host that can reach port 3001 ask for another node's postscripts, which carry the -# cluster's root ssh key. +is_deeply([ names_for({ _xcat_clienthost => [''], _xcat_authname => ['compute'] }) ], [], + 'the authenticated name of a password or token login is never offered'); + for my $request ({ node => ['xcat59-cn'] }, { node => ['xcat59-cn'], _xcat_clienthost => [''] }, - { node => ['some-other-node'], _xcat_authname => ['xcat59-cn'] }) { + { node => ['some-other-node'], _xcat_certname => ['xcat59-cn'] }) { my @got = names_for($request); ok(!grep({ $_ eq ($request->{node}->[0]) } @got), "the request's own node attribute is never offered as an identity (" . join(',', @got) . ')'); } -# Nothing to go on is an empty list, not an empty name: the caller must be able to tell the -# difference and say so. is_deeply([ names_for({}) ], [], 'a request with no identity at all offers no name'); is_deeply([ names_for(undef) ], [], 'an undefined request offers no name'); is_deeply([ names_for('string') ], [], 'a request that is not a hash offers no name'); -# Wrapped in eval, because without the guard the sub DIES here rather than returning a wrong -# answer, and a test that dies names no assertion -- it reports as a count discrepancy that is -# easy to skim past in a prove summary. my @unwrapped = eval { names_for({ _xcat_clienthost => 'xcat59-cn' }) }; is($@, '', 'a value xcatd did not wrap in an array ref does not kill the lookup'); is_deeply(\@unwrapped, [], 'and is ignored rather than dereferenced'); -# Duplicates would make the caller try the same noderange twice and log the same failure twice. -is_deeply([ names_for({ _xcat_clienthost => ['xcat59-cn'], - _xcat_clientfqdn => ['xcat59-cn'], - _xcat_authname => ['xcat59-cn'] }) ], - [ 'xcat59-cn' ], 'the same name arriving three ways is offered once'); +# --- request_client_node: the node selected ------------------------------------------------- + +# node01 and node02 are nodes, compute is a group of both. +my %groups = (compute => [qw(node01 node02)]); +my %nodes = map { $_ => 1 } qw(node01 node02); +sub expand { + my ($range) = @_; + return @{ $groups{$range} } if $groups{$range}; + return ('node01', 'node02') if $range eq 'node0[1-2]'; + return $nodes{$range} ? ($range) : (); +} +sub node_for { return xCAT::DiscoveryUtils::request_client_node($_[0], \&expand) } + +is(node_for({ _xcat_clienthost => ['node01'] }), 'node01', 'a resolved peer host selects its node'); +is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['node02'] }), 'node02', + 'a certificate CN that names exactly one node selects it'); +is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['compute'] }), undef, + 'a certificate CN that names a group selects no node'); +is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['node0[1-2]'] }), undef, + 'a certificate CN that is a node range selects no node'); +is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['nosuchnode'] }), undef, + 'a certificate CN that is not a node selects no node'); +is(node_for({ _xcat_clienthost => [''], _xcat_authname => ['node01'] }), undef, + 'the authenticated name alone selects no node'); +is(node_for({ _xcat_clienthost => ['node01'], _xcat_certname => ['node02'] }), 'node01', + 'the resolved peer host wins over the certificate CN'); + +# --- the plugin ----------------------------------------------------------------------------- + +require File::Spec->catfile($FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'xcat', 'plugins', 'getpostscript.pm'); +require xCAT::Postage; + +sub served { + my ($request) = @_; + my @served; + no warnings qw(redefine once); + local $::XCATSITEVALS{nodeauthentication} = 0; + local *xCAT_plugin::getpostscript::noderange = \&expand; + local *xCAT::Postage::makescript = sub { push @served, @{ $_[0] }; return ('#script') }; + local *xCAT::MsgUtils::trace = sub { }; + xCAT_plugin::getpostscript::process_request( + { command => ['getpostscript'], node => [], %$request }, sub { }); + return @served; +} + +is_deeply([ served({ _xcat_clienthost => [''], _xcat_authname => ['compute'] }) ], [], + 'the plugin serves no node to a password or token login named after a group'); +is_deeply([ served({ _xcat_clienthost => [''], _xcat_authname => ['node01'] }) ], [], + 'the plugin serves no node to a password or token login named after a node'); +is_deeply([ served({ _xcat_clienthost => [''], _xcat_certname => ['compute'] }) ], [], + 'the plugin serves no node to a certificate named after a group'); +is_deeply([ served({ _xcat_clienthost => [''], _xcat_certname => ['node02'] }) ], ['node02'], + 'the plugin serves the node its certificate names when the reverse lookup fails'); +is_deeply([ served({ _xcat_clienthost => ['node01'] }) ], ['node01'], + 'the plugin serves the node its peer host resolves to'); done_testing(); From b7076359f420ef45a8e318969ce939645cb2718f Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:42:47 -0300 Subject: [PATCH 45/45] fix(xcat-test): xcat-test can install without python3 on Debian python3-scapy was the only Depends of xcat-test that pulled in python3. With scapy moved to Recommends, apt-get install --no-install-recommends xcat-test can leave python3 absent, and every blackboxtest command fails before it starts, not only the DHCP steps. Add python3 to Depends. xcat_test_scapy_optional.t checks that python3 is a hard Depends, and fails without this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/debian/control | 9 +++------ xCAT-test/unit/xcat_test_scapy_optional.t | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xCAT-test/debian/control b/xCAT-test/debian/control index 2ab87adc1d..2ce6662a06 100644 --- a/xCAT-test/debian/control +++ b/xCAT-test/debian/control @@ -8,12 +8,9 @@ Homepage: https://xcat.org/ Package: xcat-test Architecture: all -Depends: ${perl:Depends} -# Only blackboxtest's DHCP steps need scapy, and dhcp.py imports it inside scapy_module(), -# which raises UnsupportedError naming this package when the import fails. So xcat-test -# installs and every other step runs without it, which is why xCAT-test.spec has only ever -# recommended it. A hard Depends: also pulls scapy's own recommends -- matplotlib, scipy and -# ipython3, about 255 MB over 54 packages -- into a CI step capped at 1200 seconds. +Depends: ${perl:Depends}, python3 +# blackboxtest needs python3. Only its DHCP steps need scapy, and dhcp.py reports a missing +# scapy itself. A hard Depends: on scapy also installs about 255 MB of its Recommends. Recommends: python3-scapy Description: xCAT automated test tool Provides automated test tool and buckets to help test xCAT commands diff --git a/xCAT-test/unit/xcat_test_scapy_optional.t b/xCAT-test/unit/xcat_test_scapy_optional.t index 9b22576723..a7097156c8 100644 --- a/xCAT-test/unit/xcat_test_scapy_optional.t +++ b/xCAT-test/unit/xcat_test_scapy_optional.t @@ -47,6 +47,9 @@ like($recommends // '', qr/python3-scapy/, 'python3-scapy is Recommended instead'); # The perl dependency is what makes the package work at all and must survive the change. like($depends // '', qr/\$\{perl:Depends\}/, 'the perl dependency is still a Depends'); +# blackboxtest is a python3 program. Without scapy, nothing else pulls in the interpreter. +my @hard = map { s/^\s+|\s+$//gr } split /,/, $depends // ''; +ok((grep { /^python3(?:\s|$)/ } @hard), 'python3 is a hard Depends of xcat-test'); # PARITY. The two packagings answer the same question, so they must answer it the same way: the # spec has recommended it since the tool was added, and the asymmetry is what this fixes.