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 001/114] 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 e7d52727193a0ab961600c1cb4512b0be3df35c7 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 07:51:05 -0300 Subject: [PATCH 002/114] fix(xcat-core): no test asserts the pod BuildRequires an openSUSE build needs The openSUSE Leap 15.6 core build dies in %build with "Can't locate Pod/Man.pm in @INC ... at ./xpod2man line 12" for xCAT-buildkit, xCAT-client, xCAT-test and xCAT-vlan. Nothing in the suite reads a spec to check that its pod converter dependency survives the suse_version conditionals, so the gap is invisible until a Leap chroot runs the converter and finds perl-base alone. This test reads every package spec, selects the ones whose %build runs xpod2man, pod2man or pod2html, and asserts each names a build dependency that holds when suse_version is defined. The spec list is derived from the checkout, so a new pod-converting spec is covered without editing the test. It fails on this commit for all six converting specs, each reporting no BuildRequires at all under suse_version. xCAT-confluent comments its converter call out, and the derivation excludes it. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/opensuse_pod_buildrequires.t | 95 +++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 xCAT-test/unit/opensuse_pod_buildrequires.t diff --git a/xCAT-test/unit/opensuse_pod_buildrequires.t b/xCAT-test/unit/opensuse_pod_buildrequires.t new file mode 100644 index 0000000000..93c29ceb8b --- /dev/null +++ b/xCAT-test/unit/opensuse_pod_buildrequires.t @@ -0,0 +1,95 @@ +#!/usr/bin/env perl +# openSUSE has no perl-generators, and its chroot carries only perl-base, which ships +# no Pod::Man and no pod2man. A spec that converts pods in %build must therefore name a +# build dependency that holds under suse_version, or the buildroot holds none by accident. +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use File::Spec; +use Test::More; + +use XCAT::Test::File qw(repo_path slurp_repo_file); + +#------------------------------------------------------------------------------- + +=head3 converts_pods + +Descriptions: Say whether a spec runs a pod converter in an active line. A commented +call does not count: xCAT-confluent carries one and needs no converter. + +Arguments: the spec text + +Returns: the number of converter calls + +=cut + +#------------------------------------------------------------------------------- +sub converts_pods { + my ($text) = @_; + return scalar(grep { /^\s*(\.\/xpod2man|pod2man|pod2html)\b/ } split /\n/, $text); +} + +#------------------------------------------------------------------------------- + +=head3 suse_buildrequires + +Descriptions: Collect the BuildRequires of a spec that apply when suse_version is +defined. Only the suse_version conditionals are evaluated; any other %if is entered, +because its BuildRequires can still reach a SUSE build. + +Arguments: the spec text + +Returns: the list of required package names + +=cut + +#------------------------------------------------------------------------------- +sub suse_buildrequires { + my ($text) = @_; + my @dead; # one entry per open conditional: true means the branch is not taken + my @names; + for my $line (split /\n/, $text) { + if ($line =~ /^%if\s*(!?)\s*0%\{\?suse_version\}\s*$/) { + push @dead, ($1 eq '!' ? 1 : 0); + } + elsif ($line =~ /^%if/) { + push @dead, 0; + } + elsif ($line =~ /^%else\b/) { + $dead[-1] = $dead[-1] ? 0 : 1 if @dead; + } + elsif ($line =~ /^%endif/) { + pop @dead; + } + elsif ($line =~ /^BuildRequires:\s*(.+?)\s*$/ && !grep { $_ } @dead) { + push @names, split /[,\s]+/, $1; + } + } + return @names; +} + +my %text; +for my $absolute (glob repo_path('*/*.spec')) { + my @parts = File::Spec->splitdir($absolute); + my $relative = File::Spec->catfile(@parts[-2, -1]); + $text{$relative} = slurp_repo_file($relative); +} +die "read no package spec from the checkout" unless keys %text > 10; + +my @converting = sort grep { converts_pods($text{$_}) } keys %text; +plan skip_all => 'no spec converts pods' unless @converting; +plan tests => 1 + scalar(@converting); + +cmp_ok(scalar(@converting), '>=', 4, 'several specs convert pods in %build'); + +# On Leap 15.6 perl(Pod::Man), perl(Pod::Html) and /usr/bin/pod2man are all in "perl"; +# "perl-Pod-Html" does not exist there at all. +for my $relative (@converting) { + my @required = suse_buildrequires($text{$relative}); + ok(scalar(grep { $_ eq 'perl' } @required), + "$relative build-requires perl on SUSE, which provides Pod::Man and pod2man") + or diag("BuildRequires under suse_version: " + . (@required ? join(', ', @required) : '(none)')); +} From 697c85174992b781acb5a49737c60b8f50b41ea5 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sat, 24 Oct 2026 07:52:41 -0300 Subject: [PATCH 003/114] fix(xcat-core): the openSUSE core build has no Pod::Man, so pod conversion fails The openSUSE Leap 15.6 target cannot build xCAT-buildkit, xCAT-client, xCAT-test or xCAT-vlan. Each dies in %build with "Can't locate Pod/Man.pm in @INC ... at ./xpod2man line 12", and that failure alone makes the openSUSE core build red. Six specs guard their pod converter dependency with "%if !0%{?suse_version}" around "BuildRequires: perl-Pod-Html". The guard is right that Leap has no perl-Pod-Html, but it drops the dependency instead of naming the package that replaces it. A Leap mock chroot then holds perl-base only, which ships neither Pod::Man nor pod2man, and openSUSE has no perl-generators to pull the full perl package in by accident. On Leap 15.6 the "perl" package provides perl(Pod::Man), perl(Pod::Html) and /usr/bin/pod2man. Each guard becomes a two-branch conditional that build-requires perl on SUSE and perl-Pod-Html elsewhere, so the EL buildroot is unchanged. opensuse_pod_buildrequires.t reported no BuildRequires under suse_version for all six specs on the preceding commit, and passes here. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec | 8 ++++++-- xCAT-SoftLayer/xCAT-SoftLayer.spec | 8 ++++++-- xCAT-buildkit/xCAT-buildkit.spec | 8 ++++++-- xCAT-client/xCAT-client.spec | 8 ++++++-- xCAT-test/xCAT-test.spec | 8 ++++++-- xCAT-vlan/xCAT-vlan.spec | 8 ++++++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec b/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec index 71fa9b96b7..23dc05a17b 100644 --- a/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec +++ b/xCAT-OpenStack-baremetal/xCAT-OpenStack-baremetal.spec @@ -20,8 +20,12 @@ BuildArch: noarch Provides: xCAT-OpenStack-baremetal = %{epoch}:%{version} Requires: xCAT-client -# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html -%if !0%{?suse_version} +# The pod converters are in perl-Pod-Html on EL and in the core perl package on +# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that +# ships neither Pod::Man nor pod2man. +%if 0%{?suse_version} +BuildRequires: perl +%else BuildRequires: perl-Pod-Html %endif diff --git a/xCAT-SoftLayer/xCAT-SoftLayer.spec b/xCAT-SoftLayer/xCAT-SoftLayer.spec index a2355ddba8..3ccb508e40 100644 --- a/xCAT-SoftLayer/xCAT-SoftLayer.spec +++ b/xCAT-SoftLayer/xCAT-SoftLayer.spec @@ -15,8 +15,12 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root BuildArch: noarch %endif Requires: xCAT-server -# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html -%if !0%{?suse_version} +# The pod converters are in perl-Pod-Html on EL and in the core perl package on +# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that +# ships neither Pod::Man nor pod2man. +%if 0%{?suse_version} +BuildRequires: perl +%else BuildRequires: perl-Pod-Html %endif diff --git a/xCAT-buildkit/xCAT-buildkit.spec b/xCAT-buildkit/xCAT-buildkit.spec index 4bc6d948b1..f9ce2778d2 100644 --- a/xCAT-buildkit/xCAT-buildkit.spec +++ b/xCAT-buildkit/xCAT-buildkit.spec @@ -12,8 +12,12 @@ Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} Prefix: /opt/xcat BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root -# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html -%if !0%{?suse_version} +# The pod converters are in perl-Pod-Html on EL and in the core perl package on +# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that +# ships neither Pod::Man nor pod2man. +%if 0%{?suse_version} +BuildRequires: perl +%else BuildRequires: perl-Pod-Html %endif diff --git a/xCAT-client/xCAT-client.spec b/xCAT-client/xCAT-client.spec index 2f6b71e288..aca7ac08a8 100644 --- a/xCAT-client/xCAT-client.spec +++ b/xCAT-client/xCAT-client.spec @@ -19,8 +19,12 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root %define s390x %(if [ "$s390x" = "1" ];then echo 1; else echo 0; fi) %define nots390x %(if [ "$s390x" = "1" ];then echo 0; else echo 1; fi) -# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html -%if !0%{?suse_version} +# The pod converters are in perl-Pod-Html on EL and in the core perl package on +# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that +# ships neither Pod::Man nor pod2man. +%if 0%{?suse_version} +BuildRequires: perl +%else BuildRequires: perl-Pod-Html %endif diff --git a/xCAT-test/xCAT-test.spec b/xCAT-test/xCAT-test.spec index 6c1d859820..b4a8d849f9 100644 --- a/xCAT-test/xCAT-test.spec +++ b/xCAT-test/xCAT-test.spec @@ -11,8 +11,12 @@ Vendor: IBM Corp. Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} Prefix: /opt/xcat BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root -# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html -%if !0%{?suse_version} +# The pod converters are in perl-Pod-Html on EL and in the core perl package on +# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that +# ships neither Pod::Man nor pod2man. +%if 0%{?suse_version} +BuildRequires: perl +%else BuildRequires: perl-Pod-Html %endif diff --git a/xCAT-vlan/xCAT-vlan.spec b/xCAT-vlan/xCAT-vlan.spec index 883f714d18..d621737f5a 100644 --- a/xCAT-vlan/xCAT-vlan.spec +++ b/xCAT-vlan/xCAT-vlan.spec @@ -11,8 +11,12 @@ Vendor: IBM Corp. Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} Prefix: /opt/xcat BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root -# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html -%if !0%{?suse_version} +# The pod converters are in perl-Pod-Html on EL and in the core perl package on +# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that +# ships neither Pod::Man nor pod2man. +%if 0%{?suse_version} +BuildRequires: perl +%else BuildRequires: perl-Pod-Html %endif 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 004/114] 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 005/114] 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 006/114] 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 007/114] 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 008/114] 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 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 009/114] 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 010/114] 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 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 011/114] 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 012/114] 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 013/114] 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 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 014/114] 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 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 015/114] 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 839117f9eff2712ccbcb5b15675790bd11c2d878 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:26:22 -0300 Subject: [PATCH 016/114] fix(xcattest): a [Table_*] value stops at its first colon or slash xcattest applies a conf's [Table_*] blocks itself, once, before the first case runs, so whatever table_attr returns is what reaches chtab. Its value class was ([\w\.\-]+), which stops at a colon or a slash and writes the truncated value with no warning: on a management node provisioning over IPv6, `net=2001:db8:176::/64` reached chtab as `net=2001`, and xcattest re-applied that junk row on every run. [Table_site] value= has the same hole, so site.master cannot be an IPv6 address either, and any table value holding a path or a comma-separated list loses everything after the first slash or colon. object_attr, beside it in the same module, already accepts ":,;/" -- which is why an [Object_node] ip= carries an IPv6 address and a [Table_networks] net= silently could not. table_attr now uses the same class. Both are faithful to what they replaced: upstream xcattest still matches tables with ([\w\.\-]+) at line 817 and objects with ([\w\.\-\+\ \/:]+) at line 854, and moving the pair into xCAT::Test::Conf is what made the asymmetry visible and testable. The class holds no whitespace and no '#', so a trailing inline comment is still excluded -- asserted, because that is the behaviour a wider class could have broken. xcattest_conf_table_value_class.t covers one line per kind of value a table holds. Seven of its 22 assertions fail without the fix, including the three IPv6 forms and the absolute path; xcattest_conf_object_attr.t stays green, which is the control that colons were never meant to be refused. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/lib/xCAT/Test/Conf.pm | 9 ++- .../unit/xcattest_conf_table_value_class.t | 64 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/unit/xcattest_conf_table_value_class.t diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm index ca56c42b73..a27ada92f7 100644 --- a/xCAT-test/lib/xCAT/Test/Conf.pm +++ b/xCAT-test/lib/xCAT/Test/Conf.pm @@ -59,7 +59,14 @@ sub object_attr { sub table_attr { my ($line) = @_; return () unless defined $line; - return ($1, $2) if $line =~ /(\w+)\s*=\s*([\w\.\-]+)/; + # The same value class as object_attr. A table value holds the same kinds of thing an object + # value does: an IPv6 prefix (2001:db8::/64), a path (/install), a comma-separated list of + # name servers. The narrower ([\w\.\-]+) this replaces stopped at the first colon or slash and + # wrote the truncated value, so `net=2001:db8:176::/64` reached chtab as `net=2001` and + # xcattest re-applied that row on every run. Nothing warned. + # + # The class holds no whitespace and no '#', so a trailing inline comment is still excluded. + return ($1, $2) if $line =~ /(\w+)\s*=\s*([:,;\w\.\-\/]+)/; return (); } diff --git a/xCAT-test/unit/xcattest_conf_table_value_class.t b/xCAT-test/unit/xcattest_conf_table_value_class.t new file mode 100644 index 0000000000..a1590085b9 --- /dev/null +++ b/xCAT-test/unit/xcattest_conf_table_value_class.t @@ -0,0 +1,64 @@ +#!/usr/bin/env perl +# A [Table_*] VALUE MAY CONTAIN A COLON OR A SLASH. table_attr DROPS THE REST OF IT. +# +# xcattest applies a conf's [Table_*] blocks itself, once, before the first case runs +# (setup_env_by_configure_file), so whatever table_attr returns is what reaches chtab. Its value +# class is ([\w\.\-]+) while object_attr, beside it in the same module, already allows ":,;/" -- +# so an [Object_node] ip= carries an IPv6 address and a [Table_networks] net= silently cannot. +# +# The narrow class is faithful to what it replaced: upstream xcattest still matches tables with +# ([\w\.\-]+) at line 817 and objects with ([\w\.\-\+\ \/:]+) at line 854. Moving the pair into +# xCAT::Test::Conf is what made the asymmetry visible and testable. +# +# Measured 2026-10-23 on a management node provisioning over IPv6: `net=2001:db8:176::/64` reached +# chtab as `net=2001`, and xcattest re-applied that junk row on every run. [Table_site] value= has +# the same hole, so site.master cannot be an IPv6 address either. Nothing warns: the line parses, +# the truncated value is written, and the case fails later for a reason that looks unrelated. +# +# The same hole swallows any path or time range a table value needs. +use strict; +use warnings; +use Test::More; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use xCAT::Test::Conf (); + +my $table = xCAT::Test::Conf->can('table_attr'); +ok($table, 'xCAT::Test::Conf provides table_attr') or die "nothing to test\n"; + +# One pair per thing a table value legitimately holds. The value is what must come back WHOLE. +my @cases = ( + ['net=2001:db8:176::/64', 'net', '2001:db8:176::/64', 'an IPv6 prefix'], + [' gateway=2001:db8:176::1', 'gateway', '2001:db8:176::1', 'an IPv6 address'], + ['value=fd00::1', 'value', 'fd00::1', 'a unique-local address'], + ['master=192.168.201.76', 'master', '192.168.201.76', 'an IPv4 address, unchanged'], + ['installdir=/install', 'installdir', '/install', 'an absolute path'], + ['nameservers=2001:db8::1,2001:db8::2', 'nameservers', '2001:db8::1,2001:db8::2', + 'a comma-separated list'], + ['domain=xcat76.lab', 'domain', 'xcat76.lab', 'a dotted name, unchanged'], + ['key=system', 'key', 'system', 'a bare word, unchanged'], +); +for my $c (@cases) { + my ($line, $attr, $value, $what) = @$c; + my ($got_attr, $got_value) = $table->($line); + is($got_attr, $attr, "$what: the attribute is $attr"); + is($got_value, $value, "$what: the value survives whole"); +} + +# A line with no assignment is still the empty list, and an inline comment is still excluded -- +# the class holds no whitespace and no '#', so widening it does not start swallowing comments. +is_deeply([ $table->('# a comment') ], [], 'a comment line yields no assignment'); +is_deeply([ $table->('[Table_site]') ], [], 'a section header yields no assignment'); +my ($a, $v) = $table->('value=fd00::1 # the management address'); +is($v, 'fd00::1', 'an inline comment is not part of the value'); + +# CONTROL: object_attr already accepts these, which is why the asymmetry is the defect rather +# than the design. Without this a reader cannot tell whether colons were meant to be refused. +my $object = xCAT::Test::Conf->can('object_attr'); +ok($object, 'and object_attr, for comparison'); +if ($object) { + my (undef, $ov) = $object->('ip=2001:db8:176::20'); + is($ov, '2001:db8:176::20', 'control: an [Object_*] value already keeps an IPv6 address'); +} + +done_testing; 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 017/114] 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 018/114] 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 019/114] 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. From 19242f88c210c9da6c5d6ca042b1cb2ec2bcf8d9 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, 29 Oct 2026 15:12:56 -0300 Subject: [PATCH 020/114] fix(ipmi): report device ID and SDR errors against the node When Get Device ID or a step of the SDR read failed, the plugin reported the error through sendoutput. Seven of these calls passed an array reference, which sendoutput takes as its return code, so the error was dropped. The other five named the node BADCODE. A refused SDR reservation also went on to read records with no reservation ID. Report these errors with sendmsg against the node, as the rest of the plugin does, and stop after a refused reservation. --- xCAT-server/lib/xcat/plugins/ipmi.pm | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index e683d872e9..9081e06921 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -7653,12 +7653,12 @@ sub initsdr_withrepinfo { if ($sessdata->{sdr_info}->{version} != 0x51) { - sendoutput(1, "SDR version unsupported."); + xCAT::SvrUtils::sendmsg([ 1, "SDR version unsupported." ], $callback, $sessdata->{node}, %allerrornodes); return (1); #bail, do not try to continue } if ($sessdata->{sdr_info}->{resv_sdr} != 1) { - sendoutput(1, "SDR reservation unsupported."); + xCAT::SvrUtils::sendmsg([ 1, "SDR reservation unsupported." ], $callback, $sessdata->{node}, %allerrornodes); return 1; } @@ -7695,7 +7695,7 @@ sub start_sdr_record { my $rsp = shift; my $sessdata = shift; if ($rsp->{error}) { - sendoutput(1, $rsp->{error}); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } my $resv_id_ls = shift @{ $sessdata->{sdr_fetch_args} }; @@ -7709,7 +7709,7 @@ sub start_sdr_record { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput(1, $text); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; } $sessdata->{sdr_nrid_ls} = $returnd[1]; @@ -7763,7 +7763,7 @@ sub add_sdr_data { my $numbytes = $sessdata->{sdr_fetch_args}->[5]; my $offset = $sessdata->{sdr_offset}; #shorten typing a little if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; #give up } my @returnd = ($rsp->{code}, @{ $rsp->{data} }); @@ -7773,7 +7773,7 @@ sub add_sdr_data { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput([ 1, $text ]); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; #abort the whole mess } push @{ $sessdata->{sdr_data} }, @returnd[ 3 .. @returnd - 1 ]; @@ -7996,7 +7996,7 @@ sub gotdevid { my $text; if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } else { @@ -8007,7 +8007,7 @@ sub gotdevid { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput([ 1, $text ]); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; } } @@ -8093,7 +8093,7 @@ sub got_sdr_rep_info { my $sessdata = shift; if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } else { @@ -8104,7 +8104,7 @@ sub got_sdr_rep_info { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput(1, $text); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; } } @@ -8119,7 +8119,7 @@ sub reserved_sdr_repo { my $rsp = shift; my $sessdata = shift; if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } else { @@ -8130,7 +8130,8 @@ sub reserved_sdr_repo { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput([ 1, $text ]); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); + return; } } my @returnd = @{ $rsp->{data} }; From 0c3640c74f6fa4a73bc77970fd74f7f612639476 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, 29 Oct 2026 15:13:04 -0300 Subject: [PATCH 021/114] test(ipmi): cover device ID and SDR errors against the node Each step of the device ID and SDR read reports a timeout as an error of the node and stops, and a refused SDR reservation sends no Get SDR request. --- xCAT-test/unit/ipmi_sdr_errors.t | 131 +++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 xCAT-test/unit/ipmi_sdr_errors.t diff --git a/xCAT-test/unit/ipmi_sdr_errors.t b/xCAT-test/unit/ipmi_sdr_errors.t new file mode 100644 index 0000000000..384f8e00d1 --- /dev/null +++ b/xCAT-test/unit/ipmi_sdr_errors.t @@ -0,0 +1,131 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings) +no warnings qw(once redefine); + +use File::Spec; +use FindBin; +use Test::More; + +# An IPMI command reads the device ID and then the SDR repository before it can answer. +# A failure in that chain must reach the administrator as an error of the node and must end +# the chain, instead of being dropped or reported under no node. + +BEGIN { + for my $module (qw( + xCAT::GlobalDef xCAT_monitoring::monitorctrl xCAT::IPMI + xCAT::BMCUtils xCAT::PasswordUtils xCAT::Utils xCAT::TableUtils + xCAT::IMMUtils xCAT::ServiceNodeUtils xCAT::NetworkUtils xCAT::Usage + xCAT::data::ibmhwtypes xCAT::data::ibmleds + xCAT::data::ipmigenericevents xCAT::data::ipmisensorevents + IBM::EnergyManager + )) { + (my $file = $module) =~ s{::}{/}g; + $INC{"$file.pm"} = __FILE__; + no strict 'refs'; + *{"${module}::import"} = sub { }; + } + + package xCAT::SvrUtils; + our @messages; + sub import { } + sub sendmsg { push @messages, { text => $_[0], node => $_[2] }; } + $INC{'xCAT/SvrUtils.pm'} = __FILE__; + + package xCAT::SPD; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::decode_spd"} = sub { return; }; + } + $INC{'xCAT/SPD.pm'} = __FILE__; + + package File::Path; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::mkpath"} = sub { return; }; + } + $INC{'File/Path.pm'} = __FILE__; + + package Thread; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::yield"} = sub { return; }; + } + $INC{'Thread.pm'} = __FILE__; + + package LWP; + our $VERSION = 5.64; + sub import { } + $INC{'LWP.pm'} = __FILE__; + + package HTTP::Request::Common; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::GET"} = sub { return; }; + *{"${caller}::POST"} = sub { return; }; + } + $INC{'HTTP/Request/Common.pm'} = __FILE__; + + package main; + *CORE::GLOBAL::chmod = sub (@) { return 1; }; +} + +package FakeSession; +sub new { return bless { calls => [] }, shift; } +sub subcmd { my ($self, %args) = @_; push @{ $self->{calls} }, \%args; return; } + +package main; + +my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..'); +$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server'); +my $plugin = File::Spec->catfile($repo_root, qw(xCAT-server lib xcat plugins ipmi.pm)); +do $plugin or die $@ || "Unable to load $plugin: $!"; + +# Run one callback of the chain with a reply and return what it reported and requested. +sub run_step { + my ($step, $rsp, %state) = @_; + my $sessdata = { node => 'node01', ipmisession => FakeSession->new(), %state }; + local @xCAT::SvrUtils::messages = (); + my $ok = eval { $step->($rsp, $sessdata); 1 }; + return { + died => $ok ? '' : ($@ || 'died'), + messages => [@xCAT::SvrUtils::messages], + requests => $sessdata->{ipmisession}->{calls}, + }; +} + +sub assert_node_error { + my ($result, $text, $case) = @_; + is($result->{died}, '', "$case: the callback returns"); + is(scalar @{ $result->{messages} }, 1, "$case: one message"); + my $message = $result->{messages}->[0] || {}; + is($message->{node}, 'node01', "$case: the message names the node"); + is_deeply($message->{text}, [ 1, $text ], "$case: the message is an error with the reply text"); + is(scalar @{ $result->{requests} }, 0, "$case: the chain stops"); +} + +my $invalid_command = { code => 0xc1, data => [] }; +my $timeout = { error => 'timeout' }; + +for my $step ( + [ 'Get Device ID', \&xCAT_plugin::ipmi::gotdevid ], + [ 'Get SDR Repository Info', \&xCAT_plugin::ipmi::got_sdr_rep_info ], + [ 'Reserve SDR Repository', \&xCAT_plugin::ipmi::reserved_sdr_repo ], + [ 'the first Get SDR', \&xCAT_plugin::ipmi::start_sdr_record ], + [ 'a following Get SDR', \&xCAT_plugin::ipmi::add_sdr_data ], +) { + my ($name, $callback) = @$step; + assert_node_error(run_step($callback, $timeout), 'timeout', "$name times out"); +} + +my $result = run_step(\&xCAT_plugin::ipmi::reserved_sdr_repo, $invalid_command, + sdr_info => { resv_sdr => 1 }); +assert_node_error($result, "Invalid or unsupported command", "a refused SDR reservation"); + +done_testing(); From 7d8658e8487427d8c22f6ac35e4e31fafcb8b587 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, 29 Oct 2026 15:26:53 -0300 Subject: [PATCH 022/114] test(netboot): check the riscv64 default drivers by name The EL riscv64 case compared the whole default driver list, so a driver added to the list failed it. Check that each expected driver is in the list. --- xCAT-test/unit/el_riscv64_install_paths.t | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xCAT-test/unit/el_riscv64_install_paths.t b/xCAT-test/unit/el_riscv64_install_paths.t index f7d7d7c453..84475c0f5a 100644 --- a/xCAT-test/unit/el_riscv64_install_paths.t +++ b/xCAT-test/unit/el_riscv64_install_paths.t @@ -88,11 +88,10 @@ ok( 'POWER media retain their separate architecture route', ); -is_deeply( - [ imgutils::default_net_drivers( 'rh', 'riscv64' ) ], - [qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net)], - 'riscv64 diskless images receive the intended default network drivers', -); +my %riscv64_drivers = map { $_ => 1 } imgutils::default_net_drivers( 'rh', 'riscv64' ); +for my $driver (qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net)) { + ok( $riscv64_drivers{$driver}, "riscv64 diskless images receive the $driver network driver" ); +} is_deeply( [ imgutils::resolver_library_paths('riscv64') ], [ 'lib64/libnss_dns.so.2', 'lib64/libresolv.so.2' ], From 9ed498e50f5fa7cdf124b90a1ab404f84bab6956 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, 29 Oct 2026 15:34:04 -0300 Subject: [PATCH 023/114] fix(netboot): give riscv64 images the Intel 700 and 800 series drivers The riscv64 default driver lists had no i40e or ice, so the initrd of a diskless image could not bring up the network of a riscv64 server with an Intel X710 or E810 adapter. Add both drivers to the EL and Ubuntu rows. genimage pulls their module dependencies from modules.dep. --- xCAT-server/share/xcat/netboot/imgutils/imgutils.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9cc0b35c7b..c3a85029cd 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -380,7 +380,7 @@ sub default_net_drivers { x86 => [qw(tg3 bnx2 bnx2x e1000 e1000e igb mlx_en mlx5_core virtio_net be2net)], x86_64 => [qw(tg3 bnx2 bnx2x e1000 e1000e igb mlx_en mlx5_core virtio_net be2net)], aarch64 => [qw(tg3 bnx2 bnx2x e1000e igb mlx_en mlx5_core virtio_net)], - riscv64 => [qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net)], + riscv64 => [qw(e1000 e1000e igb ixgbe i40e ice r8169 tg3 bnx2x mlx5_core virtio_net)], ppc64 => [qw(e1000 e1000e igb ibmveth ehea)], s390x => [qw(qdio ccwgroup)], }, @@ -395,7 +395,7 @@ sub default_net_drivers { x86_64 => [qw(tg3 bnx2 bnx2x e1000 e1000e igb mlx_en mlx5_core virtio_net overlay)], ppc64el => [qw(tg3 bnx2 bnx2x e1000 e1000e igb ibmveth ehea mlx_en mlx4_en mlx5_core virtio_net overlay)], ppc64 => [qw(e1000 e1000e igb ibmveth ehea)], - riscv64 => [qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net overlay)], + riscv64 => [qw(e1000 e1000e igb ixgbe i40e ice r8169 tg3 bnx2x mlx5_core virtio_net overlay)], s390x => [qw(qdio ccwgroup)], }, ); From 9f8f3a0a47af5706ccce5b396add9b261fa39007 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, 29 Oct 2026 15:35:09 -0300 Subject: [PATCH 024/114] test(netboot): cover the Intel 700 and 800 series riscv64 drivers The EL and Ubuntu riscv64 default driver lists carry i40e and ice, and the Ubuntu list keeps ixgbe. --- xCAT-test/unit/el_riscv64_install_paths.t | 2 +- xCAT-test/unit/ubuntu_riscv64_net_drivers.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-test/unit/el_riscv64_install_paths.t b/xCAT-test/unit/el_riscv64_install_paths.t index 84475c0f5a..91ef0331ee 100644 --- a/xCAT-test/unit/el_riscv64_install_paths.t +++ b/xCAT-test/unit/el_riscv64_install_paths.t @@ -89,7 +89,7 @@ ok( ); my %riscv64_drivers = map { $_ => 1 } imgutils::default_net_drivers( 'rh', 'riscv64' ); -for my $driver (qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net)) { +for my $driver (qw(e1000 e1000e igb ixgbe i40e ice r8169 tg3 bnx2x mlx5_core virtio_net)) { ok( $riscv64_drivers{$driver}, "riscv64 diskless images receive the $driver network driver" ); } is_deeply( diff --git a/xCAT-test/unit/ubuntu_riscv64_net_drivers.t b/xCAT-test/unit/ubuntu_riscv64_net_drivers.t index 6e98c33a2e..3a79dbc83f 100644 --- a/xCAT-test/unit/ubuntu_riscv64_net_drivers.t +++ b/xCAT-test/unit/ubuntu_riscv64_net_drivers.t @@ -18,7 +18,7 @@ require imgutils; my @riscv = imgutils::default_net_drivers( 'ubuntu', 'riscv64' ); ok( scalar @riscv, 'a riscv64 Ubuntu image is given network drivers' ); -for my $driver (qw(virtio_net e1000 e1000e igb r8169 tg3 mlx5_core)) { +for my $driver (qw(virtio_net e1000 e1000e igb ixgbe i40e ice r8169 tg3 mlx5_core)) { ok( scalar( grep { $_ eq $driver } @riscv ), "the list carries $driver" ); } From c6dcdb9b572387621d87de7e1c317bc45344be1b 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, 29 Oct 2026 15:15:31 -0300 Subject: [PATCH 025/114] fix(ipmi): read the SDR when the BMC grants an unadvertised reservation rinv, rvitals and reventlog stopped with "SDR reservation unsupported." when Get SDR Repository Info did not set the reservation bit. An OpenBMC build clears that bit but grants Reserve SDR Repository, so these commands failed on a server that ipmitool reads. Send Reserve SDR Repository in every case. When the bit is clear and the BMC rejects the command as invalid, the error stays "SDR reservation unsupported." Other refusals report their completion code. --- xCAT-server/lib/xcat/plugins/ipmi.pm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index 9081e06921..d3b450507c 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -7657,11 +7657,7 @@ sub initsdr_withrepinfo { return (1); #bail, do not try to continue } - if ($sessdata->{sdr_info}->{resv_sdr} != 1) { - xCAT::SvrUtils::sendmsg([ 1, "SDR reservation unsupported." ], $callback, $sessdata->{node}, %allerrornodes); - return 1; - } - + # Some BMCs grant a reservation that Get SDR Repository Info does not advertise. $sessdata->{ipmisession}->subcmd(netfn => 0x0a, command => 0x22, data => [], callback => \&reserved_sdr_repo, callback_args => $sessdata); } @@ -8127,7 +8123,9 @@ sub reserved_sdr_repo { if ($code != 0x00) { my $text = $codes{$code}; - if (!$text) { + if ($code == 0xc1 && !$sessdata->{sdr_info}->{resv_sdr}) { + $text = "SDR reservation unsupported."; + } elsif (!$text) { $text = sprintf("unknown response %02x", $code); } xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); From fd3f1889beb8232d8d87860f4d74b73addd6fc24 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, 29 Oct 2026 15:16:33 -0300 Subject: [PATCH 026/114] test(ipmi): cover an SDR reservation that is not advertised Replay the Get SDR Repository Info reply of an OpenBMC build that clears the reservation bit. The read asks for the reservation and uses the ID it gets. An invalid command refusal still reports "SDR reservation unsupported." against the node, a busy or privilege refusal reports its completion code, and a BMC that sets the bit is asked as before. --- xCAT-test/unit/ipmi_sdr_reservation.t | 175 ++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 xCAT-test/unit/ipmi_sdr_reservation.t diff --git a/xCAT-test/unit/ipmi_sdr_reservation.t b/xCAT-test/unit/ipmi_sdr_reservation.t new file mode 100644 index 0000000000..df10162695 --- /dev/null +++ b/xCAT-test/unit/ipmi_sdr_reservation.t @@ -0,0 +1,175 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings) +no warnings qw(once redefine); + +use File::Spec; +use FindBin; +use Test::More; + +# Get SDR Repository Info can leave the reservation bit clear on a BMC that grants Reserve +# SDR Repository. The SDR read must still ask for the reservation and use it. + +BEGIN { + for my $module (qw( + xCAT::GlobalDef xCAT_monitoring::monitorctrl xCAT::IPMI + xCAT::BMCUtils xCAT::PasswordUtils xCAT::Utils xCAT::TableUtils + xCAT::IMMUtils xCAT::ServiceNodeUtils xCAT::NetworkUtils xCAT::Usage + xCAT::data::ibmhwtypes xCAT::data::ibmleds + xCAT::data::ipmigenericevents xCAT::data::ipmisensorevents + IBM::EnergyManager + )) { + (my $file = $module) =~ s{::}{/}g; + $INC{"$file.pm"} = __FILE__; + no strict 'refs'; + *{"${module}::import"} = sub { }; + } + + package xCAT::SvrUtils; + our @messages; + sub import { } + sub sendmsg { push @messages, { text => $_[0], node => $_[2] }; } + $INC{'xCAT/SvrUtils.pm'} = __FILE__; + + package xCAT::SPD; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::decode_spd"} = sub { return; }; + } + $INC{'xCAT/SPD.pm'} = __FILE__; + + package File::Path; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::mkpath"} = sub { return; }; + } + $INC{'File/Path.pm'} = __FILE__; + + package Thread; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::yield"} = sub { return; }; + } + $INC{'Thread.pm'} = __FILE__; + + package LWP; + our $VERSION = 5.64; + sub import { } + $INC{'LWP.pm'} = __FILE__; + + package HTTP::Request::Common; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::GET"} = sub { return; }; + *{"${caller}::POST"} = sub { return; }; + } + $INC{'HTTP/Request/Common.pm'} = __FILE__; + + package main; + *CORE::GLOBAL::chmod = sub (@) { return 1; }; +} + +package FakeSession; +sub new { return bless { calls => [] }, shift; } +sub subcmd { my ($self, %args) = @_; push @{ $self->{calls} }, \%args; return; } + +package main; + +my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..'); +$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server'); +my $plugin = File::Spec->catfile($repo_root, qw(xCAT-server lib xcat plugins ipmi.pm)); +do $plugin or die $@ || "Unable to load $plugin: $!"; + +# A device identity that no SDR cache file holds, so the SDR is read from the BMC. +sub new_sessdata { + return { + node => 'node01', + ipmisession => FakeSession->new(), + mfg_id => 0xfffe, + prod_id => 0xfffe, + device_id => 0xfe, + device_rev => 0, + firmware_rev1 => 0, + firmware_rev2 => 0, + }; +} + +# The Get SDR Repository Info reply of an OpenBMC that grants reservations, with the +# operation support byte last. +sub repository_info { + my ($operation_support) = @_; + return { code => 0, data => [ 0x51, 0x2b, 0x00, 0xff, 0xff, (0) x 8, $operation_support ] }; +} + +sub requests { return $_[0]->{ipmisession}->{calls}; } + +subtest 'a BMC that does not advertise the reservation is asked for one' => sub { + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata); + is_deeply(\@xCAT::SvrUtils::messages, [], 'no error is reported'); + is(scalar @{ requests($sessdata) }, 1, 'one request follows'); + my $request = requests($sessdata)->[0] || {}; + is($request->{netfn}, 0x0a, 'the request is a storage command'); + is($request->{command}, 0x22, 'the request is Reserve SDR Repository'); + + ok($request->{callback}, "the request has a reply handler") or return; + $sessdata->{ipmisession}->{calls} = []; + $request->{callback}->({ code => 0, data => [ 0x01, 0x00 ] }, $request->{callback_args}); + is_deeply(\@xCAT::SvrUtils::messages, [], 'the granted reservation reports no error'); + my $fetch = requests($sessdata)->[0] || {}; + is($fetch->{command}, 0x23, 'Get SDR follows the reservation'); + is_deeply([ @{ $fetch->{data} || [] }[ 0, 1 ] ], [ 0x01, 0x00 ], + 'Get SDR carries the granted reservation ID'); +}; + +subtest 'a refused reservation that was not advertised is reported as unsupported' => sub { + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata); + my $request = requests($sessdata)->[0] || {}; + ok($request->{callback}, "a reservation is requested") or return; + $sessdata->{ipmisession}->{calls} = []; + $request->{callback}->({ code => 0xc1, data => [] }, $request->{callback_args}); + is(scalar @xCAT::SvrUtils::messages, 1, 'one message'); + my $message = $xCAT::SvrUtils::messages[0] || {}; + is($message->{node}, 'node01', 'the message names the node'); + is_deeply($message->{text}, [ 1, 'SDR reservation unsupported.' ], 'the message keeps its text'); + is(scalar @{ requests($sessdata) }, 0, 'no Get SDR request follows'); +}; + +subtest 'other refusals of a reservation that was not advertised keep their reason' => sub { + for my $refusal ( + [ 0xc0, 'Node busy, command could not be processed' ], + [ 0xd4, 'Insufficient privilege level' ], + ) { + my ($code, $reason) = @$refusal; + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata); + my $request = requests($sessdata)->[0] || {}; + ok($request->{callback}, "a reservation is requested") or next; + $sessdata->{ipmisession}->{calls} = []; + $request->{callback}->({ code => $code, data => [] }, $request->{callback_args}); + is_deeply([ map { $_->{text} } @xCAT::SvrUtils::messages ], [ [ 1, $reason ] ], + sprintf('completion code %02x is reported as itself', $code)); + is(scalar @{ requests($sessdata) }, 0, 'no Get SDR request follows'); + } +}; + +subtest 'a BMC that advertises the reservation is still asked for one' => sub { + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x02), $sessdata); + is_deeply(\@xCAT::SvrUtils::messages, [], 'no error is reported'); + my $request = requests($sessdata)->[0] || {}; + is($request->{command}, 0x22, 'the request is Reserve SDR Repository'); +}; + +done_testing(); From f937b60a71c33519fd02c796dff478ac94246a43 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, 29 Oct 2026 14:56:20 -0300 Subject: [PATCH 027/114] fix(go-xcat): install the apt key without apt-key apt 3, which Ubuntu 26.04 ships, has no apt-key, so go-xcat stopped with "import xcat apt key failed" before it configured a repository. On Ubuntu 18.04 to 24.04, apt-key also fails when gnupg is not installed, and go-xcat does not install it. Decode the armored key with base64 and install it as the binary keyring /etc/apt/trusted.gpg.d/xcat.gpg. Every apt release reads that file, while apt 1.0 and 1.2 on Ubuntu 14.04 and 16.04 ignore an armored key there. The key stays trusted for all repositories, as it was with apt-key. A complete uninstall removes the key with the repository files. As with apt-key, a download that holds no public key stops go-xcat and leaves the installed key in place. go-xcat refuses a download whose armored blocks do not all end with their END line, as a truncated download does. It accepts the keyring only when it starts with a public key packet, the check apt applies to a binary keyring. --- xCAT-server/share/xcat/tools/go-xcat | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 8ef13fd282..91adfed726 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -185,6 +185,7 @@ function version() GO_XCAT_DEFAULT_BASE_URL="http://xcat.org/files/xcat/repos" GO_XCAT_DEFAULT_INSTALL_PATH="/install/xcat" +GO_XCAT_APT_KEY_FILE="/etc/apt/trusted.gpg.d/xcat.gpg" # The package list of xcat-core GO_XCAT_CORE_PACKAGE_LIST=() @@ -1646,7 +1647,17 @@ function add_xcat_core_repo_apt() local tmp="${TMP_DIR}/tmp_xcat.key" download_file "${url}" "${tmp}" warn_if_bad "$?" "download xcat apt key failed" || return 1 - apt-key add "${tmp}" + # apt 3 has no apt-key, and apt before 1.4 reads only binary keyrings, which start with 0x98, 0x99 or 0xc6. + # A truncated download has a block without its END line, so it is refused. + awk '/^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ { o = h = 1; b = 0; next } + /^-----END PGP PUBLIC KEY BLOCK-----$/ { if (!o) bad = 1; o = h = b = 0; n++; next } + h && /^$/ { h = 0; b = 1; next } + b && /^=/ { b = 0; next } + b { print } + END { exit (bad || o || !n) }' "${tmp}" >"${tmp}.b64" && + base64 -d "${tmp}.b64" >"${tmp}.gpg" 2>/dev/null && + od -An -tx1 -N1 "${tmp}.gpg" | grep -qE '^ (98|99|c6)$' && + install -D -m 0644 "${tmp}.gpg" "${GO_XCAT_APT_KEY_FILE}" warn_if_bad "$?" "import xcat apt key failed" || return 1 case "${ver}" in "devel") @@ -2194,6 +2205,7 @@ function trash_xcat() rm -rf /etc/xcat rm -rf /etc/xcatdockerca rm -f /etc/apt/sources.list.d/xcat-{core,dep}.list + rm -f "${GO_XCAT_APT_KEY_FILE}" rm -f /etc/yum.repos.d/xCAT-{core,dep,dep-common}.repo{,.nouse} rm -f /etc/yum.repos.d/xcat-{core,dep,dep-common}.repo rm -f /etc/zypp/repos.d/xCAT-{core,dep,dep-common}.repo{,.nouse} From 7bebb608b72d4f75f8fe8e6142acd19d190a1d97 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, 29 Oct 2026 15:11:25 -0300 Subject: [PATCH 028/114] test(go-xcat): cover the apt key without apt-key The default xcat-core repository installs the decoded key blocks as one binary keyring in trusted.gpg.d while apt-key fails as it does on apt 3. An empty or HTML download, a block truncated after a valid base64 prefix, a body that is not base64 and a block without a public key stop go-xcat and keep the installed key. A complete uninstall removes that key and keeps the other keys. --- xCAT-test/bats/fixtures/go-xcat-apt.sh | 20 ++++++ xCAT-test/bats/go_xcat_apt_key.bats | 89 ++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 xCAT-test/bats/fixtures/go-xcat-apt.sh create mode 100644 xCAT-test/bats/go_xcat_apt_key.bats diff --git a/xCAT-test/bats/fixtures/go-xcat-apt.sh b/xCAT-test/bats/fixtures/go-xcat-apt.sh new file mode 100644 index 0000000000..5a9e3b676d --- /dev/null +++ b/xCAT-test/bats/fixtures/go-xcat-apt.sh @@ -0,0 +1,20 @@ +#!/bin/bash +PATH="" +source /tmp/go-xcat || exit 70 +TMP_DIR=/tmp/fixture +GO_XCAT_DEFAULT_BASE_URL=https://repo.example.invalid + +# apt 3 has no apt-key: a call to it is the defect under test. +apt-key() { printf '%s\n' "$*" >> /tmp/fixture/apt-key.log; return 127; } +dpkg() { [ "$1" = --print-architecture ] && echo riscv64; } +download_file() +{ + printf '%s\n' "$1" >> /tmp/fixture/download.log + cp /tmp/fixture/key.asc "$2" +} + +case "$1" in +add) add_xcat_core_repo_apt "" latest ;; +trash) trash_xcat ;; +*) exit 64 ;; +esac diff --git a/xCAT-test/bats/go_xcat_apt_key.bats b/xCAT-test/bats/go_xcat_apt_key.bats new file mode 100644 index 0000000000..e3ea63f138 --- /dev/null +++ b/xCAT-test/bats/go_xcat_apt_key.bats @@ -0,0 +1,89 @@ +#!/usr/bin/env bats +# +# go-xcat trusts the xcat.org apt key without apt-key, which apt 3 does not ship. It installs +# the key as a binary keyring, which apt before 1.4 needs, and a complete uninstall removes it +# with the repository files. + +load 'helpers/go_xcat' + +setup() +{ + [ "$(uname -s)" = Linux ] || skip 'repository checks require Linux namespaces' + command -v bwrap >/dev/null || skip 'bwrap is required' + go_xcat_require_source + [ -n "$BATS_TEST_TMPDIR" ] || return 1 + fixture="$BATS_TEST_TMPDIR/apt" + mkdir -p "$fixture/etc/apt/sources.list.d" + printf 'DISTRIB_CODENAME=resolute\n' >"$fixture/etc/lsb-release" + # Two armored blocks, as xcat.org publishes, each holding a public key packet (0x99). + printf '\231\000\002ab\231\000\002cd' >"$fixture/keyring.gpg" + { + armored_block "$(printf '\231\000\002ab' | base64)" 'Version: GnuPG v1' + armored_block "$(printf '\231\000\002cd' | base64)" + } >"$fixture/key.asc" +} + +# Print an armored public key block with the base64 body $1 and the optional header $2. +armored_block() +{ + printf -- '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' + [ -z "$2" ] || printf '%s\n' "$2" + printf '\n%s\n=AAAA\n-----END PGP PUBLIC KEY BLOCK-----\n' "$1" +} + +run_go_xcat_apt() +{ + # Debian reaches awk through /etc/alternatives, which the fixture /etc hides. + local -a alternatives=() + [ -d /etc/alternatives ] && alternatives=(--ro-bind /etc/alternatives /etc/alternatives) + bwrap --die-with-parent --unshare-net --ro-bind / / --dev /dev --proc /proc \ + --tmpfs /tmp --ro-bind "$BATS_TEST_DIRNAME/../.." /tmp/source \ + --ro-bind "$GO_XCAT_SOURCE" /tmp/go-xcat \ + --bind "$fixture" /tmp/fixture --bind "$fixture/etc" /etc "${alternatives[@]}" \ + --chdir /tmp/fixture \ + bash /tmp/source/xCAT-test/bats/fixtures/go-xcat-apt.sh "$@" +} + +@test "the default xcat-core repository trusts the xCAT key as a binary keyring" { + run run_go_xcat_apt add + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + [ ! -e "$fixture/apt-key.log" ] + [ "$(cat "$fixture/download.log")" = 'https://repo.example.invalid/apt/apt.key' ] + key="$fixture/etc/apt/trusted.gpg.d/xcat.gpg" + cmp "$fixture/keyring.gpg" "$key" + [ "$(stat -c %a "$key")" = 644 ] + [ "$(cat "$fixture/etc/apt/sources.list.d/xcat-core.list")" = \ + 'deb [arch=riscv64] https://repo.example.invalid/apt/latest/xcat-core resolute main' ] +} + +@test "a download that holds no public key keeps the installed key and stops" { + mkdir -p "$fixture/etc/apt/trusted.gpg.d" + key="$fixture/etc/apt/trusted.gpg.d/xcat.gpg" + local -a downloads=( + '' + 'Not Found' + '-----BEGIN PGP PUBLIC KEY BLOCK-----' + "$(armored_block '!!!!')" + "$(armored_block "$(printf '\264\001a' | base64)")" + "$(printf -- '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQEN')" + "$(head -n 9 "$fixture/key.asc")" + ) + for download in "${downloads[@]}"; do + cp "$fixture/keyring.gpg" "$key" + printf '%s\n' "$download" >"$fixture/key.asc" + run run_go_xcat_apt add + [ "$status" -ne 0 ] || { printf 'accepted %s\n' "$download"; return 1; } + grep -Fq 'import xcat apt key failed' <<<"$output" + cmp "$fixture/keyring.gpg" "$key" + [ ! -e "$fixture/etc/apt/sources.list.d/xcat-core.list" ] + done +} + +@test "a complete uninstall removes the xCAT key and keeps other keys" { + mkdir -p "$fixture/etc/apt/trusted.gpg.d" + cp "$fixture/keyring.gpg" "$fixture/etc/apt/trusted.gpg.d/xcat.gpg" + cp "$fixture/keyring.gpg" "$fixture/etc/apt/trusted.gpg.d/other.gpg" + run run_go_xcat_apt trash + [ ! -e "$fixture/etc/apt/trusted.gpg.d/xcat.gpg" ] + [ -e "$fixture/etc/apt/trusted.gpg.d/other.gpg" ] +} From 756a2a6358b3b02c34ed18ac52246cfba14c225c 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, 29 Oct 2026 15:23:43 -0300 Subject: [PATCH 029/114] test(go-xcat): answer apt-cache policy in the activation sandbox The apt-cache double printed nothing, so a go-xcat that asks apt which packages have a candidate would find none. Report a candidate for every package. go-xcat today reads that answer only for its package listing. --- xCAT-test/bats/go_xcat_activation.bats | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xCAT-test/bats/go_xcat_activation.bats b/xCAT-test/bats/go_xcat_activation.bats index 22621e168b..a86aeefef2 100644 --- a/xCAT-test/bats/go_xcat_activation.bats +++ b/xCAT-test/bats/go_xcat_activation.bats @@ -33,7 +33,14 @@ SH #!/bin/sh if grep -Fxq "$3" /run/fixture/installed; then printf 'install ok installed'; else exit 1; fi SH - printf '#!/bin/sh\nexit 0\n' >"$fixture/tools/apt-cache" + cat >"$fixture/tools/apt-cache" <<'SH' +#!/bin/sh +[ "$1" = policy ] || exit 0 +shift +for package do + printf '%s:\n Installed: (none)\n Candidate: 1\n' "$package" +done +SH printf '#!/bin/sh\nexit 22\n' >"$fixture/bin/curl" chmod +x "$fixture/bin/curl" "$fixture/tools/"* : >"$fixture/installed" From 15f208ad0c3b4d46b52f46db9b0e6e4dbabf859c 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, 29 Oct 2026 15:18:46 -0300 Subject: [PATCH 030/114] fix(go-xcat): skip packages the apt repositories do not provide On apt, go-xcat handed its whole list to one apt-get install, so a package the repositories lack aborted the install. ipxe-xcat is in the install list but not in the latest apt repositories, and no riscv64 apt repository has xcat-genesis-openembedded-riscv64. Install the packages that have a candidate and warn about each one that has none, as dnf --setopt=strict=0 already does on EL. A missing xcat metapackage still stops the install, because it depends on every package a management node needs. A failed apt-cache policy query also stops it, so a broken cache is not taken for missing packages. The query runs in the C locale, because a translated apt prints no "Candidate:" label. --- xCAT-server/share/xcat/tools/go-xcat | 29 +++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 91adfed726..f088f0cad5 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -950,6 +950,9 @@ function check_repo_version_apt() type apt-cache >/dev/null 2>&1 || return 255 local name="" local ver="" + local policy="" + local rc=0 + policy="$(apt-cache policy "$@" 2>/dev/null)" || rc="$?" while read -r name ver do if [[ "${name}" =~ ^[a-z] ]] @@ -966,13 +969,13 @@ function check_repo_version_apt() echo "$ver" shift fi - done < <(apt-cache policy "$@" 2>/dev/null) + done <<<"${policy}" while [[ -n "$1" ]] do echo "(not found)" shift done - return 0 + return "${rc}" } function check_repo_version() @@ -1989,7 +1992,27 @@ function install_packages_apt() type apt-get >/dev/null 2>&1 || return 255 local -a yes=() [[ "$1" = "-y" ]] && yes=("-y") && shift - apt-get --allow-unauthenticated install "${yes[@]}" "$@" + local -a available=() + local package="" ver="" versions="" + versions="$(LC_ALL=C check_repo_version_apt "$@")" + warn_if_bad "$?" "query apt package candidates failed" || return 1 + # As with dnf --setopt=strict=0, a package the repositories lack must not stop the install. + for package in "$@" + do + read -r ver + case "${ver}" in + "(none)"|"(not found)") + # The xcat metapackage depends on every package a management node needs. + [[ "${package}" = "xcat" ]] && + { warn_if_bad 1 "xcat: the repositories do not provide it"; return 1; } + warn_if_bad 1 "${package}: the repositories do not provide it, skipped" + ;; + *) + available+=("${package}") + ;; + esac + done <<<"${versions}" + apt-get --allow-unauthenticated install "${yes[@]}" "${available[@]}" } function install_packages() From b0c02900b76ab7b8ee0c706fb25e0e68fcb106db 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, 29 Oct 2026 15:24:56 -0300 Subject: [PATCH 031/114] test(go-xcat): cover apt packages the repositories do not provide An unknown package and a package with no candidate are skipped with a warning while the others install, and a translated apt still installs the packages that have a candidate. A missing xcat metapackage or a failed apt-cache policy query stops the install before apt-get runs. --- xCAT-test/bats/go_xcat_apt_install.bats | 79 +++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 xCAT-test/bats/go_xcat_apt_install.bats diff --git a/xCAT-test/bats/go_xcat_apt_install.bats b/xCAT-test/bats/go_xcat_apt_install.bats new file mode 100644 index 0000000000..9b4ff8e001 --- /dev/null +++ b/xCAT-test/bats/go_xcat_apt_install.bats @@ -0,0 +1,79 @@ +#!/usr/bin/env bats +# +# On apt, go-xcat installs the packages the repositories provide and warns about each one they +# do not, as dnf does with strict=0. Only a missing xcat metapackage stops the install, and a +# translated apt must not hide the packages that are there. + +load 'helpers/go_xcat' + +setup() +{ + go_xcat_require_source +} + +# Run install_packages_apt with apt-cache and apt-get doubles. apt-get records its arguments. +# +# $@ Package names. The names in APT_UNKNOWN (default "missing") are unknown to apt, and +# "nocandidate" is known with no candidate. apt-cache fails after it reports the +# package in APT_FAIL_AFTER. +install_with_apt() +{ + ( + log="$BATS_TEST_TMPDIR/apt-get.log" + PATH="" + source "$GO_XCAT_SOURCE" || exit 70 + apt-cache() + { + [ "$1" = policy ] || return 1 + shift + local installed='Installed:' candidate='Candidate:' package + if [ "${LC_ALL:-${LANG:-}}" != C ]; then + installed='已安装:' + candidate='候选:' + fi + for package in "$@"; do + case " ${APT_UNKNOWN:-missing} " in + *" $package "*) continue ;; + esac + case "$package" in + nocandidate) printf '%s:\n %s (none)\n %s (none)\n' "$package" "$installed" "$candidate" ;; + *) printf '%s:\n %s (none)\n %s 1.0-1\n Version table:\n 1.0-1 500\n' \ + "$package" "$installed" "$candidate" ;; + esac + [ "$package" != "${APT_FAIL_AFTER:-}" ] || return 100 + done + } + apt-get() { printf '%s\n' "$*" >>"$log"; } + install_packages_apt -y "$@" + ) +} + +@test "packages the repositories do not provide are skipped with a warning" { + run install_with_apt first missing nocandidate last + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + [ "$(cat "$BATS_TEST_TMPDIR/apt-get.log")" = '--allow-unauthenticated install -y first last' ] + grep -Fq 'missing: the repositories do not provide it, skipped' <<<"$output" + grep -Fq 'nocandidate: the repositories do not provide it, skipped' <<<"$output" +} + +@test "a translated apt still installs the packages the repositories provide" { + LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 run install_with_apt first last + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + [ "$(cat "$BATS_TEST_TMPDIR/apt-get.log")" = '--allow-unauthenticated install -y first last' ] + ! grep -Fq 'skipped' <<<"$output" +} + +@test "the install stops when the repositories do not provide the xcat metapackage" { + APT_UNKNOWN=xcat run install_with_apt perl-xcat xcat xcat-server + [ "$status" -ne 0 ] + [ ! -e "$BATS_TEST_TMPDIR/apt-get.log" ] + grep -Fq 'xcat: the repositories do not provide it' <<<"$output" +} + +@test "the install stops when apt cannot answer the candidate query" { + APT_FAIL_AFTER=xcat run install_with_apt xcat xcat-server xcat-buildkit + [ "$status" -ne 0 ] + [ ! -e "$BATS_TEST_TMPDIR/apt-get.log" ] + grep -Fq 'query apt package candidates failed' <<<"$output" + ! grep -Fq 'skipped' <<<"$output" +} From 3c85a7180c68f0609ad9596f0026d4dd73a28c3e 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, 29 Oct 2026 22:03:30 -0300 Subject: [PATCH 032/114] docs(support-matrix): list Ubuntu 24.04 and 26.04 on riscv64 The overview support matrix marked Ubuntu unsupported on riscv64 and limited riscv64 support to EL 10. The riscv64 guide and the mixed cluster support matrix document Ubuntu 24.04 and 26.04 riscv64 management and compute nodes, and the xcat-core and xcat-dep apt repositories index riscv64 for both releases. Mark both releases supported on riscv64 and name Ubuntu in the riscv64 note. --- docs/source/overview/support_matrix.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/source/overview/support_matrix.rst b/docs/source/overview/support_matrix.rst index 7058d9a3ad..00157865bc 100644 --- a/docs/source/overview/support_matrix.rst +++ b/docs/source/overview/support_matrix.rst @@ -16,9 +16,9 @@ Operating System & Hardware Support Matrix +-----------+---------------+---------+----------+-----------+ | Ubuntu | 22.04 | yes | yes | no | +-----------+---------------+---------+----------+-----------+ -| Ubuntu | 24.04 | yes | yes | no | +| Ubuntu | 24.04 | yes | yes | yes | +-----------+---------------+---------+----------+-----------+ -| Ubuntu | 26.04 | yes | yes | no | +| Ubuntu | 26.04 | yes | yes | yes | +-----------+---------------+---------+----------+-----------+ | openEuler | 20.03 LTS SP4 | yes | no | no | +-----------+---------------+---------+----------+-----------+ @@ -34,7 +34,7 @@ Operating System & Hardware Support Matrix openEuler support covers the management node, installed and diskless service nodes, and stateful and stateless compute nodes. -riscv64 support covers EL 10 (Rocky Linux 10 and the RHEL 10 RISC-V developer preview), on nodes -that boot through UEFI firmware and grub2. Both stateful and stateless nodes are supported, and -the management node itself can run on riscv64. See +riscv64 support covers EL 10 (Rocky Linux 10 and the RHEL 10 RISC-V developer preview) and +Ubuntu 24.04 and 26.04, on nodes that boot through UEFI firmware and grub2. Both stateful and +stateless nodes are supported, and the management node itself can run on riscv64. See :doc:`/guides/admin-guides/manage_clusters/riscv64/index` for details. From e813f1eed002e8df300e91e0a155f29bca068d79 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 30 Oct 2026 10:01:15 -0300 Subject: [PATCH 033/114] fix(xcat-core): no test shows a [Table_*] semicolon breaks the chtab command xcattest builds the chtab command for a [Table_*] row with unquoted words and runs it through /bin/bash -c. A [Table_vm] othersettings value such as cpumode:host-passthrough;firmware:efi-secureboot ends the command at the semicolon: chtab receives only the first setting, and bash runs the second as a command, so the environment setup fails. Move the command builder from setup_env_by_configure_file into xCAT::Test::Conf::chtab_command, with the same output, so a test can read the words chtab receives. xcattest_conf_chtab_command.t splits the command the way the shell does. Three of its four checks fail on this commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/lib/xCAT/Test/Conf.pm | 30 +++++++++ xCAT-test/unit/xcattest_conf_chtab_command.t | 64 ++++++++++++++++++++ xCAT-test/xcattest | 9 +-- 3 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 xCAT-test/unit/xcattest_conf_chtab_command.t diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm index a27ada92f7..8a9f649b60 100644 --- a/xCAT-test/lib/xCAT/Test/Conf.pm +++ b/xCAT-test/lib/xCAT/Test/Conf.pm @@ -125,6 +125,36 @@ sub chdef_command { #------------------------------------------------------------------------------- +=head3 chtab_command + + Descriptions: + The chtab command that applies one row of a [Table_*] block. + + The assignments are sorted, so one conf builds one command. + Arguments: + $table - the table name, as the section name spells it + $key - the key column of the row + $name - the value of the key column + $attrs - a hash reference of column to value + Returns: + the command + +=cut + +#------------------------------------------------------------------------------- +sub chtab_command { + my ($table, $key, $name, $attrs) = @_; + my @words = ("$key=$name"); + foreach my $attr (sort keys %$attrs) { + next if $attr eq '__KEY__'; + my $value = defined $attrs->{$attr} ? $attrs->{$attr} : ''; + push @words, "$table.$attr=$value"; + } + return join ' ', 'chtab', @words; +} + +#------------------------------------------------------------------------------- + =head3 _quote Descriptions: diff --git a/xCAT-test/unit/xcattest_conf_chtab_command.t b/xCAT-test/unit/xcattest_conf_chtab_command.t new file mode 100644 index 0000000000..6fd3110593 --- /dev/null +++ b/xCAT-test/unit/xcattest_conf_chtab_command.t @@ -0,0 +1,64 @@ +#!/usr/bin/env perl +# xcattest applies each row of a [Table_*] block with chtab, and runs the command through +# /bin/bash -c. A vm.othersettings value separates its settings with a semicolon: +# +# othersettings=cpumode:host-passthrough;firmware:efi-secureboot +# +# Unquoted, bash ends the chtab command at the semicolon and runs the second setting as a +# command. These checks split the command the way the shell does and look at the words chtab +# receives. +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use Test::More; +use Text::ParseWords qw(parse_line); + +require xCAT::Test::Conf; + +# The words bash gives to chtab, or undef when the command holds an unquoted shell operator. +sub chtab_words { + my ($cmd) = @_; + my @words = parse_line(qr/\s+/, 0, $cmd); + return undef if grep { !defined $_ } @words; + my @tokens = parse_line(qr/\s+/, 1, $cmd); + return undef if grep { !/^'.*'$/s && /[;&|<>`\$()*?\[\]]/ } @tokens; + return \@words; +} + +my $cmd = xCAT::Test::Conf::chtab_command('vm', 'node', 'cn1', + { __KEY__ => 'node', othersettings => 'cpumode:host-passthrough;firmware:efi-secureboot' }); +is_deeply( + chtab_words($cmd), + [ 'chtab', 'node=cn1', 'vm.othersettings=cpumode:host-passthrough;firmware:efi-secureboot' ], + 'chtab receives both settings of a vm.othersettings value in one argument' +); + +$cmd = xCAT::Test::Conf::chtab_command('site', 'key', 'domain name', + { __KEY__ => 'key', value => 'a&b' }); +is_deeply( + chtab_words($cmd), + [ 'chtab', 'key=domain name', 'site.value=a&b' ], + 'the row selector is quoted like the assignments' +); + +$cmd = xCAT::Test::Conf::chtab_command('site', 'key', 'motd', + { __KEY__ => 'key', value => "it's here" }); +is_deeply( + chtab_words($cmd), + [ 'chtab', 'key=motd', "site.value=it's here" ], + 'a single quote in a value does not end the quoting' +); + +# The values a table already held pass through unchanged. +$cmd = xCAT::Test::Conf::chtab_command('networks', 'netname', 'prov6', + { __KEY__ => 'netname', net => '2001:db8:176::/64', mask => '/64', dynamicrange => 'a-b' }); +is_deeply( + chtab_words($cmd), + [ 'chtab', 'netname=prov6', 'networks.dynamicrange=a-b', 'networks.mask=/64', + 'networks.net=2001:db8:176::/64' ], + 'the key column is not written as an attribute, and the assignments are sorted' +); + +done_testing(); diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index 7a9d9da963..0f9f79512a 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -1593,12 +1593,9 @@ sub setup_env_by_configure_file { if (exists $$config_ref{table}) { foreach my $type (keys %{ $$config_ref{table} }) { foreach my $name (keys %{ $$config_ref{table}{$type} }) { - $cmd = "chtab $$config_ref{table}{$type}{$name}{__KEY__}=$name"; - foreach my $attr (keys %{ $$config_ref{table}{$type}{$name} }) { - if ($attr ne '__KEY__') { - $cmd = $cmd . " $type.$attr=$$config_ref{table}{$type}{$name}{$attr}"; - } - } + $cmd = xCAT::Test::Conf::chtab_command($type, + $$config_ref{table}{$type}{$name}{__KEY__}, $name, + $$config_ref{table}{$type}{$name}); log_this($running_log_fd, "$cmd"); &runcmd($cmd); if ($::RUNCMD_RC != 0) { From 2107bd6069f6781cb7cf693bb9f4f1195b09aa53 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 30 Oct 2026 10:01:30 -0300 Subject: [PATCH 034/114] fix(xcat-core): chtab receives only the first setting of a [Table_*] value With [Table_vm] othersettings=cpumode:host-passthrough;firmware:efi-secureboot, xcattest gives chtab only cpumode:host-passthrough, and bash runs firmware:efi-secureboot as a command. The environment setup then fails. chtab_command joined its words unquoted, and xcattest runs the command through /bin/bash -c. chtab_command now quotes every word, the row selector included, with the same _quote that chdef_command uses. xcattest_conf_chtab_command.t passes with this change and fails 3 of 4 checks on the previous commit. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/lib/xCAT/Test/Conf.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xCAT-test/lib/xCAT/Test/Conf.pm b/xCAT-test/lib/xCAT/Test/Conf.pm index 8a9f649b60..b5e74e7177 100644 --- a/xCAT-test/lib/xCAT/Test/Conf.pm +++ b/xCAT-test/lib/xCAT/Test/Conf.pm @@ -130,6 +130,9 @@ sub chdef_command { Descriptions: The chtab command that applies one row of a [Table_*] block. + xcattest runs every command through /bin/bash -c, so each word is quoted, the row + selector too. A vm.othersettings value carries a semicolon. + The assignments are sorted, so one conf builds one command. Arguments: $table - the table name, as the section name spells it @@ -150,7 +153,7 @@ sub chtab_command { my $value = defined $attrs->{$attr} ? $attrs->{$attr} : ''; push @words, "$table.$attr=$value"; } - return join ' ', 'chtab', @words; + return join ' ', 'chtab', map { _quote($_) } @words; } #------------------------------------------------------------------------------- From 0f978df984ff09a8020c03f5d616461947c6d296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:54:47 -0300 Subject: [PATCH 035/114] test(install): give the riscv64 EFI fixtures partition GUIDs The efibootmgr fixture printed HD(1,GPT,...) without a partition GUID or the tab that ends an entry label, and the lsblk fixture could not answer a PARTUUID query, so no test could tell which partition a boot entry points at. The fixtures now print real GUIDs and labels, and lsblk reports the ESP partition GUID. --- xCAT-test/native/install_profile_riscv64.t | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xCAT-test/native/install_profile_riscv64.t b/xCAT-test/native/install_profile_riscv64.t index 15b035011b..cb8b6a8238 100644 --- a/xCAT-test/native/install_profile_riscv64.t +++ b/xCAT-test/native/install_profile_riscv64.t @@ -132,6 +132,7 @@ my $lsblk = fake_command('lsblk', <<'SH'); case "$*" in *PKNAME*) printf "vda\n" ;; *PARTN*) printf "1\n" ;; + *PARTUUID*) printf "0b8f4c1e-6a51-4b4e-9d7e-2f3a1c5d7e90\n" ;; esac SH my $efibootmgr = fake_command('efibootmgr', <<'SH'); @@ -139,8 +140,8 @@ printf '%s\n' "$*" >> "$XCAT_EFI_LOG" case "$*" in '') exit 0 ;; '-v') - printf 'Boot0001* Rocky HD(1,GPT,...)/File(\\EFI\\rocky\\shimx64.efi)\n' - printf 'Boot0002* OldRiscv HD(1,GPT,...)/File(\\EFI\\rocky\\grubriscv64.efi)\n' + printf 'Boot0001* Rocky Linux\tHD(1,GPT,0b8f4c1e-6a51-4b4e-9d7e-2f3a1c5d7e90,0x800,0x80000)/File(\\EFI\\rocky\\shimx64.efi)\n' + printf 'Boot0002* Rocky Linux\tHD(1,GPT,0B8F4C1E-6A51-4B4E-9D7E-2F3A1C5D7E90,0x800,0x80000)/File(\\EFI\\rocky\\grubriscv64.efi)\n' printf 'Boot0003* Network PXE\n' exit 0 ;; From 2f160aea37f27c5d0a3c6fbfb44b7aeb21cdc1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:55:05 -0300 Subject: [PATCH 036/114] fix(install): keep the riscv64 boot entries of other disks The EL10 riscv64 fix-up removed every UEFI boot entry for shimx64, grubx64 or grubriscv64, on any disk. The default partition layout installs to one disk and keeps the others, so an operating system on another disk lost its boot entry. The fix-up now removes only the entries on the ESP of the new install. Anaconda removes the entries with its own label before it adds its own, so an install that recreated the ESP leaves no old entry behind. When lsblk reports no partition GUID for the ESP, the fix-up removes nothing and still adds the new entry. --- .../share/xcat/install/scripts/post.rhels10.riscv64 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels10.riscv64 b/xCAT-server/share/xcat/install/scripts/post.rhels10.riscv64 index 3ede6003f7..78b11a78ca 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels10.riscv64 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels10.riscv64 @@ -34,12 +34,15 @@ if [ "$("$xcat_riscv_uname" -m)" = "riscv64" ] && [ -d "$xcat_riscv_install_root disk="$("$xcat_riscv_lsblk" -no PKNAME "$espdev" 2>/dev/null | head -1 | tr -d '[:space:]')" part="$("$xcat_riscv_lsblk" -no PARTN "$espdev" 2>/dev/null | head -1 | tr -d '[:space:]')" if [ -n "$disk" ] && [ -n "$part" ]; then + espuuid="$("$xcat_riscv_lsblk" -no PARTUUID "$espdev" 2>/dev/null | head -1 | tr -d '[:space:]' | tr 'A-F' 'a-f')" # drop the x86 entries anaconda created for this install, and any - # riscv64 entry a previous provisioning of this node left behind, so + # riscv64 entry a previous provisioning of this node left on this ESP, so # reinstalling does not fill the firmware variable store with copies - for bootnum in $("$xcat_riscv_efibootmgr" -v 2>/dev/null | awk '/\\EFI\\[^\\]+\\(shimx64|grubx64|grubriscv64)\.efi/ { sub(/^Boot/, "", $1); sub(/\*$/, "", $1); print $1 }'); do - "$xcat_riscv_efibootmgr" -q -b "$bootnum" -B || true - done + if [ -n "$espuuid" ]; then + for bootnum in $("$xcat_riscv_efibootmgr" -v 2>/dev/null | awk -v esp=",gpt,$espuuid," 'index(tolower($0), esp) && /\\EFI\\[^\\]+\\(shimx64|grubx64|grubriscv64)\.efi/ { sub(/^Boot/, "", $1); sub(/\*$/, "", $1); print $1 }'); do + "$xcat_riscv_efibootmgr" -q -b "$bootnum" -B || true + done + fi label="$(. "$xcat_riscv_install_root/etc/os-release" 2>/dev/null; echo "${NAME:-Linux}")" if "$xcat_riscv_efibootmgr" -q -c -d "/dev/$disk" -p "$part" -L "$label" -l "\\EFI\\$vendordir\\grubriscv64.efi"; then printf '%s\n' "riscv64: UEFI boot entry \"$label\" -> \\EFI\\$vendordir\\grubriscv64.efi on /dev/$disk part $part" From a09bc8eb076d00057557baec198da7313c8b373c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:55:21 -0300 Subject: [PATCH 037/114] test(install): cover riscv64 boot entries on other disks The EL10 fix-up must keep the boot entry of a system on another disk, and must remove nothing when lsblk reports no ESP partition GUID. Both cases fail with the earlier code, which removed every matching entry. --- xCAT-test/native/install_profile_riscv64.t | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xCAT-test/native/install_profile_riscv64.t b/xCAT-test/native/install_profile_riscv64.t index cb8b6a8238..2fe46f52ca 100644 --- a/xCAT-test/native/install_profile_riscv64.t +++ b/xCAT-test/native/install_profile_riscv64.t @@ -129,6 +129,7 @@ my $findmnt = fake_command('findmnt', <<'SH'); printf '/dev/vda1\n' SH my $lsblk = fake_command('lsblk', <<'SH'); +[ -n "$XCAT_TEST_NO_PARTUUID" ] && case "$*" in *PARTUUID*) exit 0 ;; esac case "$*" in *PKNAME*) printf "vda\n" ;; *PARTN*) printf "1\n" ;; @@ -143,6 +144,7 @@ case "$*" in printf 'Boot0001* Rocky Linux\tHD(1,GPT,0b8f4c1e-6a51-4b4e-9d7e-2f3a1c5d7e90,0x800,0x80000)/File(\\EFI\\rocky\\shimx64.efi)\n' printf 'Boot0002* Rocky Linux\tHD(1,GPT,0B8F4C1E-6A51-4B4E-9D7E-2F3A1C5D7E90,0x800,0x80000)/File(\\EFI\\rocky\\grubriscv64.efi)\n' printf 'Boot0003* Network PXE\n' + printf 'Boot0004* Ubuntu\tHD(1,GPT,5d2e8a47-0c3b-4f19-8e6a-91b7c4d2f063,0x800,0x100000)/\\EFI\\ubuntu\\grubriscv64.efi\n' exit 0 ;; *'-c'*) exit "${XCAT_EFI_CREATE_RC:-0}" ;; @@ -240,6 +242,7 @@ my $efi_calls = read_text($efi_log); like($efi_calls, qr/^-q -b 0001 -B$/m, 'the invalid x86 boot entry is removed'); like($efi_calls, qr/^-q -b 0002 -B$/m, 'the prior RISC-V boot entry is removed'); unlike($efi_calls, qr/0003/, 'unrelated firmware entries are retained'); +unlike($efi_calls, qr/-b 0004 /, 'the boot entry of a system on another disk is retained'); like( $efi_calls, qr/^-q -c -d \/dev\/vda -p 1 -L Rocky Linux -l \\EFI\\rocky\\grubriscv64\.efi$/m, @@ -263,4 +266,11 @@ unlink($efi_log); is($status, 0, 'an efibootmgr create failure remains nonfatal'); like($output, qr/firmware will use \\EFI\\BOOT\\BOOTRISCV64\.EFI/, 'the fallback path is reported after an efibootmgr failure'); +unlink($efi_log); +($status, $output) = run_post($root, XCAT_TEST_NO_PARTUUID => 1); +is($status, 0, 'the fix-up completes when lsblk reports no ESP partition GUID'); +my $unknown_calls = read_text($efi_log); +unlike($unknown_calls, qr/ -B$/m, 'no boot entry is removed when the ESP partition GUID is unknown'); +like($unknown_calls, qr/^-q -c -d \/dev\/vda -p 1 -L Rocky Linux /m, 'the boot entry is still registered without the ESP partition GUID'); + done_testing(); From c3e322de965955f04b8837c29cd09176c5793908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:15:27 -0300 Subject: [PATCH 038/114] fix(install): stop nodeset when a template has no root password A #CRYPT# template entry rendered as an empty string when the passwd table had no row for its key. An EL kickstart then held a bare "rootpw --iscrypted", and anaconda stopped with "A single argument is expected for the rootpw command". nodeset reported no error. nodeset now reports the missing passwd row and writes no boot configuration for the node, as it does for a missing #TABLE# field. #CRYPTORLOCKED# still renders a locked password. --- xCAT-server/lib/perl/xCAT/Template.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 747ba01e04..0fa6f3447c 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -1657,7 +1657,7 @@ sub envvar return ($ENV{$envvar}); } -sub crydb +sub crypt_field { my ($table, $key, $field) = @_; my @fields = [$field, 'cryptmethod']; @@ -1681,10 +1681,19 @@ sub crydb return xCAT::PasswordUtils::crypt_system_password($table, $kp, \@fields); } +sub crydb +{ + my ( $table, $key, $field ) = @_; + my $crypted = crypt_field( $table, $key, $field ); + return $crypted if defined($crypted) && length($crypted); + $tmplerr = "Unable to find requested field <$field> from table <$table>, with key <$key>"; + return ""; +} + sub crydb_or_locked { my ( $table, $key, $field ) = @_; - my $crypted = crydb( $table, $key, $field ); + my $crypted = crypt_field( $table, $key, $field ); return $crypted if defined($crypted) && length($crypted); return '*'; } From 2b8eb6a5fdaf22942a0ba9fe7ceb22157899bc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:23:57 -0300 Subject: [PATCH 039/114] docs(mixed-cluster): copy the xCAT Perl library to the image build node genimage loads the xCAT Perl library and the Perl modules it uses. The procedure that builds an image on a node of the target architecture copied only /opt/xcat/share/xcat/netboot, so genimage stopped with "Can't locate xCAT/SvrUtils.pm". The procedure now also copies /opt/xcat/lib/perl and installs the Perl modules. EL7 packages Digest::SHA and Sys::Syslog apart from perl, so the command names them. --- .../advanced/mixed_cluster/building_stateless_images.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/source/advanced/mixed_cluster/building_stateless_images.rst b/docs/source/advanced/mixed_cluster/building_stateless_images.rst index 590829abd6..9f20d51dc8 100644 --- a/docs/source/advanced/mixed_cluster/building_stateless_images.rst +++ b/docs/source/advanced/mixed_cluster/building_stateless_images.rst @@ -70,10 +70,15 @@ The following describes creating stateless images of the same Operating System, mkdir /install mount -o soft xcatmn:/install /install - #. Copy the executable files from the ``/opt/xcat/share/xcat/netboot`` from the xCAT Management node to the target node: :: + #. Copy ``/opt/xcat/share/xcat/netboot`` and the xCAT Perl library ``/opt/xcat/lib/perl`` from the xCAT Management node to the target node: :: - mkdir -p /opt/xcat/share/xcat/ + mkdir -p /opt/xcat/share/xcat/ /opt/xcat/lib/ scp -r xcatmn:/opt/xcat/share/xcat/netboot /opt/xcat/share/xcat/ + scp -r xcatmn:/opt/xcat/lib/perl /opt/xcat/lib/ + + #. Install the Perl modules that the xCAT Perl library uses: :: + + yum install perl perl-DBI perl-Digest-SHA perl-JSON perl-Sys-Syslog perl-XML-Simple #. Execute the ``genimage`` command obtained from the ``--dryrun``: :: From 2b2c6970c69528baaea665ee02b6a607c1dee961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:15:27 -0300 Subject: [PATCH 040/114] test(install): cover templates without a root password row The EL10 kickstart must not render without the passwd row, and must carry the hash of the configured password when the row exists. The Ubuntu autoinstall must still lock a password that has no row. The first case fails with the earlier code, which rendered an empty rootpw. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/template_root_password.t | 56 +++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/template_root_password.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index fa31e51ee5..46e4509e66 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -50,7 +50,7 @@ jobs: status=0 sudo sh -c 'cd "$1" && bats xCAT-test/native/getinstdisk_selection.bats' sh "$workdir" || status=1 sudo sh -c 'cd "$1" && bats xCAT-test/native/syslog_log_directory.bats' sh "$workdir" || status=1 - sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1 + sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/template_root_password.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1 exit "$status" - name: Prepare xCAT syslog directory if: ${{ !cancelled() }} diff --git a/xCAT-test/native/template_root_password.t b/xCAT-test/native/template_root_password.t new file mode 100644 index 0000000000..013c46a863 --- /dev/null +++ b/xCAT-test/native/template_root_password.t @@ -0,0 +1,56 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Slurper qw(read_text write_text); +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; + +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Template qw(template_database set_row render_template); + +plan skip_all => 'template rendering requires Linux namespaces' unless $^O eq 'linux'; +my $database = template_database(); +set_row('site', {key => 'secureroot'}, {value => 0}); +set_row('nodetype', {node => 'node'}, {os => 'rhels10.0', arch => 'x86_64', provmethod => 'install'}); +my $kickstart = repo_path('xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl'); +(my $pkglist = $kickstart) =~ s/\.tmpl$/.pkglist/; +my $output = "$database/ks"; + +sub render_kickstart { + return eval { + render_template($database, $kickstart, $output, 'node', $pkglist, '/install/media', 'rh', undef, + {xcatmaster => '192.0.2.1'}); + 1; + } ? '' : $@; +} + +my $error = render_kickstart(); +like($error, qr/Unable to find requested field from table , with key /, + 'a kickstart without a root password row is refused'); + +set_row('passwd', {key => 'system', username => 'root'}, {password => 'cluster'}); +$error = render_kickstart(); +is($error, '', 'a kickstart with a root password row renders') or diag($error); +my ($hash) = (-f $output ? read_text($output) : '') =~ /^rootpw --iscrypted (\S+)$/m; +ok(defined($hash) && crypt('cluster', $hash) eq $hash, 'the kickstart carries the hash of the root password'); + +set_row('nodetype', {node => 'node'}, {os => 'ubuntu24.04', arch => 'x86_64', provmethod => 'install'}); +my $passwd = xCAT::Table->new('passwd') or die 'Cannot open passwd'; +$passwd->delEntries({key => 'system', username => 'root'}); +$passwd->close(); +write_text("$database/image.pkglist", "vim\n"); +my $autoinstall = "$database/autoinstall.yaml"; +my $locked = eval { + render_template($database, repo_path('xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl'), + $autoinstall, 'node', "$database/image.pkglist", '/install/ubuntu24.04/x86_64', 'ubuntu', undef, + {xcatmaster => '192.0.2.1'}, osarch => 'x86_64'); + 1; +}; +ok($locked, 'an autoinstall without a root password row renders') or diag($@); +like(-f $autoinstall ? read_text($autoinstall) : '', qr/^\s+password: "\*"$/m, + 'the autoinstall locks the password that has no row'); + +done_testing(); From 2536ccc134b46b5ab16d30bc0f605f886b45bbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:34:05 -0300 Subject: [PATCH 041/114] fix(netboot): write keyfiles for the otherifce interfaces of EL10 images genimage wrote an ifcfg file for each interface that otherifce or genimage -r names. EL10 reads no ifcfg files, and its images have no network-scripts directory. Such an interface got DHCP only from the profile that NetworkManager makes for any port without one. genimage now writes a NetworkManager keyfile with DHCP for each of these interfaces on EL10 and later. A rebuild replaces the keyfiles of the earlier build. Older releases still get the same ifcfg files. --- .../share/xcat/netboot/imgutils/imgutils.pm | 34 +++++++++++++++++++ xCAT-server/share/xcat/netboot/rh/genimage | 14 +------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9cc0b35c7b..8ba604ba0c 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -189,6 +189,40 @@ sub mark_uftp_receiver { return !$error; } +# The initial ramdisk configures $prinic, and bringing it up again breaks an NFS-based boot. +# EL10 reads no ifcfg files, so its images get keyfiles. +sub write_nic_profiles { + my ($rootimg_dir, $osver, $prinic, $othernics) = @_; + my @othernics = grep { length } split(/,/, $othernics // ''); + my $scripts = "$rootimg_dir/etc/sysconfig/network-scripts"; + my $keyfiles = "$rootimg_dir/etc/NetworkManager/system-connections"; + my $major = el_major_version($osver); + my %profiles; + if (defined($major) && $major >= 10) { + if (-d $keyfiles) { + # The keyfiles of an earlier build can name interfaces that this build no longer requests. + opendir(my $dh, $keyfiles) or die("Error: cannot read $keyfiles: $!\n"); + foreach my $old (grep { /^xcat-genimage-.*\.nmconnection$/ } readdir($dh)) { + unlink("$keyfiles/$old") or die("Error: cannot remove $keyfiles/$old: $!\n"); + } + closedir($dh); + $profiles{"$keyfiles/xcat-genimage-$_.nmconnection"} = + "[connection]\nid=$_\ntype=ethernet\ninterface-name=$_\n\n[ipv4]\nmethod=auto\n" for @othernics; + } + } elsif (-d $scripts) { + $profiles{"$scripts/ifcfg-$prinic"} = "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=$prinic\n" if $prinic; + $profiles{"$scripts/ifcfg-$_"} = "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n" for @othernics; + } + foreach my $file (sort keys %profiles) { + # NetworkManager ignores a keyfile that other users can read. + my $mode = $file =~ /\.nmconnection$/ ? oct('600') : oct('644'); + my $fh; + open($fh, '>', $file) && chmod($mode, $file) && print($fh $profiles{$file}) && close($fh) + or die("Error: cannot write $file: $!\n"); + } + return; +} + sub varsubinline{ my $line=shift; my $refvardict=shift; diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 5808728a3a..a73e254e98 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -2166,19 +2166,7 @@ sub generic_post { #This function is meant to leave the image in a state approxi print $cfgfile "#Dummy resolv.conf to make boot cleaner"; close($cfgfile); - # Create the ifcfg-x file for diskless node. But keep the ONBOOT=no - # to skip the break of nfs-based boot - if ($prinic) { - open($cfgfile, ">", "$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$prinic"); - print $cfgfile "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=$prinic\n"; - close($cfgfile); - } - foreach (split /,/, $othernics) { - if (/^$/) { next; } - open($cfgfile, ">", "$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$_"); - print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n"; - close($cfgfile); - } + imgutils::write_nic_profiles($rootimg_dir, $osver, $prinic, $othernics); # securetty not needed on s390x if ($arch ne "s390x") { From 5609c8f811ccafafb3f353acbbb37322d224ceac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:34:05 -0300 Subject: [PATCH 042/114] test(netboot): cover the otherifce profiles of diskless images An EL10 image must get a DHCP keyfile for each requested interface, also when it has a network-scripts directory. Only root can read the keyfiles, and the interface of the initial ramdisk gets none. A rebuild must drop the keyfile of an interface that is no longer requested and keep other profiles. An EL9 image must keep its ifcfg files. --- xCAT-test/unit/imgutils_nic_profiles.t | 72 ++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 xCAT-test/unit/imgutils_nic_profiles.t diff --git a/xCAT-test/unit/imgutils_nic_profiles.t b/xCAT-test/unit/imgutils_nic_profiles.t new file mode 100644 index 0000000000..bec60b5a3c --- /dev/null +++ b/xCAT-test/unit/imgutils_nic_profiles.t @@ -0,0 +1,72 @@ +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Fcntl qw(S_IMODE); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use Test::More; +use XCAT::Test::File qw(repo_path); + +$ENV{XCATROOT} = repo_path('xCAT-server'); +require(repo_path('xCAT-server/share/xcat/netboot/imgutils/imgutils.pm')); + +my @both = ('etc/sysconfig/network-scripts', 'etc/NetworkManager/system-connections'); + +sub image { + my $root = tempdir(CLEANUP => 1); + make_path(map { "$root/$_" } @_); + return $root; +} + +sub mode { + my ($file) = @_; + return -f $file ? sprintf('%04o', S_IMODE((stat $file)[2])) : 'missing'; +} + +sub profiles { + my ($root) = @_; + return [map { substr($_, length($root) + 1) } sort glob("$root/{$both[0],$both[1]}/*")]; +} + +for my $case (['rhels10.1', 'etc/NetworkManager/system-connections'], ['alma10.1', @both]) { + my ($os, @dirs) = @$case; + my $root = image(@dirs); + imgutils::write_nic_profiles($root, $os, 'eth0', 'eth1,,eth2'); + is_deeply(profiles($root), [map { "$both[1]/xcat-genimage-$_.nmconnection" } qw(eth1 eth2)], + "a $os image with " . join(' and ', @dirs) . ' gets keyfiles for the requested interfaces only'); + for my $nic (qw(eth1 eth2)) { + my $file = "$root/$both[1]/xcat-genimage-$nic.nmconnection"; + is(-f $file ? read_text($file) : '', + "[connection]\nid=$nic\ntype=ethernet\ninterface-name=$nic\n\n[ipv4]\nmethod=auto\n", + "the $os keyfile for $nic asks for DHCP"); + is(mode($file), '0600', "only root can read the $os keyfile for $nic"); + } +} + +my $rebuilt = image($both[1]); +write_text("$rebuilt/$both[1]/site.nmconnection", "site profile\n"); +imgutils::write_nic_profiles($rebuilt, 'rhels10.1', 'eth0', 'eth1,eth2'); +imgutils::write_nic_profiles($rebuilt, 'rhels10.1', 'eth0', 'eth2'); +is_deeply(profiles($rebuilt), ["$both[1]/site.nmconnection", "$both[1]/xcat-genimage-eth2.nmconnection"], + 'a rebuilt EL10 image drops the keyfile of an interface that is no longer requested and keeps other profiles'); + +my $el9 = image(@both); +imgutils::write_nic_profiles($el9, 'rhels9.6', 'eth0', 'eth1'); +is_deeply(profiles($el9), ["$both[0]/ifcfg-eth0", "$both[0]/ifcfg-eth1"], 'an EL9 image gets ifcfg files only'); +is(read_text("$el9/$both[0]/ifcfg-eth0"), "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=eth0\n", + 'the EL9 interface of the initial ramdisk stays off at boot'); +is(read_text("$el9/$both[0]/ifcfg-eth1"), "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=eth1\n", + 'the EL9 interface eth1 gets DHCP'); +is(mode("$el9/$both[0]/ifcfg-eth1"), '0644', 'the EL9 ifcfg file keeps its permissions'); + +for my $os (qw(rhels10.1 rhels9.6)) { + my $bare = image('etc'); + imgutils::write_nic_profiles($bare, $os, 'eth0', 'eth1'); + ok(!-e "$bare/etc/sysconfig" && !-e "$bare/etc/NetworkManager", "a $os image without either directory gets no profile"); +} + +done_testing(); From 9da20e00cd631c453c05ee04f2b85b8dc329b29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:50:31 -0300 Subject: [PATCH 043/114] fix(netboot): keep EL10 diskless nodes from DHCP on every port NetworkManager in an EL10 diskless image made a DHCP profile for every Ethernet port without one. A port with a link but no DHCP server kept NetworkManager-wait-online from finishing, so the node booted degraded. Diskful nodes are not affected, because anaconda writes a profile for every port. genimage now sets no-auto-default=* in the NetworkManager configuration of EL10 images. The boot interface keeps the profile from the initial ramdisk. The other interfaces get only the profiles that the image or the xCAT network configuration gives them. --- xCAT-server/share/xcat/netboot/imgutils/imgutils.pm | 13 +++++++++++++ xCAT-server/share/xcat/netboot/rh/genimage | 1 + 2 files changed, 14 insertions(+) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 8ba604ba0c..8f0d0ec7e0 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -223,6 +223,19 @@ sub write_nic_profiles { return; } +# NetworkManager otherwise makes a DHCP profile for every Ethernet port without one. +sub disable_auto_profiles { + my ($rootimg_dir, $osver) = @_; + my $major = el_major_version($osver); + my $confdir = "$rootimg_dir/etc/NetworkManager/conf.d"; + return unless defined($major) && $major >= 10 && -d $confdir; + my $file = "$confdir/xcat.conf"; + my $fh; + open($fh, '>', $file) && print($fh "[main]\nno-auto-default=*\n") && close($fh) + or die("Error: cannot write $file: $!\n"); + return; +} + sub varsubinline{ my $line=shift; my $refvardict=shift; diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index a73e254e98..26826cb2fb 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -2167,6 +2167,7 @@ sub generic_post { #This function is meant to leave the image in a state approxi close($cfgfile); imgutils::write_nic_profiles($rootimg_dir, $osver, $prinic, $othernics); + imgutils::disable_auto_profiles($rootimg_dir, $osver); # securetty not needed on s390x if ($arch ne "s390x") { From 3e514bc6eecf137ff2c193de83ee3a5822edb4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:52:02 -0300 Subject: [PATCH 044/114] test(netboot): cover the NetworkManager defaults of EL10 images An EL10 image must turn off the automatic DHCP profiles. An EL9 image must keep the NetworkManager defaults, and an image without NetworkManager must get no NetworkManager configuration. --- xCAT-test/unit/imgutils_nic_profiles.t | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/xCAT-test/unit/imgutils_nic_profiles.t b/xCAT-test/unit/imgutils_nic_profiles.t index bec60b5a3c..49a271027c 100644 --- a/xCAT-test/unit/imgutils_nic_profiles.t +++ b/xCAT-test/unit/imgutils_nic_profiles.t @@ -69,4 +69,19 @@ for my $os (qw(rhels10.1 rhels9.6)) { ok(!-e "$bare/etc/sysconfig" && !-e "$bare/etc/NetworkManager", "a $os image without either directory gets no profile"); } +for my $case (['rhels10.1', 1], ['rocky10.2', 1], ['rhels9.6', 0]) { + my ($os, $disabled) = @$case; + my $root = image('etc/NetworkManager/conf.d'); + imgutils::disable_auto_profiles($root, $os); + my $conf = "$root/etc/NetworkManager/conf.d/xcat.conf"; + if ($disabled) { + is(-f $conf ? read_text($conf) : '', "[main]\nno-auto-default=*\n", "a $os image turns off the automatic DHCP profiles"); + } else { + ok(!-e $conf, "a $os image keeps the NetworkManager defaults"); + } +} +my $without = image('etc'); +imgutils::disable_auto_profiles($without, 'rhels10.1'); +ok(!-e "$without/etc/NetworkManager", 'an image without NetworkManager gets no NetworkManager configuration'); + done_testing(); From 1c42a2c7294b62fa7aef0cb3aba2e88206de5f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:22:04 -0300 Subject: [PATCH 045/114] fix(netboot): drop the dhclient and ifcfg handoff from EL10 initrds The dracut_105 xcatroot scripts and the statelite xcat-prepivot.sh copied dhclient leases and wrote an ifcfg file for the boot interface. EL10 has no dhclient and no ifcfg plugin. The copy failed with "cannot stat" on every boot, and the ifcfg write failed on a directory that the image does not have. NetworkManager in the initrd already hands the boot interface to the NetworkManager of the root image. The scripts no longer copy leases or write ifcfg files. --- .../netboot/rh/dracut_105/stateless/xcatroot | 57 ------------------- .../rh/dracut_105/statelite/xcat-prepivot.sh | 46 --------------- .../netboot/rh/dracut_105/statelite/xcatroot | 57 ------------------- 3 files changed, 160 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot index e0edf3c349..7a48711bb0 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot @@ -368,63 +368,6 @@ else fi cd / -function getdevfrommac() { - boothwaddr=$1 - ip link show | while read line - do - dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1` - if [ "X$dev" != "X" ]; then - devname=$dev - fi - - if [ "X$devname" != "X" ]; then - hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'` - if [ "X$hwaddr" = "X$boothwaddr" ]; then - echo $devname - fi - fi - done -} - - -if [ -z $STATEMNT ]; then - for lf in /tmp/dhclient.*.lease; do - netif=${lf#*.} - netif=${netif%.*} - cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases" - done - - ifname="$(getarg ifname=)" - netdev="$(getarg netdev=)" - BOOTIF="$(getarg BOOTIF=)" - if [ ! -z "$ifname" ]; then - MACX=${ifname#*:} - ETHX=${ifname%:$MACX*} - elif [ ! -z "$netdev" ]; then - ETHX=$netdev - MACX=`ip link show $netdev | grep ether | awk '{print $2}'` - elif [ ! -z "$BOOTIF" ]; then - MACX=$BOOTIF - MACX=${MACX#01-} - MACX=${MACX//-/:} - ETHX=$(getdevfrommac $MACX) - fi - - - if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then - if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX" - touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - fi - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes" - echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - fi -fi - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/etc/resolv.conf" cp /etc/resolv.conf "$NEWROOT/etc/" diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh index a3bcb8188e..b1e3924392 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh @@ -143,52 +143,6 @@ mount -n --bind /dev $NEWROOT/dev mount -n --bind /proc $NEWROOT/proc mount -n --bind /sys $NEWROOT/sys -function getdevfrommac() { - boothwaddr=$1 - ip link show | while read line - do - dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1` - if [ "X$dev" != "X" ]; then - devname=$dev - fi - - if [ "X$devname" != "X" ]; then - hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'` - if [ "X$hwaddr" = "X$boothwaddr" ]; then - echo $devname - fi - fi - done -} - - -for lf in /tmp/dhclient.*.lease; do - netif=${lf#*.} - netif=${netif%.*} - cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" -done - -if [ ! -z "$ifname" ]; then - MACX=${ifname#*:} - ETHX=${ifname%:$MACX*} -elif [ ! -z "$netdev" ]; then - ETHX=$netdev - MACX=`ip link show $netdev | grep ether | awk '{print $2}'` -elif [ ! -z "$BOOTIF" ]; then - MACX=$BOOTIF - ETHX=$(getdevfrommac $BOOTIF) -fi - -if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then - if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then - touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - fi - echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX -fi - cp /etc/resolv.conf "$NEWROOT/etc/" if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot index f14ad2b341..bc91d8c466 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot +++ b/xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot @@ -317,63 +317,6 @@ else fi cd / -function getdevfrommac() { - boothwaddr=$1 - ip link show | while read line - do - dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1` - if [ "X$dev" != "X" ]; then - devname=$dev - fi - - if [ "X$devname" != "X" ]; then - hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'` - if [ "X$hwaddr" = "X$boothwaddr" ]; then - echo $devname - fi - fi - done -} - - -if [ -z $STATEMNT ]; then - for lf in /tmp/dhclient.*.lease; do - netif=${lf#*.} - netif=${netif%.*} - cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases" - done - - ifname="$(getarg ifname=)" - netdev="$(getarg netdev=)" - BOOTIF="$(getarg BOOTIF=)" - if [ ! -z "$ifname" ]; then - MACX=${ifname#*:} - ETHX=${ifname%:$MACX*} - elif [ ! -z "$netdev" ]; then - ETHX=$netdev - MACX=`ip link show $netdev | grep ether | awk '{print $2}'` - elif [ ! -z "$BOOTIF" ]; then - MACX=$BOOTIF - MACX=${MACX#01-} - MACX=${MACX//-/:} - ETHX=$(getdevfrommac $MACX) - fi - - - if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then - if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX" - touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - fi - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes" - echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX - fi -fi - [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/etc/resolv.conf" cp /etc/resolv.conf "$NEWROOT/etc/" From 6d5f8bcec5f9dbd690d9dd3707b41ca098447441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:25:40 -0300 Subject: [PATCH 046/114] test(netboot): cover the EL10 initrd network handoff The dracut_105 xcatroot must not copy dhclient leases or write an ifcfg file. With the earlier script the case fails on the "cannot stat" and ifcfg errors that an EL10 boot printed. --- xCAT-test/bats/xcatroot_rootimg_checksum.bats | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xCAT-test/bats/xcatroot_rootimg_checksum.bats b/xCAT-test/bats/xcatroot_rootimg_checksum.bats index 195707595e..550c56d9ab 100644 --- a/xCAT-test/bats/xcatroot_rootimg_checksum.bats +++ b/xCAT-test/bats/xcatroot_rootimg_checksum.bats @@ -174,7 +174,7 @@ run_xcatroot() done # genimage puts the helper in every initial ramdisk that can receive the root image over UFTP. [ -n "$NO_UFTP_HELPER" ] || sandbox+=(--ro-bind "$(repo_path xCAT-server/share/xcat/netboot/imgutils/xcat-rootimg-fetch.sh)" /lib/xcat-rootimg-fetch.sh) - echo "imgurl=$URL XCAT=192.0.2.1:3001 nonodestatus $CMDLINE $UFTP" >"$FX/cmdline" + echo "imgurl=$URL XCAT=192.0.2.1:3001 nonodestatus $CMDLINE $UFTP $KERNEL_ARGS" >"$FX/cmdline" echo "$IMAGE_PLAN" >"$FX/image.plan" echo "$CHECKSUM_PLAN" >"$FX/checksum.plan" echo "${MAXWAITS:-100}" >"$FX/maxwaits" @@ -309,3 +309,11 @@ check_each_script() CMDLINE= SCRIPTS=$UFTP_SCRIPTS UFTP="xcat.uftp=1045 xcat.uftpfp=$FP" check_each_script 'packed image' "$URL " 0 'Cannot receive .*rootimg.cpio.gz over UFTP' } + +@test 'the EL10 initial ramdisk copies no dhclient lease and writes no ifcfg file' { + SCRIPTS='xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot bash' + KERNEL_ARGS='ifname=eth0:52:54:00:12:34:56' + check_each_script 'packed image' "$URL.sha256 $URL $URL.sha256 " 0 '' + run grep -E 'dhclient|network-scripts' "$FX/console" + [ "$status" -eq 1 ] || { echo "$output"; return 1; } +} From 3d30d5fd864f7d591ce5295ead6f255e642ca16d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:51:11 -0300 Subject: [PATCH 047/114] fix(go-xcat): read apt candidates in the C locale check_repo_version_apt looks for the "Candidate:" label of apt-cache policy. A translated apt prints that label in the user's language. The package table of go-xcat check, install and update then showed every package as "(not found)" in the repositories. Run apt-cache policy with LC_ALL="C" inside check_repo_version_apt, so that every caller gets the untranslated labels. Drop the LC_ALL=C that the install filter added. --- xCAT-server/share/xcat/tools/go-xcat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index f088f0cad5..3a934d3570 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -952,7 +952,7 @@ function check_repo_version_apt() local ver="" local policy="" local rc=0 - policy="$(apt-cache policy "$@" 2>/dev/null)" || rc="$?" + policy="$(LC_ALL="C" apt-cache policy "$@" 2>/dev/null)" || rc="$?" while read -r name ver do if [[ "${name}" =~ ^[a-z] ]] @@ -1994,7 +1994,7 @@ function install_packages_apt() [[ "$1" = "-y" ]] && yes=("-y") && shift local -a available=() local package="" ver="" versions="" - versions="$(LC_ALL=C check_repo_version_apt "$@")" + versions="$(check_repo_version_apt "$@")" warn_if_bad "$?" "query apt package candidates failed" || return 1 # As with dnf --setopt=strict=0, a package the repositories lack must not stop the install. for package in "$@" From 96850ce72b467b4b8cfdfa94a9538cf2507668e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:52:06 -0300 Subject: [PATCH 048/114] test(go-xcat): cover the package table under a translated apt Share the apt-cache double of the apt install tests. Check that list_xcat_packages shows the apt candidates in the C locale and under a translated apt. --- xCAT-test/bats/go_xcat_apt_install.bats | 28 ++-------- xCAT-test/bats/go_xcat_package_listing.bats | 59 +++++++++++++++++++++ xCAT-test/bats/helpers/go_xcat_apt.bash | 28 ++++++++++ 3 files changed, 90 insertions(+), 25 deletions(-) create mode 100644 xCAT-test/bats/go_xcat_package_listing.bats create mode 100644 xCAT-test/bats/helpers/go_xcat_apt.bash diff --git a/xCAT-test/bats/go_xcat_apt_install.bats b/xCAT-test/bats/go_xcat_apt_install.bats index 9b4ff8e001..322c4688a9 100644 --- a/xCAT-test/bats/go_xcat_apt_install.bats +++ b/xCAT-test/bats/go_xcat_apt_install.bats @@ -5,44 +5,22 @@ # translated apt must not hide the packages that are there. load 'helpers/go_xcat' +load 'helpers/go_xcat_apt' setup() { go_xcat_require_source } -# Run install_packages_apt with apt-cache and apt-get doubles. apt-get records its arguments. +# Run install_packages_apt with the apt-cache double. apt-get records its arguments. # -# $@ Package names. The names in APT_UNKNOWN (default "missing") are unknown to apt, and -# "nocandidate" is known with no candidate. apt-cache fails after it reports the -# package in APT_FAIL_AFTER. +# $@ Package names, answered as helpers/go_xcat_apt describes. install_with_apt() { ( log="$BATS_TEST_TMPDIR/apt-get.log" PATH="" source "$GO_XCAT_SOURCE" || exit 70 - apt-cache() - { - [ "$1" = policy ] || return 1 - shift - local installed='Installed:' candidate='Candidate:' package - if [ "${LC_ALL:-${LANG:-}}" != C ]; then - installed='已安装:' - candidate='候选:' - fi - for package in "$@"; do - case " ${APT_UNKNOWN:-missing} " in - *" $package "*) continue ;; - esac - case "$package" in - nocandidate) printf '%s:\n %s (none)\n %s (none)\n' "$package" "$installed" "$candidate" ;; - *) printf '%s:\n %s (none)\n %s 1.0-1\n Version table:\n 1.0-1 500\n' \ - "$package" "$installed" "$candidate" ;; - esac - [ "$package" != "${APT_FAIL_AFTER:-}" ] || return 100 - done - } apt-get() { printf '%s\n' "$*" >>"$log"; } install_packages_apt -y "$@" ) diff --git a/xCAT-test/bats/go_xcat_package_listing.bats b/xCAT-test/bats/go_xcat_package_listing.bats new file mode 100644 index 0000000000..7d504e2c34 --- /dev/null +++ b/xCAT-test/bats/go_xcat_package_listing.bats @@ -0,0 +1,59 @@ +#!/usr/bin/env bats +# +# go-xcat check, install and update print a table of the xCAT packages, with the installed version +# and the version that the repositories offer. On apt, the table must show the candidates that a +# translated apt reports. + +load 'helpers/go_xcat' +load 'helpers/go_xcat_apt' + +setup() +{ + go_xcat_require_source +} + +# Print the package table of list_xcat_packages with the apt-cache double. xcat-core offers xcat and +# xcat-server, xcat-dep offers ipmitool-xcat, and none of them is installed. +list_packages() +{ + ( + PATH="" + source "$GO_XCAT_SOURCE" || exit 70 + get_package_list() + { + case "$1" in + xcat-core) echo xcat xcat-server ;; + xcat-dep) echo ipmitool-xcat ;; + esac + } + check_package_version() + { + local package + for package in "$@"; do + echo '(not installed)' + done + } + list_xcat_packages + ) +} + +# Succeed when the table offers version 1.0-1 of every package. +offers_every_package() +{ + local package + for package in xcat xcat-server ipmitool-xcat; do + grep -Eq "^${package} +\\(not installed\\) +1\\.0-1 *\$" <<<"$1" || return 1 + done +} + +@test "the package table shows the apt candidates" { + LANG=C LC_ALL=C run list_packages + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + offers_every_package "$output" || { printf '%s\n' "$output"; return 1; } +} + +@test "the package table shows the candidates that a translated apt reports" { + LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 run list_packages + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + offers_every_package "$output" || { printf '%s\n' "$output"; return 1; } +} diff --git a/xCAT-test/bats/helpers/go_xcat_apt.bash b/xCAT-test/bats/helpers/go_xcat_apt.bash new file mode 100644 index 0000000000..550aa06147 --- /dev/null +++ b/xCAT-test/bats/helpers/go_xcat_apt.bash @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Answer "apt-cache policy" as apt does, with translated labels unless LC_ALL or LANG is C. +# +# $@ Package names. The names in APT_UNKNOWN (default "missing") are unknown to apt, and +# "nocandidate" is known with no candidate. apt-cache fails after it reports the +# package in APT_FAIL_AFTER. +apt-cache() +{ + [ "$1" = policy ] || return 1 + shift + local installed='Installed:' candidate='Candidate:' package + if [ "${LC_ALL:-${LANG:-}}" != C ]; then + installed='已安装:' + candidate='候选:' + fi + for package in "$@"; do + case " ${APT_UNKNOWN:-missing} " in + *" $package "*) continue ;; + esac + case "$package" in + nocandidate) printf '%s:\n %s (none)\n %s (none)\n' "$package" "$installed" "$candidate" ;; + *) printf '%s:\n %s (none)\n %s 1.0-1\n Version table:\n 1.0-1 500\n' \ + "$package" "$installed" "$candidate" ;; + esac + [ "$package" != "${APT_FAIL_AFTER:-}" ] || return 100 + done +} From 1e1ed5160114b5f852681a66ba6b9e62f4d90cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:52:27 -0300 Subject: [PATCH 049/114] fix(go-xcat): keep tput errors out of the package table list_xcat_packages reads the terminal width with tput cols. With an unknown or unset TERM, tput prints "unknown terminal" or "No value for $TERM" in the middle of the go-xcat output. Check the terminal type with tput longname, with its output discarded, before reading the width. tput cols keeps its stderr, because the tput of ncurses 5 (EL7) reads the width through stderr. With stderr discarded, it reports 80 columns on a wider terminal. --- xCAT-server/share/xcat/tools/go-xcat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 3a934d3570..78175944a1 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -2277,7 +2277,8 @@ function list_xcat_packages() warn_if_bad "$?" "Failed to get package list from repository \`xcat-dep'." || return 1 local -i cols - cols="$(type tput >/dev/null 2>&1 && tput cols)" + # The tput of ncurses 5 reads the width through stderr, so only the terminal type check is silenced. + cols="$(type tput >/dev/null 2>&1 && tput longname >/dev/null 2>&1 && tput cols)" [[ "${cols}" -lt 80 ]] && cols=80 [[ "${cols}" -gt 90 ]] && cols=90 [[ -t 1 ]] || cols=90 From 98190f9ebaa26cdadfdc5aaf1578ac0e7b4a5c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:52:48 -0300 Subject: [PATCH 050/114] test(go-xcat): cover the package table with an unknown terminal type Check that list_xcat_packages adds no tput error to its output when TERM names a terminal type that tput does not know, or is empty. --- xCAT-test/bats/go_xcat_package_listing.bats | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xCAT-test/bats/go_xcat_package_listing.bats b/xCAT-test/bats/go_xcat_package_listing.bats index 7d504e2c34..343785e9a2 100644 --- a/xCAT-test/bats/go_xcat_package_listing.bats +++ b/xCAT-test/bats/go_xcat_package_listing.bats @@ -2,7 +2,7 @@ # # go-xcat check, install and update print a table of the xCAT packages, with the installed version # and the version that the repositories offer. On apt, the table must show the candidates that a -# translated apt reports. +# translated apt reports. A terminal type that tput does not know must not add tput errors to it. load 'helpers/go_xcat' load 'helpers/go_xcat_apt' @@ -57,3 +57,19 @@ offers_every_package() [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } offers_every_package "$output" || { printf '%s\n' "$output"; return 1; } } + +@test "an unknown terminal type adds no tput error to the package table" { + command -v tput >/dev/null || skip "tput is required" + TERM=xcat-unknown-terminal run list_packages + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + offers_every_package "$output" || { printf '%s\n' "$output"; return 1; } + if grep -F 'tput' <<<"$output"; then return 1; fi +} + +@test "an empty TERM adds no tput error to the package table" { + command -v tput >/dev/null || skip "tput is required" + TERM= run list_packages + [ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; } + offers_every_package "$output" || { printf '%s\n' "$output"; return 1; } + if grep -F 'tput' <<<"$output"; then return 1; fi +} From 875acb6cfb1e8a2734715d09d44dee4728a0b9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:58:35 -0300 Subject: [PATCH 051/114] fix(ipmi): read the SDR record count as one 16-bit value got_sdr_rep_info computed the record count as ($returnd[1] + $returnd[2]) << 8, because Perl gives + a higher precedence than <<. The count names the SDR cache of a BMC. Counts whose two bytes have the same sum, such as 39 and 294, shared a cache. A BMC that went from one count to the other reused the old SDR. Shift only the MS byte, and raise the SDR cache version to 5. A cache file from the old encoding can have the name of a new count: the file for 257 records is named 512. The version makes each BMC model read its SDR again once after the update. --- xCAT-server/lib/xcat/plugins/ipmi.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index d3b450507c..378e4ed337 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -124,7 +124,7 @@ my $cache_dir = "/var/cache/xcat"; use xCAT::data::ibmleds; use xCAT::data::ipmigenericevents; use xCAT::data::ipmisensorevents; -my $cache_version = 4; +my $cache_version = 5; my %sdr_caches; #store sdr cachecs in memory indexed such that identical nodes do not hit the disk multiple times #my $status_noop="XXXno-opXXX"; @@ -8106,7 +8106,7 @@ sub got_sdr_rep_info { } my @returnd = @{ $rsp->{data} }; $sessdata->{sdr_info}->{version} = $returnd[0]; - $sessdata->{sdr_info}->{rec_count} = $returnd[1] + $returnd[2] << 8; + $sessdata->{sdr_info}->{rec_count} = $returnd[1] + ($returnd[2] << 8); $sessdata->{sdr_info}->{resv_sdr} = ($returnd[13] & 0b00000010) >> 1; initsdr_withrepinfo($sessdata); } From e049e1c155677ff14da82413a4b301517fa703b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 20:58:53 -0300 Subject: [PATCH 052/114] test(ipmi): cover an SDR record count above 255 Check that got_sdr_rep_info selects another SDR cache when the record count changes from 39 to 294 or from 1 to 256. Check that the same count keeps the same cache. Check that loadsdrcache does not load a cache file of an earlier release, and still loads a file that storsdrcache wrote. --- xCAT-test/unit/ipmi_sdr_reservation.t | 59 +++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/xCAT-test/unit/ipmi_sdr_reservation.t b/xCAT-test/unit/ipmi_sdr_reservation.t index df10162695..7a02b78e40 100644 --- a/xCAT-test/unit/ipmi_sdr_reservation.t +++ b/xCAT-test/unit/ipmi_sdr_reservation.t @@ -6,11 +6,15 @@ use warnings; no warnings qw(once redefine); use File::Spec; +use File::Temp qw(tempdir); use FindBin; +use Storable qw(nstore_fd); use Test::More; # Get SDR Repository Info can leave the reservation bit clear on a BMC that grants Reserve -# SDR Repository. The SDR read must still ask for the reservation and use it. +# SDR Repository. The SDR read must still ask for the reservation and use it. The record count +# of the reply names the SDR cache, so a changed count must select another cache, and a cache +# named with the record count of an earlier release must be read again. BEGIN { for my $module (qw( @@ -73,6 +77,8 @@ BEGIN { package main; *CORE::GLOBAL::chmod = sub (@) { return 1; }; + # storsdrcache creates the cache directory of the management node. + *CORE::GLOBAL::system = sub { return 0; }; } package FakeSession; @@ -101,10 +107,12 @@ sub new_sessdata { } # The Get SDR Repository Info reply of an OpenBMC that grants reservations, with the -# operation support byte last. +# record count (43 by default) and the operation support byte last. sub repository_info { - my ($operation_support) = @_; - return { code => 0, data => [ 0x51, 0x2b, 0x00, 0xff, 0xff, (0) x 8, $operation_support ] }; + my ($operation_support, $records) = @_; + $records //= 0x2b; + return { code => 0, + data => [ 0x51, $records & 0xff, $records >> 8, 0xff, 0xff, (0) x 8, $operation_support ] }; } sub requests { return $_[0]->{ipmisession}->{calls}; } @@ -172,4 +180,47 @@ subtest 'a BMC that advertises the reservation is still asked for one' => sub { is($request->{command}, 0x22, 'the request is Reserve SDR Repository'); }; +sub cache_file_for { + my ($records) = @_; + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x02, $records), $sessdata); + return $sessdata->{sdrcache_file}; +} + +subtest 'a changed record count selects another SDR cache' => sub { + for my $change ([ 39, 294 ], [ 1, 256 ]) { + my ($before, $after) = @$change; + isnt(cache_file_for($after), cache_file_for($before), + "a BMC that goes from $before to $after records does not reuse its SDR cache"); + } + is(cache_file_for(294), cache_file_for(294), 'the same record count keeps the SDR cache'); +}; + +sub sdr_record { + return SDR->new(sensor_owner_id => 0x20, sensor_owner_lun => 0, sensor_number => 1); +} + +subtest 'an SDR cache of an earlier release is read again' => sub { + my $dir = tempdir(CLEANUP => 1); + + # Earlier releases wrote version 4 and named the cache of 257 records like that of 512. + my $legacy = "$dir/sdr_legacy"; + open(my $fh, '>', $legacy) or die "$legacy: $!"; + nstore_fd({ xcat_sdrcacheversion => 4 }, $fh); + nstore_fd(sdr_record(), $fh); + close($fh); + my $sessdata = new_sessdata(); + is(xCAT_plugin::ipmi::loadsdrcache($sessdata, $legacy), 1, 'the cache is not loaded'); + is_deeply($sessdata->{sdr_hash} || {}, {}, 'no SDR record comes from it'); + + my $current = "$dir/sdr_current"; + my $writer = new_sessdata(); + $writer->{sdr_hash} = { '32.0.1' => sdr_record() }; + is(xCAT_plugin::ipmi::storsdrcache($current, $writer), 0, 'a new cache is written'); + my $reader = new_sessdata(); + is(xCAT_plugin::ipmi::loadsdrcache($reader, $current), 0, 'the new cache is loaded'); + is_deeply([ keys %{ $reader->{sdr_hash} || {} } ], ['32.0.1'], 'its SDR record is read back'); +}; + done_testing(); From 2fb4e3b89a748581292dd841986a1575eeb2286c 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, 2 Nov 2026 15:03:11 -0300 Subject: [PATCH 053/114] fix(anaconda): accept the openEuler riscv64 media openEuler publishes 24.03 LTS installation media for riscv64, but the openEuler media check admits only x86_64 and ppc64le. copycds stops with "Unsupported openEuler architecture in .treeinfo". Admit riscv64 as well. aarch64 stays refused. --- xCAT-server/lib/xcat/plugins/anaconda.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 993dae39b1..1c674adca0 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -114,7 +114,7 @@ sub _openeuler_media_info return { error => 'Unsupported openEuler LTS version in .treeinfo' } unless defined($version); return { error => 'Unsupported openEuler architecture in .treeinfo' } - unless defined($general{arch}) && $general{arch} =~ /\A(?:x86_64|ppc64le)\z/; + unless defined($general{arch}) && $general{arch} =~ /\A(?:x86_64|ppc64le|riscv64)\z/; return { distname => "openeuler$version", arch => $general{arch} }; } From a112ff0f2d257164f7323c56cd1270afa1b90b6a 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, 2 Nov 2026 15:05:11 -0300 Subject: [PATCH 054/114] test(anaconda): identify the openEuler riscv64 media The fixture holds the .treeinfo and .discinfo of the 24.03 LTS-SP3 RVA23 DVD. copycds must identify it as openeuler24.03sp3 on riscv64. --- .../openeuler-media/24.03sp3-riscv64/.discinfo | 3 +++ .../openeuler-media/24.03sp3-riscv64/.treeinfo | 17 +++++++++++++++++ xCAT-test/fixtures/openeuler-media/README.md | 5 ++++- xCAT-test/unit/anaconda_openeuler_media.t | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.discinfo create mode 100644 xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.treeinfo diff --git a/xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.discinfo b/xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.discinfo new file mode 100644 index 0000000000..c0797ee98c --- /dev/null +++ b/xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.discinfo @@ -0,0 +1,3 @@ +1772722427.779849 +RVA23 +riscv64 diff --git a/xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.treeinfo b/xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.treeinfo new file mode 100644 index 0000000000..4d4e8dcba6 --- /dev/null +++ b/xCAT-test/fixtures/openeuler-media/24.03sp3-riscv64/.treeinfo @@ -0,0 +1,17 @@ +[general] +timestamp = 1772724994.9646769 +family = openEuler +version = 24.03-LTS-SP3 +name = openEuler-24.03-LTS-SP3 +variant = Server +arch = riscv64 +packagedir = + +[stage2] +mainimage = images/install.img + +[images-riscv64] +kernel = images/pxeboot/vmlinuz +initrd = images/pxeboot/initrd.img +efiboot.img = images/efiboot.img + diff --git a/xCAT-test/fixtures/openeuler-media/README.md b/xCAT-test/fixtures/openeuler-media/README.md index 12665bb250..e7037e346b 100644 --- a/xCAT-test/fixtures/openeuler-media/README.md +++ b/xCAT-test/fixtures/openeuler-media/README.md @@ -4,5 +4,8 @@ These files are the upstream expanded installation-tree metadata: - https://repo.openeuler.org/openEuler-24.03-LTS/OS/ppc64le/ - https://repo.openeuler.org/openEuler-24.03-LTS-SP4/OS/x86_64/ +- https://repo.openeuler.org/openEuler-24.03-LTS-SP3/ISO/riscv64/rva23/, + from `openEuler-24.03-LTS-SP3-RVA23-riscv64-dvd.iso` -Both `.discinfo` descriptions are empty. POWER uses `2403-LTS` in `.treeinfo`. +The x86_64 and POWER `.discinfo` descriptions are empty, and the riscv64 one is +`RVA23`. POWER uses `2403-LTS` in `.treeinfo`. diff --git a/xCAT-test/unit/anaconda_openeuler_media.t b/xCAT-test/unit/anaconda_openeuler_media.t index 71036c0a3f..2733eb0c80 100644 --- a/xCAT-test/unit/anaconda_openeuler_media.t +++ b/xCAT-test/unit/anaconda_openeuler_media.t @@ -51,6 +51,7 @@ sub media_tree { for my $case ( ['24.03-ppc64le', 'openeuler24.03', 'ppc64le'], ['24.03sp4-x86_64', 'openeuler24.03sp4', 'x86_64'], + ['24.03sp3-riscv64', 'openeuler24.03sp3', 'riscv64'], ) { my ($fixture, $os, $arch) = @$case; my $responses = inspect_media(repo_path("xCAT-test/fixtures/openeuler-media/$fixture")); From a3d3926c705bcd05415c92375823ce7af2cc9ba0 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, 2 Nov 2026 15:05:54 -0300 Subject: [PATCH 055/114] fix(anaconda): publish the riscv64 boot loader of openEuler media copycds looks for EFI/BOOT/grubriscv64.efi on riscv64 media. openEuler media carry the same image as EFI/BOOT/grubriscv64.EFI, so copycds publishes no grub2.riscv64. A management node with only openEuler media then has no riscv64 network boot loader. Match the image name case-insensitively, as UEFI does. --- xCAT-server/lib/xcat/plugins/anaconda.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 1c674adca0..dee1055d44 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2203,7 +2203,13 @@ sub _install_media_grub2_loader { my $image = $MEDIA_GRUB2_LOADERS{$arch}; return unless $image; - my $source = "$path/EFI/BOOT/$image"; + + # UEFI file names are case-insensitive: openEuler ships grubriscv64.EFI. + opendir(my $dh, "$path/EFI/BOOT") or return; + my ($name) = sort grep { lc($_) eq $image } readdir($dh); + closedir($dh); + return unless defined($name); + my $source = "$path/EFI/BOOT/$name"; return unless -r $source; my $tftpdir = xCAT::TableUtils->getTftpDir(); From 28e447bb2ea5bb72cf2f21f231463024a09a8682 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, 2 Nov 2026 15:07:10 -0300 Subject: [PATCH 056/114] test(anaconda): publish an upper-case riscv64 media boot loader openEuler media carry EFI/BOOT/grubriscv64.EFI. copycds must publish it as grub2.riscv64. --- xCAT-test/unit/copycd_grub2_loader.t | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xCAT-test/unit/copycd_grub2_loader.t b/xCAT-test/unit/copycd_grub2_loader.t index f663beacc8..3e479ca27f 100644 --- a/xCAT-test/unit/copycd_grub2_loader.t +++ b/xCAT-test/unit/copycd_grub2_loader.t @@ -94,4 +94,15 @@ is( scalar xCAT_plugin::anaconda::_install_media_grub2_loader( $bare_media, 'ris is( messages( \@responses ), '', 'media without a grub2 image report nothing' ); ok( !-d File::Spec->catdir( $tftpdir, 'boot' ), 'media without a grub2 image create no directories' ); +# openEuler spells the image grubriscv64.EFI; UEFI names are case-insensitive +$tftpdir = File::Spec->catdir( $root, 'tftpboot-openeuler' ); +make_path($tftpdir); +my $oe_media = media( $root, 'openeuler24.03sp3-riscv64', 'grubriscv64.EFI' ); +@responses = (); +$loader = File::Spec->catfile( $tftpdir, 'boot', 'grub2', 'grub2.riscv64' ); +is( scalar xCAT_plugin::anaconda::_install_media_grub2_loader( $oe_media, 'riscv64', sub { push @responses, @_; } ), + $loader, 'an upper-case image name is published as the riscv64 boot loader' ); +is( -f $loader ? read_text($loader) : undef, "boot loader from the media\n", + 'the published image is the one from the openEuler media' ); + done_testing(); From 0c9860fcfa2a775fd89a4c76727e014034945ce3 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, 2 Nov 2026 15:16:58 -0300 Subject: [PATCH 057/114] fix(netboot): build and pack openEuler riscv64 diskless images genimage and packimage admit openEuler images only for x86_64 and ppc64le. For the riscv64 osimage that copycds creates, genimage stops with "Unsupported openEuler release or architecture" and packimage with "Unsupported openEuler image release or architecture". Admit riscv64 in both commands. --- xCAT-server/lib/xcat/plugins/genimage.pm | 2 +- xCAT-server/lib/xcat/plugins/packimage.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/genimage.pm b/xCAT-server/lib/xcat/plugins/genimage.pm index 92493e92af..8c5f606470 100644 --- a/xCAT-server/lib/xcat/plugins/genimage.pm +++ b/xCAT-server/lib/xcat/plugins/genimage.pm @@ -305,7 +305,7 @@ sub process_request { } if ($osver =~ /^openeuler/) { unless (defined(xCAT::Utils::normalize_openeuler_version(substr($osver, 9))) - && $arch =~ /^(?:x86_64|ppc64le)$/) { + && $arch =~ /^(?:x86_64|ppc64le|riscv64)$/) { $callback->({ error => ["Unsupported openEuler release or architecture: $osver $arch"], errorcode => [1] }); return 1; } diff --git a/xCAT-server/lib/xcat/plugins/packimage.pm b/xCAT-server/lib/xcat/plugins/packimage.pm index 54293761b5..e873c59476 100644 --- a/xCAT-server/lib/xcat/plugins/packimage.pm +++ b/xCAT-server/lib/xcat/plugins/packimage.pm @@ -201,7 +201,7 @@ sub process_request { my $is_openeuler = $osver =~ /^openeuler/; if ($is_openeuler) { unless (defined(xCAT::Utils::normalize_openeuler_version(substr($osver, 9))) - && $arch =~ /^(?:x86_64|ppc64le)$/) { + && $arch =~ /^(?:x86_64|ppc64le|riscv64)$/) { $callback->({ error => ["Unsupported openEuler image release or architecture: $osver $arch"], errorcode => [1] }); return 1; } From 72b3228f816b442befdb7d957f0d778b789cebc3 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, 2 Nov 2026 15:22:02 -0300 Subject: [PATCH 058/114] test(netboot): build and pack openEuler riscv64 diskless images genimage must dispatch an openeuler24.03sp3 riscv64 image to the native openEuler builder. packimage must pack it, and still refuse it as a StateLite image. --- xCAT-test/unit/openeuler_genimage_dispatch.t | 6 ++++++ xCAT-test/unit/packimage_openeuler_stateless.t | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xCAT-test/unit/openeuler_genimage_dispatch.t b/xCAT-test/unit/openeuler_genimage_dispatch.t index df152e5d01..bd46003c8d 100644 --- a/xCAT-test/unit/openeuler_genimage_dispatch.t +++ b/xCAT-test/unit/openeuler_genimage_dispatch.t @@ -55,6 +55,12 @@ for my $os (qw(openeuler20.03sp4 openeuler22.03sp4 openeuler24.03sp1 openeuler24 like($out, qr{netboot/openeuler; ./genimage -a ppc64le -o openeuler24\.03 -p compute\n}, 'POWER keeps its architecture and GA release'); } +{ + my ($responses, $out) = dispatch('openeuler24.03sp3', 'riscv64'); + ok(!grep({ $_->{error} } @$responses), 'riscv64 resolves the native image builder'); + like($out, qr{netboot/openeuler; ./genimage -a riscv64 -o openeuler24\.03sp3 -p compute\n}, + 'riscv64 keeps its architecture and SP release'); +} for my $case (['openeuler25.03', 'x86_64'], ['openeuler24.03sp0', 'x86_64'], ['openeuler', 'x86_64'], ['openeuler24.03', 'aarch64']) { my ($responses, $out) = dispatch(@$case); diff --git a/xCAT-test/unit/packimage_openeuler_stateless.t b/xCAT-test/unit/packimage_openeuler_stateless.t index 46bfc78259..6fb0f5ddbc 100644 --- a/xCAT-test/unit/packimage_openeuler_stateless.t +++ b/xCAT-test/unit/packimage_openeuler_stateless.t @@ -82,7 +82,7 @@ sub attempt { } for my $case (['openeuler20.03sp4', 'x86_64'], ['openeuler22.03sp4', 'x86_64'], - ['openeuler24.03sp3', 'x86_64'], ['openeuler24.03', 'ppc64le']) { + ['openeuler24.03sp3', 'x86_64'], ['openeuler24.03', 'ppc64le'], ['openeuler24.03sp3', 'riscv64']) { my ($responses, $commands, $locks, $root) = attempt(@$case, 0); ok(grep({ $_->{error} && $_->{error}[0] =~ /Invalid compress method/ } @$responses), "@$case reaches the archive boundary"); @@ -94,7 +94,7 @@ for my $case (['openeuler20.03sp4', 'x86_64'], ['openeuler22.03sp4', 'x86_64'], } for my $case (['openeuler24.03sp3', 'x86_64', 1], ['openeuler24.03', 'ppc64le', 1], - ['openeuler25.03', 'x86_64', 0], ['openeuler24.03sp0', 'x86_64', 0], + ['openeuler24.03sp3', 'riscv64', 1], ['openeuler25.03', 'x86_64', 0], ['openeuler24.03sp0', 'x86_64', 0], ['openeuler24.03sp3', 's390x', 0]) { my ($responses, $commands, $locks, $root) = attempt(@$case); my $error = $case->[2] ? qr/StateLite images are not supported/ : qr/Unsupported openEuler image/; From da5aea54f5627f6de043ab6312cef34602d50302 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, 2 Nov 2026 16:57:16 -0300 Subject: [PATCH 059/114] docs(openeuler): list riscv64 compute nodes List openEuler 24.03 LTS SP4 on riscv64 in the openEuler guide, the riscv64 guide and the support matrix. The scope is installed and stateless compute nodes from the RVA23 media. riscv64 management and service nodes stay out, because xCAT publishes no openEuler riscv64 packages. The openEuler guide also says to import the openEuler key on the genimage build host. A new installation has no key in its RPM keyring. --- .../manage_clusters/openeuler/index.rst | 23 +++++++++++++++++-- .../manage_clusters/riscv64/index.rst | 10 +++++--- docs/source/overview/support_matrix.rst | 5 ++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst b/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst index 3c57348437..d1ec78f1a4 100644 --- a/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst +++ b/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst @@ -28,6 +28,9 @@ Qualification uses one service pack from each LTS release: * - 24.03 LTS GA - ppc64le - ``openeuler24.03`` + * - 24.03 LTS SP4 + - riscv64 + - ``openeuler24.03sp4`` Earlier service packs are outside this qualification. The POWER GA image is a functional exception; its qualification does not establish maintained @@ -41,6 +44,17 @@ cpio with gzip compression. SQLite serves standalone management nodes; MariaDB serves the service-node hierarchy. Additional firmware, database, image-format and network combinations need separate qualification. +On riscv64, the qualification covers installed and stateless compute nodes +from the RVA23 media, managed from a riscv64 management node that runs +Ubuntu 26.04. xCAT publishes no openEuler riscv64 packages, so riscv64 +management and service nodes are outside it. The test hardware could not boot +from the network, so firmware network boot is not qualified either. See +:doc:`/guides/admin-guides/manage_clusters/riscv64/index`. + +openEuler also publishes RVA20 media for riscv64. ``copycds`` copies both +builds of a release to the same directory, so import only the build that +matches the nodes. + The tested provisioning networks use IPv4 and ISC DHCP on isolated links, with separate upstream and downstream interfaces on service nodes. The qualification covers on-link access to the assigned management or service @@ -116,8 +130,13 @@ Stateless compute images Build the image on an openEuler host of the target architecture, using its native kernel, modules and package repositories. Check the image's network -drivers and interface settings before generation. For the imported compute -profile:: +drivers and interface settings before generation. ``genimage`` checks every +package against the signing keys in the build host's RPM keyring. A new +openEuler installation has no key there. Import the openEuler key first:: + + rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-openEuler + +For the imported compute profile:: genimage openeuler24.03sp4-x86_64-netboot-compute packimage -m cpio -c gzip openeuler24.03sp4-x86_64-netboot-compute diff --git a/docs/source/guides/admin-guides/manage_clusters/riscv64/index.rst b/docs/source/guides/admin-guides/manage_clusters/riscv64/index.rst index 1605ae0aee..5c4f944531 100644 --- a/docs/source/guides/admin-guides/manage_clusters/riscv64/index.rst +++ b/docs/source/guides/admin-guides/manage_clusters/riscv64/index.rst @@ -1,10 +1,13 @@ RISC-V 64-bit (riscv64) ======================= -xCAT manages RISC-V 64-bit (``riscv64``) compute nodes running EL10 or Ubuntu. +xCAT manages RISC-V 64-bit (``riscv64``) compute nodes running EL10, Ubuntu or +openEuler. Rocky Linux 10 is the reference EL distribution and the RHEL 10 RISC-V developer preview uses the same media layout; on the Ubuntu side, 24.04 and 26.04 are -supported from the live-server media. The general cluster management documentation under +supported from the live-server media. openEuler 24.03 LTS SP4 is supported from +the RVA23 media. See :doc:`/guides/admin-guides/manage_clusters/openeuler/index`. +The general cluster management documentation under :doc:`/guides/admin-guides/manage_clusters/index` applies; this page only covers what is specific to the architecture. @@ -27,7 +30,8 @@ What riscv64 nodes need BaseOS tree, which the ``grub2-xcat`` package also installs and :doc:`/guides/install-guides/yum/grub2` describes copying by hand; ``copycds`` publishes it when the management node does not have it yet and keeps an image - that is already there. + that is already there. openEuler media carry the same image as + ``EFI/BOOT/grubriscv64.EFI``, and ``copycds`` publishes it the same way. Ubuntu media are different: the loader they carry boots only from the media, because it holds a built-in configuration that searches for the live diff --git a/docs/source/overview/support_matrix.rst b/docs/source/overview/support_matrix.rst index 7058d9a3ad..f3429aa62d 100644 --- a/docs/source/overview/support_matrix.rst +++ b/docs/source/overview/support_matrix.rst @@ -24,7 +24,7 @@ Operating System & Hardware Support Matrix +-----------+---------------+---------+----------+-----------+ | openEuler | 22.03 LTS SP4 | yes | no | no | +-----------+---------------+---------+----------+-----------+ -| openEuler | 24.03 LTS SP4 | yes | no | no | +| openEuler | 24.03 LTS SP4 | yes | no | yes | +-----------+---------------+---------+----------+-----------+ .. note:: @@ -32,7 +32,8 @@ Operating System & Hardware Support Matrix EL stands for Enterprise Linux, such as: Red Hat Enterprise Linux (RHEL), Rocky Linux, AlmaLinux, CentOS and Oracle Linux. openEuler support covers the management node, installed and diskless service nodes, and - stateful and stateless compute nodes. + stateful and stateless compute nodes. On riscv64, it covers only stateful and stateless + compute nodes. riscv64 support covers EL 10 (Rocky Linux 10 and the RHEL 10 RISC-V developer preview), on nodes that boot through UEFI firmware and grub2. Both stateful and stateless nodes are supported, and From 48c4f81b824a2e5287ede3573b561c6907fefc5f 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, 2 Nov 2026 19:25:17 -0300 Subject: [PATCH 060/114] fix(netboot): start kdump on stateless nodes only with dump memory openEuler diskless images enable kdump.service, which @core brings in. A stateless command line reserves dump memory only through linuximage.dump or addkcmdline, so on every other node kdump.service fails and the node boots degraded. genimage adds a kdump.service drop-in with triggering conditions on crashkernel and fadump, so the service is skipped when the command line has neither. POWER firmware-assisted dumps, which xCAT configures with fadump= and no crashkernel=, still start. An image without kdump.service is unchanged. --- xCAT-server/share/xcat/netboot/imgutils/imgutils.pm | 13 +++++++++++++ xCAT-server/share/xcat/netboot/rh/genimage | 1 + 2 files changed, 14 insertions(+) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9cc0b35c7b..9e19d6ce92 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -118,6 +118,19 @@ sub disable_vendor_repositories { } } +# kdump.service fails without dump memory, which a stateless command line +# reserves only with crashkernel= or, on POWER, fadump=. +sub skip_kdump_without_dump_memory { + my ($rootimg_dir) = @_; + return unless -e "$rootimg_dir/usr/lib/systemd/system/kdump.service"; + my $dropin_dir = "$rootimg_dir/etc/systemd/system/kdump.service.d"; + mkpath($dropin_dir); + open(my $fh, '>', "$dropin_dir/xcat-dump-memory.conf") + or die "Cannot write $dropin_dir/xcat-dump-memory.conf: $!\n"; + print $fh "[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n"; + close($fh) or die "Cannot write $dropin_dir/xcat-dump-memory.conf: $!\n"; +} + sub publish_boot_files { my ($native_bootdir, $destdir, $initrd, $mode) = @_; move($initrd, "$native_bootdir/initrd-$mode.gz") diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 5808728a3a..f885dc68f2 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -821,6 +821,7 @@ xdie("Error: failed to generate the initial ramdisk: native image has no dracut if $native_bootdir && !$dracutmode; imgutils::disable_vendor_repositories($rootimg_dir); +imgutils::skip_kdump_without_dump_memory($rootimg_dir); #-- run postinstall script unless ($imagename) { From 7a570074654564a34993930ff35ecabfeda3f6b7 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, 2 Nov 2026 19:26:32 -0300 Subject: [PATCH 061/114] test(netboot): start kdump on stateless nodes only with dump memory An image with kdump.service must get the dump-memory drop-in, once, next to any site drop-in, and an image without it must get none. systemd itself must start kdump.service with crashkernel= or fadump= on the command line, and skip it with neither. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/kdump_condition_systemd.t | 42 +++++++++++++++++ xCAT-test/unit/imgutils_kdump_condition.t | 52 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 xCAT-test/native/kdump_condition_systemd.t create mode 100644 xCAT-test/unit/imgutils_kdump_condition.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index fa31e51ee5..3fbad86536 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -104,7 +104,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/kdump_condition_systemd.t b/xCAT-test/native/kdump_condition_systemd.t new file mode 100755 index 0000000000..dba670b81f --- /dev/null +++ b/xCAT-test/native/kdump_condition_systemd.t @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Slurper qw(read_text write_text); +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use XCAT::Test::Process qw(run_command); +use imgutils; + +plan skip_all => 'systemd condition evaluation requires Linux' unless $^O eq 'linux'; +my ($analyze) = grep { -x $_ } qw(/usr/bin/systemd-analyze /bin/systemd-analyze); +BAIL_OUT('Install systemd to run this test') unless $analyze; + +# systemd evaluates the drop-in's own conditions; SYSTEMD_PROC_CMDLINE stands in +# for the kernel command line of the node. +my $root = tempdir(CLEANUP => 1); +make_path("$root/usr/lib/systemd/system"); +write_text("$root/usr/lib/systemd/system/kdump.service", "[Service]\n"); +imgutils::skip_kdump_without_dump_memory($root); +my @conditions = grep { /^Condition/ } + split /\n/, read_text("$root/etc/systemd/system/kdump.service.d/xcat-dump-memory.conf"); +ok(@conditions, 'the drop-in carries conditions'); + +for my $case ( + ['crashkernel=256M quiet', 1, 'a crashkernel= reservation'], + ['fadump=on fadump_reserve_mem=1G dump=nfs://192.0.2.1/dumps', 1, 'a POWER firmware-assisted dump'], + ['quiet console=ttyS0,115200', 0, 'no dump memory'], +) { + my ($cmdline, $start, $label) = @$case; + local $ENV{SYSTEMD_PROC_CMDLINE} = $cmdline; + my ($status, $output) = run_command($analyze, 'condition', @conditions); + is($status == 0 ? 1 : 0, $start, ($start ? 'kdump.service starts with ' : 'kdump.service does not start with ') . $label) + or diag($output); +} + +done_testing(); diff --git a/xCAT-test/unit/imgutils_kdump_condition.t b/xCAT-test/unit/imgutils_kdump_condition.t new file mode 100644 index 0000000000..d3d16bb45c --- /dev/null +++ b/xCAT-test/unit/imgutils_kdump_condition.t @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +my $dropin = 'etc/systemd/system/kdump.service.d/xcat-dump-memory.conf'; +my $condition = "[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n"; + +sub image_root { + my (%units) = @_; + my $root = tempdir(CLEANUP => 1); + for my $unit (keys %units) { + make_path("$root/usr/lib/systemd/system"); + write_text("$root/usr/lib/systemd/system/$unit", $units{$unit}); + } + return $root; +} + +{ + my $root = image_root('kdump.service' => "[Service]\nExecStart=/usr/bin/kdumpctl start\n", + 'NetworkManager.service' => "[Service]\n"); + make_path("$root/etc/systemd/system/kdump.service.d"); + write_text("$root/etc/systemd/system/kdump.service.d/site.conf", "[Service]\nTimeoutSec=600\n"); + for my $pass (1, 2) { + imgutils::skip_kdump_without_dump_memory($root); + is(read_text("$root/$dropin"), $condition, + "pass $pass: kdump.service runs only with crashkernel= or fadump="); + } + opendir(my $dh, "$root/etc/systemd/system/kdump.service.d") or die "opendir: $!"; + is_deeply([sort grep { !/^\./ } readdir($dh)], ['site.conf', 'xcat-dump-memory.conf'], + 'the drop-in is written once next to the site drop-ins'); + closedir($dh); + is(read_text("$root/etc/systemd/system/kdump.service.d/site.conf"), "[Service]\nTimeoutSec=600\n", + 'a site drop-in is unchanged'); + ok(!-e "$root/etc/systemd/system/NetworkManager.service.d", 'other units get no drop-in'); +} + +{ + my $root = image_root('NetworkManager.service' => "[Service]\n"); + imgutils::skip_kdump_without_dump_memory($root); + ok(!-e "$root/etc/systemd/system/kdump.service.d", 'an image without kdump.service is unchanged'); +} + +done_testing(); From 4f8d099b193b44683b2217407a147c35e2abfb6e 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, 2 Nov 2026 19:33:43 -0300 Subject: [PATCH 062/114] fix(install): start kdump on openEuler nodes only with dump memory On riscv64, an installed openEuler node reserves no dump memory, so kdump.service fails and the node boots degraded. The openEuler kickstart %post adds the kdump.service drop-in that stateless images get. It runs before post.rhels8, which ends the %post script with exit 0. A node whose command line carries crashkernel= or fadump= still starts kdump. --- .../share/xcat/install/openeuler/compute.openeuler.tmpl | 1 + xCAT-server/share/xcat/install/scripts/post.openeuler | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 xCAT-server/share/xcat/install/scripts/post.openeuler diff --git a/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl b/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl index 77dda6d86e..a022871a5f 100644 --- a/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl +++ b/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl @@ -32,6 +32,7 @@ mkdir -p /var/log/xcat/ cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.openeuler# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng# #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.rhels8# #SELINUXRELABEL# diff --git a/xCAT-server/share/xcat/install/scripts/post.openeuler b/xCAT-server/share/xcat/install/scripts/post.openeuler new file mode 100644 index 0000000000..319dae7d84 --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/post.openeuler @@ -0,0 +1,7 @@ +# kdump.service fails without dump memory, which the kernel has only when its +# command line carries crashkernel= or, on POWER, fadump=. +if [ -e /usr/lib/systemd/system/kdump.service ]; then + mkdir -p /etc/systemd/system/kdump.service.d + printf '[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n' \ + >/etc/systemd/system/kdump.service.d/xcat-dump-memory.conf +fi From fd8e60c21eb652eba8014bfb35836e48accb5631 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, 2 Nov 2026 19:36:18 -0300 Subject: [PATCH 063/114] test(install): start kdump on openEuler nodes only with dump memory The rendered compute and service %post, run in a sandbox through the downloaded postscript, must leave the kdump.service drop-in that stateless images get. A system without kdump.service must get none. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/openeuler_post_kdump.t | 86 +++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/openeuler_post_kdump.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 3fbad86536..a61196daa7 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -104,7 +104,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/openeuler_post_kdump.t b/xCAT-test/native/openeuler_post_kdump.t new file mode 100644 index 0000000000..445858aff5 --- /dev/null +++ b/xCAT-test/native/openeuler_post_kdump.t @@ -0,0 +1,86 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Copy qw(copy); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; + +use imgutils; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database set_row render_template); + +plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux'; +my $database = template_database(); +require xCAT::SvrUtils; +set_row('passwd', {key => 'system', username => 'root'}, {password => '$6$fixture$encrypted'}); +set_row('nodetype', {node => 'node'}, {os => 'openeuler24.03sp4', arch => 'riscv64', provmethod => 'install'}); + +my $dropin = 'etc/systemd/system/kdump.service.d/xcat-dump-memory.conf'; +my $image = tempdir(CLEANUP => 1); +make_path("$image/usr/lib/systemd/system"); +write_text("$image/usr/lib/systemd/system/kdump.service", "[Service]\n"); +imgutils::skip_kdump_without_dump_memory($image); +my $stateless = read_text("$image/$dropin"); + +sub post_root { + my (%units) = @_; + my $root = sandbox_root(); + make_path("$root/units", "$root/etc/systemd/system", "$root/etc/yum.repos.d"); + write_text("$root/units/$_", $units{$_}) for keys %units; + write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n"); + copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!; + write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n"); + for my $name (qw(curl logger sleep updateflag.awk nmcli openssl)) { + copy(repo_path('xCAT-test/fixtures/install-profile/command'), "$root/bin/$name") or die $!; + chmod 0755, "$root/bin/$name" or die $!; + } + return $root; +} + +my $base = repo_path('xCAT-server/share/xcat/install/openeuler'); +for my $profile (qw(compute service)) { + subtest "$profile post-install sequence" => sub { + my $tmpl = xCAT::SvrUtils->get_tmpl_file_name($base, $profile, 'openeuler24.03sp4', 'riscv64'); + my $pkglist = xCAT::SvrUtils->get_pkglist_file_name($base, $profile, 'openeuler24.03sp4', 'riscv64'); + my $output = "$database/$profile.ks"; + render_template($database, $tmpl, $output, 'node', $pkglist, '/install/media', 'openeuler', undef, + {xcatmaster => '192.0.2.1'}); + my @posts; + my $rendered = read_text($output); + while ($rendered =~ /^%post([^\n]*)\n(.*?)^%end/msg) { + push @posts, [$1, $2]; + } + ok(@posts, 'renders a %post section'); + + for my $case ( + [{'kdump.service' => "[Service]\nExecStart=/usr/bin/kdumpctl start\n"}, $stateless, + 'installs the drop-in that stateless images get'], + [{'NetworkManager.service' => "[Service]\n"}, undef, 'adds no drop-in without kdump.service'], + ) { + my ($units, $expected, $label) = @$case; + my $root = post_root(%$units); + my $index = 0; + for my $post (@posts) { + my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/; + write_text("$root/post.sh", $post->[1]); + my ($rc, $log) = sandbox_run($root, {read_only => {"$root/units" => '/usr/lib/systemd/system'}}, + 'timeout', '30', $interpreter // '/bin/sh', '/fixture/post.sh'); + is($rc, 0, '%post section ' . ++$index . ' completes') + or diag($log, read_text("$root/log/xcat/xcat.log")); + } + ok(-e "$root/postscript-ran", 'runs the rendered sequence through the downloaded postscript'); + ok(!-e "$root/unexpected-command", 'external fixtures accept the requested operations'); + is(-f "$root/$dropin" ? read_text("$root/$dropin") : undef, $expected, $label); + } + }; +} + +done_testing(); From 3505c49b9a84a267716fdff59cf2b84f00a38136 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, 2 Nov 2026 18:25:34 -0300 Subject: [PATCH 064/114] fix(anaconda): refuse to mix the RVA20 and RVA23 openEuler media openEuler publishes RVA20 and RVA23 builds of each riscv64 release. Both carry the same .treeinfo identity, so copycds copies the second one into the directory of the first, and the result is a repository with packages of two builds. copycds now compares the .discinfo description, RVA23 or empty, with the copy already in the target directory, and refuses a different build. Media of the same build, and every other architecture, copy as before. --- xCAT-server/lib/xcat/plugins/anaconda.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index dee1055d44..dcc6c3859e 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -119,6 +119,19 @@ sub _openeuler_media_info return { distname => "openeuler$version", arch => $general{arch} }; } +# The second line of .discinfo, or '' when it is missing. +sub _discinfo_description +{ + my ($file) = @_; + open(my $fh, '<', $file) or return ''; + <$fh>; + my $description = <$fh>; + close($fh); + return '' unless defined($description); + chomp($description); + return $description; +} + sub _driver_disk_marker_path { @@ -2503,6 +2516,17 @@ sub copycd { $path = $defaultpath; } + # The RVA20 and RVA23 builds of an openEuler riscv64 release have the same + # .treeinfo identity. Only the .discinfo description tells them apart. + if ($openeuler_media && -r "$path/.discinfo") { + my $copied = _discinfo_description("$path/.discinfo"); + my $media = defined($desc) ? $desc : ''; + if (lc($copied) ne lc($media)) { + my $build = length($copied) ? $copied : 'no build name'; + $callback->({ error => "$path holds openEuler media of another build ($build). Copy this media to another directory with -p.", errorcode => [1] }); + return; + } + } if ($::XCATSITEVALS{osimagerequired}) { my ($nohaveimages, $errstr) = xCAT::SvrUtils->update_tables_with_templates($distname, $arch, $path, $osdistroname, checkonly => 1); if ($nohaveimages) { From c2af0283ab9e5bfa3f5731a987b64751a5f2f4df 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, 2 Nov 2026 18:27:24 -0300 Subject: [PATCH 065/114] test(anaconda): refuse to mix the RVA20 and RVA23 openEuler media copycds must refuse media of one build over a copy of the other, before it opens any table, and leave the copy unchanged. Media of the same build, in either case, a target without a copy and x86_64 media must copy on. --- xCAT-test/unit/anaconda_openeuler_media.t | 68 ++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/xCAT-test/unit/anaconda_openeuler_media.t b/xCAT-test/unit/anaconda_openeuler_media.t index 2733eb0c80..bd82a9a030 100644 --- a/xCAT-test/unit/anaconda_openeuler_media.t +++ b/xCAT-test/unit/anaconda_openeuler_media.t @@ -2,7 +2,8 @@ use strict; use warnings; -use File::Slurper qw(write_text); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); use File::Temp qw(tempdir); use FindBin; use Storable qw(dclone); @@ -143,4 +144,69 @@ ok(!xCAT_plugin::anaconda::using_dracut('openeuler24.09'), 'a non-LTS token is n is_deeply($request, $original, 'missing payload is rejected before claiming or changing media'); } +# Complete riscv64 media whose .discinfo names a build, as the RVA23 DVD does. +sub build_media { + my ($description, $arch) = @_; + $arch ||= 'riscv64'; + my $root = media_tree('24.03-LTS-SP3', $arch, '', $arch); + write_text("$root/.discinfo", "1234567890\n$description\n$arch\n"); + make_path("$root/images/pxeboot", "$root/repodata"); + write_text("$root/$_", "payload\n") + for qw(images/pxeboot/vmlinuz images/pxeboot/initrd.img images/install.img repodata/repomd.xml); + return $root; +} + +# Copies media to $target. The table stub stops a copy that passes the build +# check at its first table, before anything is written. +sub copy_media { + my ($media, $target) = @_; + my $request = { command => ['copycd'], arg => ['-m', $media, '-p', $target] }; + my (@responses, $output, $stopped); + { + open(my $stdout, '>', \$output) or die "open scalar output: $!"; + local *STDOUT = $stdout; + no warnings 'redefine'; + local *xCAT::Table::new = sub { + my ($class, $table, @args) = @_; + die "copy reached table $table\n" if $table ne 'site' || @args; + return bless {}, 'Local::OpenEulerSite'; + }; + local *xCAT::TableUtils::get_site_attribute = sub { return '/unused-install-root'; }; + eval { + xCAT_plugin::anaconda::process_request($request, sub { push @responses, @_ }, sub { + die "copy dispatched a request\n"; + }); + 1; + } or $stopped = $@; + } + return (\@responses, $stopped); +} + +sub copied_target { + my ($description) = @_; + my $target = tempdir(CLEANUP => 1); + write_text("$target/.discinfo", "1234567800\n$description\nriscv64\n") if defined $description; + return $target; +} + +for my $case (['RVA23', '', 'RVA23'], ['', 'RVA23', 'no build name']) { + my ($copied, $media, $named) = @$case; + my $target = copied_target($copied); + my ($responses, $stopped) = copy_media(build_media($media), $target); + like($responses->[0]{error} || '', qr/\Q$target\E holds openEuler media of another build \(\Q$named\E\)/, + "media of build '$media' are refused over a copy of build '$copied'"); + is_deeply($responses->[0]{errorcode}, [1], 'the refusal reports failure'); + is($stopped, undef, 'the refusal comes before any table is opened'); + is(read_text("$target/.discinfo"), "1234567800\n$copied\nriscv64\n", 'the existing copy is unchanged'); +} + +for my $case (['RVA23', 'RVA23', 'riscv64'], ['rva23', 'RVA23', 'riscv64'], [undef, 'RVA23', 'riscv64'], + ['', '', 'x86_64']) { + my ($copied, $media, $arch) = @$case; + my $label = defined $copied ? "a copy of build '$copied'" : 'an empty target'; + my ($responses, $stopped) = copy_media(build_media($media, $arch), copied_target($copied)); + ok(!grep({ ($_->{error} // '') =~ /another build/ } @$responses), "$arch media of build '$media' copy over $label"); + is($stopped, "copy reached table osdistro\n", 'the copy continues past the build check'); +} + done_testing(); From e95818d9287426fa6445a114b9ca81c66c72bc77 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, 2 Nov 2026 18:27:32 -0300 Subject: [PATCH 066/114] docs(openeuler): say that copycds refuses mixed riscv64 builds The openEuler guide now says that copycds refuses to copy the RVA20 and RVA23 builds of a release over each other, and that -p copies the second build to another directory. --- .../admin-guides/manage_clusters/openeuler/index.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst b/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst index d1ec78f1a4..84ed7174ec 100644 --- a/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst +++ b/docs/source/guides/admin-guides/manage_clusters/openeuler/index.rst @@ -51,9 +51,10 @@ management and service nodes are outside it. The test hardware could not boot from the network, so firmware network boot is not qualified either. See :doc:`/guides/admin-guides/manage_clusters/riscv64/index`. -openEuler also publishes RVA20 media for riscv64. ``copycds`` copies both -builds of a release to the same directory, so import only the build that -matches the nodes. +openEuler also publishes RVA20 media for riscv64. Both builds of a release +have the same target directory, and ``copycds`` refuses to copy one over the +other. Import the build that matches the nodes, or copy the other build to +another directory with ``-p``. The tested provisioning networks use IPv4 and ISC DHCP on isolated links, with separate upstream and downstream interfaces on service nodes. The From 1f990063f5d37f7f8124bbb2ccae6258cb8e7b05 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, 29 Oct 2026 22:08:54 -0300 Subject: [PATCH 067/114] fix(ubuntu): apply partitionfile entries on Subiquity installs linuximage.partitionfile had no effect on Ubuntu 20.04 and later installs. The Subiquity pre-install script decodes each entry with base64decode, which uses read -n, and Subiquity runs the script under dash, which has no read -n. A layout file decoded to an empty storage config, which stops the install, and a layout script or disk script decoded to nothing. The d: and s:d: disk step also ran after the script had written the storage config, so a disk file could not change the disk that getinstdisk chose, which prefers a disk that already holds an operating system. Decode with coreutils base64, which the live system ships, and run the disk step before the storage config is written. The storage config uses the first disk the disk file names, because the layout uses one disk, and names it by its device node: Subiquity matches the path literally and finds no disk for a /dev/disk/by-id link. --- .../xcat/install/scripts/pre.ubuntu.subiquity | 67 +++---------------- 1 file changed, 11 insertions(+), 56 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity index 92707fb716..be79dbe1c7 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity +++ b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity @@ -139,63 +139,15 @@ chmod 755 /tmp/foo.sh /tmp/foo.sh >/tmp/foo.log 2>&1 & +# Subiquity runs this script under dash, which has no read -n, and its live system ships coreutils. base64decode() { - h0="0"; h1="1"; h2="2"; h3="3"; h4="4"; h5="5"; h6="6"; h7="7"; - h8="8"; h9="9"; h10="A"; h11="B"; h12="C"; h13="D"; h14="E"; h15="F"; - - while : - do - i=0 - while [ "$i" -lt 4 ] - do - read -n 1 c || return - - case "${c}" in - "A") d=0 ;; "B") d=1 ;; "C") d=2 ;; "D") d=3 ;; - "E") d=4 ;; "F") d=5 ;; "G") d=6 ;; "H") d=7 ;; - "I") d=8 ;; "J") d=9 ;; "K") d=10 ;; "L") d=11 ;; - "M") d=12 ;; "N") d=13 ;; "O") d=14 ;; "P") d=15 ;; - "Q") d=16 ;; "R") d=17 ;; "S") d=18 ;; "T") d=19 ;; - "U") d=20 ;; "V") d=21 ;; "W") d=22 ;; "X") d=23 ;; - "Y") d=24 ;; "Z") d=25 ;; "a") d=26 ;; "b") d=27 ;; - "c") d=28 ;; "d") d=29 ;; "e") d=30 ;; "f") d=31 ;; - "g") d=32 ;; "h") d=33 ;; "i") d=34 ;; "j") d=35 ;; - "k") d=36 ;; "l") d=37 ;; "m") d=38 ;; "n") d=39 ;; - "o") d=40 ;; "p") d=41 ;; "q") d=42 ;; "r") d=43 ;; - "s") d=44 ;; "t") d=45 ;; "u") d=46 ;; "v") d=47 ;; - "w") d=48 ;; "x") d=49 ;; "y") d=50 ;; "z") d=51 ;; - "0") d=52 ;; "1") d=53 ;; "2") d=54 ;; "3") d=55 ;; - "4") d=56 ;; "5") d=57 ;; "6") d=58 ;; "7") d=59 ;; - "8") d=60 ;; "9") d=61 ;; "+") d=62 ;; "/") d=63 ;; - "=") d=0 ;; - *) continue ;; - esac - - eval "a${i}=${c}" - eval "b${i}=${d}" - - i=$(( i + 1 )) - done - - o0=$(( ((b0 << 2) | (b1 >> 4)) & 0xff )) - o1=$(( ((b1 << 4) | (b2 >> 2)) & 0xff )) - o2=$(( ((b2 << 6) | b3) & 0xff )) - - [ "${a2}" == "=" ] && - eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 - ))}\"" && - return - [ "${a3}" == "=" ] && - eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 - ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16 - ))}\"" && - return - eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16 - ))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16 - ))}\\x\${h$(( o2 / 16 ))}\${h$(( o2 % 16 ))}\"" - done + base64 -d } + +# A d: or s:d: entry in linuximage.partitionfile replaces the disk getinstdisk chose. +#XCA_PARTMAN_DISK_SCRIPT# + # Note that the subiquity/curtin installation config is fairly picky about # the order in which things are specified - you have to specify all the # partitions before you can specify any filesystems, which means this is @@ -211,7 +163,10 @@ base64decode() # to this unwrapped file and must start at column 0. logger -t $log_label -p "info" "Generate partition file..." if [ -e /tmp/xcat.install_disk ]; then - INSTALL_DISK=$(cat /tmp/xcat.install_disk) + # The layout uses one disk, the first one the disk file names. + INSTALL_DISK=$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk) + # Subiquity matches the disk path literally, so resolve a link such as /dev/disk/by-id/. + INSTALL_DISK=$(readlink -f "$INSTALL_DISK" || echo "$INSTALL_DISK") else logger -t $log_label -p "err" "Failed to find partition file - getinstdisk must be run first" logger -t $log_label -p "err" "Using fallback default disk /dev/sda" @@ -385,8 +340,8 @@ storage: EOF fi +# A partitionfile layout or s: script must come after the default layout, which it replaces. #XCA_PARTMAN_RECIPE_SCRIPT# -#XCA_PARTMAN_DISK_SCRIPT# #XCA_PARTMAN_ADDITIONAL_CONFIG_SCRIPT# exit 0 From 94fb370ee4e30d50b45598fe7f009ed92f08e9e6 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, 29 Oct 2026 22:08:55 -0300 Subject: [PATCH 068/114] test(ubuntu): cover partitionfile entries on Subiquity installs Render the node's pre-install script through the Template entry point and run its partitioning under dash. Without a partitionfile the storage config keeps the disk getinstdisk chose. A disk file puts its first disk there, resolved when it is a link, a disk script puts the disk it writes there, and a layout file or layout script replaces the default storage config. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/README.md | 7 +- .../native/ubuntu_subiquity_install_disk.t | 85 +++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 xCAT-test/native/ubuntu_subiquity_install_disk.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index a61196daa7..2fb86641ef 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -104,7 +104,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index e875373802..8d03a9db8b 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -422,13 +422,14 @@ prove xCAT-test/native/install_profile_riscv64.t \ xCAT-test/native/netboot_profile_riscv64.t \ xCAT-test/native/netboot_profile_postinstall.t \ xCAT-test/native/builddebs_riscv64.t \ - xCAT-test/native/ubuntu_subiquity_template.t + xCAT-test/native/ubuntu_subiquity_template.t \ + xCAT-test/native/ubuntu_subiquity_install_disk.t ``` The renderers need the system Perl with the xCAT dependencies, XML::Simple, DBD::SQLite, Capture::Tiny, and File::Slurper. The sandbox clears the environment -and does not mount perlbrew or local::lib directories. The Subiquity case also -needs /usr/bin/python3 with PyYAML; on EL8, install python36 for that path. +and does not mount perlbrew or local::lib directories. The Subiquity cases also +need /usr/bin/python3 with PyYAML; on EL8, install python36 for that path. The Debian case needs debhelper, devscripts, fakeroot, and reprepro, and skips on non-Debian hosts. Each case creates its own temporary files and database. The temporary directory must allow execution; set TMPDIR if /tmp is noexec. diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t new file mode 100644 index 0000000000..3a5c19480a --- /dev/null +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -0,0 +1,85 @@ +#!/usr/bin/env perl +# The storage config a Subiquity install receives for each linuximage.partitionfile form. +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database render_template); + +plan skip_all => 'installer execution requires Linux namespaces' unless $^O eq 'linux'; +my $database = template_database(); +# Subiquity runs its early commands under dash. +my ($shell) = grep { -x $_ } qw(/usr/bin/dash /bin/dash /bin/sh); +my $sequence = 0; + +sub render_part { + my ($script, $pattern, @entries) = @_; + my $dir = "$database/case-" . ++$sequence; + make_path($dir); + my @partitionfile; + for my $n (0 .. $#entries) { + my ($prefix, $contents) = @{ $entries[$n] }; + write_text("$dir/partition-$n", $contents); + push @partitionfile, "$prefix$dir/partition-$n"; + } + render_template($database, repo_path("xCAT-server/share/xcat/install/scripts/$script"), "$dir/node.pre", + 'node', '', '', '', join(',', @partitionfile), {xcatmaster => '192.0.2.1'}); + my ($part) = read_text("$dir/node.pre") =~ $pattern; + return $part; +} + +# getinstdisk has already chosen /dev/sdz. +sub installer_root { + my $root = sandbox_root(); + make_path("$root/efi", "$root/by-id"); + write_text("$root/bin/logger", "#!/bin/sh\nexit 0\n"); + chmod 0755, "$root/bin/logger" or die $!; + write_text("$root/tmp/xcat.install_disk", "/dev/sdz\n"); + write_text("$root/nvme7n1", ''); + symlink('../../nvme7n1', "$root/by-id/nvme-link") or die $!; + return $root; +} + +sub storage_config { + my ($root) = @_; + return -e "$root/tmp/partitionfile" ? read_text("$root/tmp/partitionfile") : ''; +} + +# Written as PyYAML writes it, so it reads the same before and after the pre-script rewrites it. +my $layout = "storage:\n version: 1\n config:\n - id: custom-disk\n type: disk\n path: /dev/disk/by-id/custom\n"; +my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n"; +my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n"; + +# Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage +# config must name. +my @cases = ( + ['no partitionfile', [], '/dev/sdz'], + ['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'], + ['a disk file naming a link', [['d:', "/dev/disk/by-id/nvme-link\n"]], '/dev/nvme7n1'], + ['a disk script', [['s:d:', $diskscript]], '/dev/disk/by-id/scripted'], + ['a layout file', [['', $layout]], '/dev/disk/by-id/custom'], + ['a layout script', [['s:', $writer]], '/dev/disk/by-id/custom'], +); +for my $case (@cases) { + my ($label, $entries, $expected) = @$case; + subtest $label => sub { + my $part = render_part('pre.ubuntu.subiquity', qr/(^base64decode\(\)\n.*^exit 0$)/ms, @$entries); + ok($part, 'the rendered script defines base64decode before the partitioning') or return; + my $root = installer_root(); + write_text("$root/part.sh", $part); + my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi', + "$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh'); + is($rc, 0, "the partitioning runs under $shell") or diag($output); + my $config = storage_config($root); + my ($disk) = $config =~ /^\s+type: disk\n(?:\s+\S+:.*\n)*?\s+path: (\S+)$/m; + is($disk, $expected, "the storage config partitions $expected"); + is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom'; + }; +} +done_testing(); From e87c72c38d6ed9331fd1d08ac85536e79fcc70ee 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, 29 Oct 2026 22:42:40 -0300 Subject: [PATCH 069/114] fix(template): read each partitionfile entry with its own s: prefix linuximage.partitionfile takes a comma-separated list of layout, d: disk and c: configuration entries, any of them prefixed with s: for a script. The Ubuntu layout step chose between decoding a layout file and running a layout script by the s: prefix of the last entry in the whole list, so a layout file followed by an s:d: disk script was run as a script, and a layout script followed by a d: disk file was copied into the layout as text. The parser also kept a script flag set by an earlier entry of the same kind after a later entry replaced it. Give each kind the prefix of the entry that is used, the last one of that kind, and decode the Ubuntu layout by it. --- xCAT-server/lib/perl/xCAT/Template.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 747ba01e04..d332a91f5e 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -224,15 +224,16 @@ sub subvars { $filepath = $1; } + # The last entry of each kind wins, with its own s: prefix. if ($filepath =~ /^d:(.*)/) { - $diskfile = $1; - if ($scriptflag) { $diskscriptflag = 1; } + $diskfile = $1; + $diskscriptflag = $scriptflag; } elsif ($filepath =~ /^c:(.*)/) { - $configfile = $1; - if ($scriptflag) { $configscriptflag = 1; } + $configfile = $1; + $configscriptflag = $scriptflag; } elsif ($filepath) { - $partitionfile = $filepath; - if ($scriptflag) { $partscriptflag = 1; } + $partitionfile = $filepath; + $partscriptflag = $scriptflag; } } @@ -483,7 +484,7 @@ sub subvars { # Put the base64 coded partitionfile into %pre part $partcontent = "cat > /tmp/partscript.enc << EOFEOF\n" . $partcontent . "\nEOFEOF\n"; - if ($scriptflag) { + if ($partscriptflag) { # Put the code to decode preseed script and run it to generate pressed recipe file #$partcontent .= "python -c 'import base64; print base64.b64decode(open(\"/tmp/partscript.enc\",\"rb\").read())' >/tmp/partscript\n"; From ff870a0723a010bea7ec28a704264b8684ff4387 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, 29 Oct 2026 22:42:41 -0300 Subject: [PATCH 070/114] test(template): cover partitionfile entries read with their own s: prefix A layout file followed by a disk script and a layout script followed by a disk file each replace the default storage config with the administrator layout. A layout file after a layout script and a disk file after a disk script are read as files, on Subiquity and in the debian-installer recipe step. --- .../native/ubuntu_subiquity_install_disk.t | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t index 3a5c19480a..84de4aa2e5 100644 --- a/xCAT-test/native/ubuntu_subiquity_install_disk.t +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -65,6 +65,11 @@ my @cases = ( ['a disk script', [['s:d:', $diskscript]], '/dev/disk/by-id/scripted'], ['a layout file', [['', $layout]], '/dev/disk/by-id/custom'], ['a layout script', [['s:', $writer]], '/dev/disk/by-id/custom'], + ['a layout file after a layout script', [['s:', "#!/bin/sh\nexit 0\n"], ['', $layout]], '/dev/disk/by-id/custom'], + ['a disk file after a disk script', [['s:d:', "#!/bin/sh\nexit 0\n"], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], + '/dev/disk/by-id/nvme-pinned'], + ['a layout file before a disk script', [['', $layout], ['s:d:', $diskscript]], '/dev/disk/by-id/custom'], + ['a layout script before a disk file', [['s:', $writer], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], '/dev/disk/by-id/custom'], ); for my $case (@cases) { my ($label, $entries, $expected) = @$case; @@ -82,4 +87,16 @@ for my $case (@cases) { is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom'; }; } + +# The debian-installer path renders the same entries into pre.ubuntu, under a shell with read -n. +subtest 'a debian-installer recipe file after a recipe script' => sub { + my $part = render_part('pre.ubuntu', qr/(^base64decode\(\)\n.*?^exit 0$)/ms, + ['s:', "#!/bin/sh\nexit 0\n"], ['', "recipe ::\n .\n"]); + ok($part, 'the rendered script defines base64decode before the recipe') or return; + my $root = installer_root(); + write_text("$root/part.sh", $part); + my ($rc, $output) = sandbox_run($root, '/bin/bash', '/fixture/part.sh'); + is($rc, 0, 'the recipe step runs') or diag($output); + is(storage_config($root), "recipe ::\n .\n", 'the later recipe file replaces the default recipe'); +}; done_testing(); From 45546220be063025b445d282af3d6a0391c30cc6 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, 29 Oct 2026 23:06:05 -0300 Subject: [PATCH 071/114] fix(ubuntu): stop a Subiquity install when a partitionfile entry fails A disk script or layout script that failed, or a disk or layout entry that held nothing usable, left the disk getinstdisk chose or the default layout in place, and the install went on to wipe that disk. A layout whose storage section is missing or empty is worse: Subiquity then puts LVM on the largest disk. The entry exists to keep the install off some disks, so these fallbacks can destroy the disk it protects. A valid layout that started a YAML document also broke the install, because it was appended to autoinstall.yaml as a second document. When a disk or layout entry is configured, require it to succeed and to write a disk name, or a storage section with a config or a layout, and stop the pre-install script with an error otherwise. Subiquity then stops before it partitions. Rewrite an accepted layout as a YAML fragment that holds only the storage section. Without an entry, the detected disk and the default layout are used as before. --- .../xcat/install/scripts/pre.ubuntu.subiquity | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity index be79dbe1c7..cddbed7d89 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity +++ b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity @@ -146,7 +146,19 @@ base64decode() } # A d: or s:d: entry in linuximage.partitionfile replaces the disk getinstdisk chose. +rm -f /tmp/diskscript.enc +[ -e /tmp/xcat.install_disk ] && mv /tmp/xcat.install_disk /tmp/xcat.install_disk.detected #XCA_PARTMAN_DISK_SCRIPT# +override_rc=$? +if [ -e /tmp/diskscript.enc ]; then + # Falling back to the detected disk could wipe the disk the entry protects. + if [ "$override_rc" -ne 0 ] || [ -z "$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk 2>/dev/null)" ]; then + logger -t $log_label -p "err" "The partitionfile disk entry selected no disk, stopping the install" + exit 1 + fi +elif [ -e /tmp/xcat.install_disk.detected ]; then + mv /tmp/xcat.install_disk.detected /tmp/xcat.install_disk +fi # Note that the subiquity/curtin installation config is fairly picky about # the order in which things are specified - you have to specify all the @@ -340,8 +352,33 @@ storage: EOF fi +# Keep only a storage section that holds a config or a layout, rewritten as one YAML fragment +# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing. +normalize_storage_layout() +{ + python3 -c 'import sys, yaml +s = yaml.safe_load(open(sys.argv[1])) +t = s.get("storage") if isinstance(s, dict) else None +if not (isinstance(t, dict) and (t.get("config") or t.get("layout"))): + sys.exit(1) +open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" 2>/dev/null +} + # A partitionfile layout or s: script must come after the default layout, which it replaces. +rm -f /tmp/partscript.enc +mv /tmp/partitionfile /tmp/partitionfile.default #XCA_PARTMAN_RECIPE_SCRIPT# +override_rc=$? +if [ -e /tmp/partscript.enc ]; then + # Keeping the default layout could wipe a disk the administrator layout protects. + if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile; then + logger -t $log_label -p "err" "The partitionfile layout entry wrote no layout, stopping the install" + rm -f /tmp/partitionfile + exit 1 + fi +else + mv /tmp/partitionfile.default /tmp/partitionfile +fi #XCA_PARTMAN_ADDITIONAL_CONFIG_SCRIPT# exit 0 From 1d378818dd822731527e667beb9ef540f3c95785 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, 29 Oct 2026 23:06:20 -0300 Subject: [PATCH 072/114] test(ubuntu): cover a failed partitionfile entry on Subiquity installs A disk script or layout script that fails, or that writes no disk or layout, and a disk file or layout file that holds only blank lines, comments or an empty storage section each stop the pre-install script and leave no storage config for Subiquity. A layout file that starts a YAML document still leaves autoinstall.yaml one document. --- .../native/ubuntu_subiquity_install_disk.t | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t index 84de4aa2e5..dbcf016365 100644 --- a/xCAT-test/native/ubuntu_subiquity_install_disk.t +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -57,7 +57,7 @@ my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n"; my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n"; # Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage -# config must name. +# config must name, or undef when the install must stop before a storage config exists. my @cases = ( ['no partitionfile', [], '/dev/sdz'], ['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'], @@ -70,6 +70,16 @@ my @cases = ( '/dev/disk/by-id/nvme-pinned'], ['a layout file before a disk script', [['', $layout], ['s:d:', $diskscript]], '/dev/disk/by-id/custom'], ['a layout script before a disk file', [['s:', $writer], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], '/dev/disk/by-id/custom'], + ['a disk script that fails', [['s:d:', "#!/bin/sh\nexit 42\n"]], undef], + ['a disk script that selects no disk', [['s:d:', "#!/bin/sh\nexit 0\n"]], undef], + ['a layout script that fails', [['s:', "#!/bin/sh\nexit 42\n"]], undef], + ['a layout script that writes no layout', [['s:', "#!/bin/sh\nexit 0\n"]], undef], + ['a layout file with only blank lines', [['', "\n \n"]], undef], + ['a layout file with only comments', [['', "# no layout yet\n"]], undef], + ['a disk file with only blank lines', [['d:', " \n\n"]], undef], + ['a layout file with an empty storage section', [['', "storage:\n"]], undef], + ['a layout file with a null storage section', [['', "storage: null\n"]], undef], + ['a layout file that starts a YAML document', [['', "---\n$layout"]], '/dev/disk/by-id/custom'], ); for my $case (@cases) { my ($label, $entries, $expected) = @$case; @@ -80,11 +90,20 @@ for my $case (@cases) { write_text("$root/part.sh", $part); my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi', "$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh'); + if (!defined $expected) { + isnt($rc, 0, "the pre-install script fails under $shell"); + ok(!-e "$root/tmp/partitionfile", 'and leaves no storage config to inject'); + return; + } is($rc, 0, "the partitioning runs under $shell") or diag($output); my $config = storage_config($root); my ($disk) = $config =~ /^\s+type: disk\n(?:\s+\S+:.*\n)*?\s+path: (\S+)$/m; is($disk, $expected, "the storage config partitions $expected"); is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom'; + # The early command appends the storage config to Subiquity's autoinstall.yaml. + write_text("$root/autoinstall.yaml", "version: 1\nidentity:\n hostname: node\n$config"); + is(system('/usr/bin/python3', '-I', '-c', 'import sys, yaml; sys.exit("storage" not in yaml.safe_load(open(sys.argv[1])))', + "$root/autoinstall.yaml"), 0, 'autoinstall.yaml stays one YAML document with a storage section'); }; } From f1d8641672330f3266aa77bacbc8ef93ca31c1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:15:59 -0300 Subject: [PATCH 073/114] fix(ubuntu): keep a partitionfile layout on the partitionfile disk A Subiquity layout written with "layout:" and no "match" goes to the largest disk. With a d: or s:d: entry in linuximage.partitionfile, that disk need not be the one the entry selected, so the install could wipe a disk the entry was meant to keep it off. When a disk entry is configured, give such a layout a match on the selected disk. Refuse a use_gap layout in that case, because some Subiquity releases ignore match in use_gap mode and would install into free space on another disk. A layout with its own match, a "config:" layout and a layout without a disk entry are kept as written. --- .../xcat/install/scripts/pre.ubuntu.subiquity | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity index cddbed7d89..90b3e363b1 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity +++ b/xCAT-server/share/xcat/install/scripts/pre.ubuntu.subiquity @@ -150,7 +150,9 @@ rm -f /tmp/diskscript.enc [ -e /tmp/xcat.install_disk ] && mv /tmp/xcat.install_disk /tmp/xcat.install_disk.detected #XCA_PARTMAN_DISK_SCRIPT# override_rc=$? +disk_entry="" if [ -e /tmp/diskscript.enc ]; then + disk_entry=1 # Falling back to the detected disk could wipe the disk the entry protects. if [ "$override_rc" -ne 0 ] || [ -z "$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk 2>/dev/null)" ]; then logger -t $log_label -p "err" "The partitionfile disk entry selected no disk, stopping the install" @@ -353,7 +355,9 @@ EOF fi # Keep only a storage section that holds a config or a layout, rewritten as one YAML fragment -# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing. +# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing, +# and a layout without a match goes to the largest disk too, so it gets the disk in $2, if any. +# Some Subiquity releases ignore match in use_gap mode, so such a layout is refused with $2. normalize_storage_layout() { python3 -c 'import sys, yaml @@ -361,7 +365,12 @@ s = yaml.safe_load(open(sys.argv[1])) t = s.get("storage") if isinstance(s, dict) else None if not (isinstance(t, dict) and (t.get("config") or t.get("layout"))): sys.exit(1) -open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" 2>/dev/null +l = t.get("layout") +if sys.argv[2] and isinstance(l, dict): + if l.get("mode") == "use_gap": + sys.exit(1) + l.setdefault("match", {"path": sys.argv[2]}) +open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" "$2" 2>/dev/null } # A partitionfile layout or s: script must come after the default layout, which it replaces. @@ -371,8 +380,8 @@ mv /tmp/partitionfile /tmp/partitionfile.default override_rc=$? if [ -e /tmp/partscript.enc ]; then # Keeping the default layout could wipe a disk the administrator layout protects. - if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile; then - logger -t $log_label -p "err" "The partitionfile layout entry wrote no layout, stopping the install" + if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile "${disk_entry:+$INSTALL_DISK}"; then + logger -t $log_label -p "err" "The partitionfile layout entry wrote no usable layout, stopping the install" rm -f /tmp/partitionfile exit 1 fi From 75c874ebadd4aac99d92b142ebdd60789b335f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:15:59 -0300 Subject: [PATCH 074/114] test(ubuntu): cover a partitionfile layout on the partitionfile disk A layout without a match that follows a disk file gets a match on the disk the file selects, resolved when it is a link, and a use_gap layout that follows a disk file stops the install. A layout with its own match and a layout without a disk entry are kept as written. --- .../native/ubuntu_subiquity_install_disk.t | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t index dbcf016365..1131c30629 100644 --- a/xCAT-test/native/ubuntu_subiquity_install_disk.t +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -57,7 +57,8 @@ my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n"; my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n"; # Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage -# config must name, or undef when the install must stop before a storage config exists. +# config must name, or undef when the install must stop before a storage config exists. A fourth +# value is the whole storage config of a layout. my @cases = ( ['no partitionfile', [], '/dev/sdz'], ['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'], @@ -80,9 +81,19 @@ my @cases = ( ['a layout file with an empty storage section', [['', "storage:\n"]], undef], ['a layout file with a null storage section', [['', "storage: null\n"]], undef], ['a layout file that starts a YAML document', [['', "---\n$layout"]], '/dev/disk/by-id/custom'], + ['a layout without a match after a disk file', [['', "storage:\n layout:\n name: direct\n"], + ['d:', "/dev/disk/by-id/nvme-link\n"]], undef, + "storage:\n layout:\n name: direct\n match:\n path: /dev/nvme7n1\n"], + ['a layout with its own match after a disk file', [['', "storage:\n layout:\n name: direct\n match:\n ssd: true\n"], + ['d:', "/dev/disk/by-id/nvme-link\n"]], undef, + "storage:\n layout:\n name: direct\n match:\n ssd: true\n"], + ['a layout without a match and no disk entry', [['', "storage:\n layout:\n name: direct\n"]], undef, + "storage:\n layout:\n name: direct\n"], + ['a use_gap layout after a disk file', [['', "storage:\n layout:\n name: direct\n mode: use_gap\n"], + ['d:', "/dev/disk/by-id/nvme-link\n"]], undef], ); for my $case (@cases) { - my ($label, $entries, $expected) = @$case; + my ($label, $entries, $expected, $expected_layout) = @$case; subtest $label => sub { my $part = render_part('pre.ubuntu.subiquity', qr/(^base64decode\(\)\n.*^exit 0$)/ms, @$entries); ok($part, 'the rendered script defines base64decode before the partitioning') or return; @@ -90,6 +101,11 @@ for my $case (@cases) { write_text("$root/part.sh", $part); my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi', "$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh'); + if (defined $expected_layout) { + is($rc, 0, "the partitioning runs under $shell") or diag($output); + is(storage_config($root), $expected_layout, 'the storage config is the expected layout'); + return; + } if (!defined $expected) { isnt($rc, 0, "the pre-install script fails under $shell"); ok(!-e "$root/tmp/partitionfile", 'and leaves no storage config to inject'); From 00fb5843cff281f063bad553a0f9bc662c054176 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, 29 Oct 2026 22:11:42 -0300 Subject: [PATCH 075/114] docs(ubuntu): describe partitionfile on Subiquity installs State that on Subiquity installs the partition definition file or script provides a curtin storage section that replaces the default layout, that a layout without a match is restricted to the disk a disk entry selects, that a failed layout or disk entry stops the install, that the first disk of a disk file is used, and that a disk script runs in the live installer under dash. Name the file that the disk file and the disk script write as /tmp/xcat.install_disk, which both Ubuntu installers read, instead of /tmp/install_disk. --- .../common/deployment/cfg_partition.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst b/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst index 82767e6d5e..fe5a2090df 100644 --- a/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst +++ b/docs/source/guides/admin-guides/manage_clusters/common/deployment/cfg_partition.rst @@ -9,6 +9,8 @@ By default, xCAT will attempt to determine the first physical disk and use a gen .. warning:: **partition definition script** has only been verified on RedHat and Ubuntu, use at your own risk for SLES. +.. note:: Ubuntu 20.04 and later install with Subiquity. There the partition definition file, or the file the partition definition script writes to ``/tmp/partitionfile``, holds a curtin ``storage:`` section with a ``config`` or ``layout`` entry instead of a partman recipe. The installer keeps only that section, and it replaces the default layout. With a partition disk file or script as well, a ``layout`` without a ``match`` is restricted to the disk it selects, and a ``use_gap`` layout is refused. A layout or disk entry that fails, or that writes no layout or disk, stops the install before it partitions. The additional preseed configuration applies to the debian-installer only. + .. END_Overview @@ -480,13 +482,14 @@ If not specified, the default value will be used. nodeset osimage= - the ``d:`` preceding the filename tells nodeset that this is a partition disk file. -- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, it will generate a script to write the content of the partition disk file to ``/tmp/install_disk``, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/.pre``. +- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, it will generate a script to write the content of the partition disk file to ``/tmp/xcat.install_disk``, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/.pre``. +- A Subiquity install partitions only the first disk the file names. Use a ``/dev/disk/by-id/`` name when the kernel can enumerate the disks in a different order at each boot. .. END_Partition_Disk_File_ubuntu_only .. BEGIN_Partition_Disk_Script_ubuntu_only -The disk script contains a script to generate a partitioning disk file named ``/tmp/install_disk``. for example: :: +The disk script contains a script to generate a partitioning disk file named ``/tmp/xcat.install_disk``. for example: :: rm /tmp/devs-with-boot 2>/dev/null || true; for d in $(list-devices partition); do @@ -499,12 +502,12 @@ The disk script contains a script to generate a partitioning disk file named ``/ fi done; if [[ -e /tmp/devs-with-boot ]]; then - head -n1 /tmp/devs-with-boot | egrep -o '\S+[^0-9]' > /tmp/install_disk; + head -n1 /tmp/devs-with-boot | egrep -o '\S+[^0-9]' > /tmp/xcat.install_disk; rm /tmp/devs-with-boot 2>/dev/null || true; else DEV=`ls /dev/disk/by-path/* -l | egrep -o '/dev.*[s|h|v]d[^0-9]$' | sort -t : -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -g | head -n1 | egrep -o '[s|h|v]d.*$'`; if [[ "$DEV" == "" ]]; then DEV="sda"; fi; - echo "/dev/$DEV" > /tmp/install_disk; + echo "/dev/$DEV" > /tmp/xcat.install_disk; fi; If not specified, the default value will be used. @@ -516,6 +519,7 @@ If not specified, the default value will be used. - the ``s:`` prefix tells ``nodeset`` that is a script, the ``s:d:`` preceding the filename tells ``nodeset`` that this is a script to generate the partition disk file. - For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/.pre``. +- A Subiquity install runs the script in the live installer system, under ``dash`` unless its first line names another interpreter. ``list-devices``, which the example uses, exists only in the debian-installer. .. END_Partition_Disk_Script_ubuntu_only From 1c2a71d250b0901d21875116114b6cae45e69268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 18:08:11 -0300 Subject: [PATCH 076/114] test(scriptlib): run the NetworkManager autoconnect test in a sandbox The unit test sourced scriptlib in the host Bash, with a fake nmcli first in the host PATH. It now runs the helper with sandbox_run in xCAT-test/native, and the pull-request workflow runs it in its own step. --- .github/workflows/xcat_test.yml | 3 ++ xCAT-test/native/README.md | 8 +++ .../networkmanager_autoconnect.t | 49 ++++++++++--------- 3 files changed, 36 insertions(+), 24 deletions(-) rename xCAT-test/{unit => native}/networkmanager_autoconnect.t (77%) diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index a61196daa7..07e6e507e1 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -69,6 +69,9 @@ jobs: - name: Exercise the UFTP listener if: ${{ !cancelled() }} run: prove xCAT-test/native/uftp_listener.t + - name: Exercise the install script library + if: ${{ !cancelled() }} + run: prove xCAT-test/native/networkmanager_autoconnect.t - name: Run tests if: ${{ !cancelled() }} run: perl github_action_xcat_test.pl diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index e875373802..2ffa12cd1b 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -247,6 +247,14 @@ answers what the store answers for each path it measures. Check the TAP output for skipped prerequisites. A successful `prove` exit with skipped cases does not qualify those cases. +`networkmanager_autoconnect.t` runs the NetworkManager helper of the install +script library under Bash, with an `nmcli` command fixture, in a private +filesystem. It needs Bubblewrap and unprivileged user namespaces: + +``` +prove xCAT-test/native/networkmanager_autoconnect.t +``` + ## FIPS policy and discovery keys Run the unchanged statelite and Cumulus callers in private filesystems: diff --git a/xCAT-test/unit/networkmanager_autoconnect.t b/xCAT-test/native/networkmanager_autoconnect.t similarity index 77% rename from xCAT-test/unit/networkmanager_autoconnect.t rename to xCAT-test/native/networkmanager_autoconnect.t index 8864bf53a7..744eba7164 100644 --- a/xCAT-test/unit/networkmanager_autoconnect.t +++ b/xCAT-test/native/networkmanager_autoconnect.t @@ -2,15 +2,16 @@ use strict; use warnings; -use File::Path qw(make_path); use File::Slurper qw(read_binary write_binary); use File::Spec; -use File::Temp qw(tempdir); use FindBin; use lib "$FindBin::Bin/../lib"; use Test::More; use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); + +plan skip_all => 'scriptlib execution requires Linux namespaces' unless $^O eq 'linux'; my $scriptlib = repo_path( File::Spec->catfile( @@ -19,17 +20,14 @@ my $scriptlib = repo_path( ); -r $scriptlib or die("$scriptlib is required"); -is( system( 'bash', '-n', $scriptlib ), 0, +my $root = sandbox_root(); +is( ( sandbox_run( $root, { read_only => { $scriptlib => '/scriptlib' } }, + '/bin/bash', '-n', '/scriptlib' ) )[0], 0, 'the install script library has valid Bash syntax' ); -my $tmpdir = tempdir( CLEANUP => 1 ); -my $test_bin = File::Spec->catdir( $tmpdir, 'bin' ); -my $empty_bin = File::Spec->catdir( $tmpdir, 'empty-bin' ); -make_path( $test_bin, $empty_bin ); - -my $nmcli_log = File::Spec->catfile( $tmpdir, 'nmcli.log' ); -my $message_log = File::Spec->catfile( $tmpdir, 'messages.log' ); -my $fake_nmcli = File::Spec->catfile( $test_bin, 'nmcli' ); +my $nmcli_log = File::Spec->catfile( $root, 'nmcli.log' ); +my $message_log = File::Spec->catfile( $root, 'messages.log' ); +my $fake_nmcli = File::Spec->catfile( $root, 'bin', 'nmcli' ); write_binary( $fake_nmcli, <<'SH' ); #!/bin/sh { @@ -47,8 +45,7 @@ fi SH chmod 0755, $fake_nmcli or die "Unable to make $fake_nmcli executable: $!"; -my $driver = File::Spec->catfile( $tmpdir, 'run-helper' ); -write_binary( $driver, <<'SH' ); +write_binary( File::Spec->catfile( $root, 'run-helper' ), <<'SH' ); #!/bin/bash msgutil_r() { { @@ -62,7 +59,7 @@ msgutil_r() { . "$XCAT_TEST_SCRIPTLIB" xcat_enable_active_nm_autoconnect "$@" SH -chmod 0755, $driver or die "Unable to make $driver executable: $!"; +my $driver = '/fixture/run-helper'; my $connections = join( "\n", 'primary uplink:activated', 'backup:deactivated', @@ -170,15 +167,19 @@ sub run_program { write_binary( $nmcli_log, '' ); write_binary( $message_log, '' ); - local %ENV = %ENV; - $ENV{PATH} = $has_nmcli ? "$test_bin:$ENV{PATH}" : $empty_bin; - $ENV{XCATDEBUGMODE} = $options{debug} // '0'; - $ENV{MASTER_IP} = '192.0.2.10'; - $ENV{XCAT_TEST_MESSAGE_LOG} = $message_log; - $ENV{XCAT_TEST_NMCLI_LOG} = $nmcli_log; - $ENV{XCAT_TEST_NMCLI_OUTPUT} = $options{connections} // ''; - $ENV{XCAT_TEST_SCRIPTLIB} = $scriptlib; + my %env = ( + XCATDEBUGMODE => $options{debug} // '0', + MASTER_IP => '192.0.2.10', + XCAT_TEST_MESSAGE_LOG => '/fixture/messages.log', + XCAT_TEST_NMCLI_LOG => '/fixture/nmcli.log', + XCAT_TEST_NMCLI_OUTPUT => $options{connections} // '', + XCAT_TEST_SCRIPTLIB => '/scriptlib', + ); + $env{PATH} = '/fixture/empty-bin' unless $has_nmcli; - my $status = system( '/bin/bash', $program, @{$arguments} ); - return $status == -1 ? 255 : $status >> 8; + my ( $status, $output ) = sandbox_run( $root, + { read_only => { $scriptlib => '/scriptlib' }, env => \%env }, + '/bin/bash', $program, @{$arguments} ); + diag($output) if $status; + return $status; } From d4c0b34393b310f3ea8c7f59a515635de6fc9e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 18:08:18 -0300 Subject: [PATCH 077/114] test(debian): run the xcatd init state test in a sandbox The unit test ran the Debian init helpers in the host shell, with fake ucf, update-rc.d, systemctl and mv first in the host PATH. It now runs them with sandbox_run in xCAT-test/native, with the compatibility root apart from the /etc of the sandbox, and the Debian package lifecycle step runs it. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/README.md | 3 ++- .../xcatd_debian_init_state.t | 26 +++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) rename xCAT-test/{unit => native}/xcatd_debian_init_state.t (98%) diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 07e6e507e1..5ac3956e15 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/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 + 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 xCAT-test/native/xcatd_debian_init_state.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/README.md b/xCAT-test/native/README.md index 2ffa12cd1b..558896edcf 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -303,7 +303,8 @@ On Debian or Ubuntu, install `bubblewrap`, `debhelper`, `devscripts`, `fakeroot` prove 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/package_upgrade_logging.t \ + xCAT-test/native/xcatd_debian_init_state.t ``` On EL8 or EL10, install `bubblewrap`, `rpm-build`, `systemd`, `chkconfig`, diff --git a/xCAT-test/unit/xcatd_debian_init_state.t b/xCAT-test/native/xcatd_debian_init_state.t similarity index 98% rename from xCAT-test/unit/xcatd_debian_init_state.t rename to xCAT-test/native/xcatd_debian_init_state.t index 158baf99c3..4a1b154660 100644 --- a/xCAT-test/unit/xcatd_debian_init_state.t +++ b/xCAT-test/native/xcatd_debian_init_state.t @@ -2,17 +2,19 @@ use strict; use warnings; -use File::Basename qw(basename); +use File::Basename qw(basename dirname); use File::Copy qw(copy); use File::Path qw(make_path); use File::Slurper qw(read_binary write_binary); use File::Spec; -use File::Temp qw(tempdir); use FindBin; use lib "$FindBin::Bin/../lib"; use Test::More; use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); + +plan skip_all => 'init helper execution requires Linux namespaces' unless $^O eq 'linux'; my $state_helper = repo_path('xCAT-server/debian/xcatd-init-state'); my $compat_helper = repo_path('xCAT-server/share/xcat/scripts/xcatd-init-compat'); @@ -30,7 +32,8 @@ sub path_mode { } sub stage_root { - my $root = tempdir( CLEANUP => 1 ); + # The compatibility root stays apart from the /etc of the sandbox. + my $root = File::Spec->catdir( sandbox_root(), 'compat' ); my $scripts = File::Spec->catdir( $root, 'opt', 'xcat', 'share', 'xcat', 'scripts' ); @@ -188,11 +191,18 @@ SH sub run_script { my ( $root, $script, @arguments ) = @_; - local $ENV{XCAT_COMPAT_ROOT} = $root; - local $ENV{XCATROOT} = '/opt/xcat'; - local $ENV{PATH} = File::Spec->catdir( $root, 'test-bin' ) . ':/usr/bin:/bin'; - system( '/bin/sh', $script, @arguments ); - return $? >> 8; + my $source = repo_path('.'); + $script =~ s{^\Q$root\E/}{/fixture/compat/}; + my ( $status, $output ) = sandbox_run( dirname($root), { + read_only => { $source => $source }, + env => { + XCAT_COMPAT_ROOT => '/fixture/compat', + XCATROOT => '/opt/xcat', + PATH => '/fixture/compat/test-bin:/usr/bin:/bin', + }, + }, '/bin/sh', $script, @arguments ); + note($output) if length $output; + return $status; } sub run_state { From 2aa38638812a655808b5e719111baf0e46446e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 18:08:30 -0300 Subject: [PATCH 078/114] test(probe): move the detect_dhcpd test to the native tests The test runs both detect_dhcpd scripts with a fake tcpdump, and its capture cases need private mount and network namespaces. It now lives in xCAT-test/native with the other namespace tests, and the pull-request workflow runs it in its own step. The capture cases keep their own unshare call, because they add a default route on the loopback interface. --- .github/workflows/xcat_test.yml | 3 +++ xCAT-test/native/README.md | 10 ++++++++++ .../{unit => native}/detect_dhcpd_tcpdump_lookup.t | 0 3 files changed, 13 insertions(+) rename xCAT-test/{unit => native}/detect_dhcpd_tcpdump_lookup.t (100%) diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 5ac3956e15..04ac4f1f6e 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -72,6 +72,9 @@ jobs: - name: Exercise the install script library if: ${{ !cancelled() }} run: prove xCAT-test/native/networkmanager_autoconnect.t + - name: Exercise the DHCP server detector + if: ${{ !cancelled() }} + run: prove xCAT-test/native/detect_dhcpd_tcpdump_lookup.t - name: Run tests if: ${{ !cancelled() }} run: perl github_action_xcat_test.pl diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index 558896edcf..0a5b6b3d2c 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -255,6 +255,16 @@ filesystem. It needs Bubblewrap and unprivileged user namespaces: prove xCAT-test/native/networkmanager_autoconnect.t ``` +`detect_dhcpd_tcpdump_lookup.t` runs the DHCP server detectors of xCAT-server +and xCAT-probe with a `tcpdump` command fixture. The capture cases need a +default route on the loopback interface, so they run in mount and network +namespaces from `unshare` instead of Bubblewrap. They need `unshare`, `mount`, +`ip` and a writable `/var/tmp`, and skip without a private network namespace: + +``` +prove xCAT-test/native/detect_dhcpd_tcpdump_lookup.t +``` + ## FIPS policy and discovery keys Run the unchanged statelite and Cumulus callers in private filesystems: diff --git a/xCAT-test/unit/detect_dhcpd_tcpdump_lookup.t b/xCAT-test/native/detect_dhcpd_tcpdump_lookup.t similarity index 100% rename from xCAT-test/unit/detect_dhcpd_tcpdump_lookup.t rename to xCAT-test/native/detect_dhcpd_tcpdump_lookup.t From b473ce90d06f5166711918ecfaa49f96b56717f5 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, 5 Nov 2026 16:59:53 -0300 Subject: [PATCH 079/114] fix(ubuntu): lock the root image while genimage builds it packimage, rmimage and the EL genimage take the image operation lock of a root image, but the Ubuntu genimage did not. packimage or rmimage could work on a root image while genimage installed packages in it, and two genimage or geninitrd runs could change one root image at the same time. genimage now takes the lock before it changes the root image, for a full build and for the --onlyinitrd run of geninitrd, and holds it until it exits. --- xCAT-server/share/xcat/netboot/ubuntu/genimage | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index abfdc8216a..d97cf8ce1e 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -66,6 +66,7 @@ my $tempfile; my $prompt; my $noupdate; my $kernelimage; +my $lock; sub xdie { @@ -218,6 +219,15 @@ foreach (@ndrivers, @default_ndrivers) { my $uarch = xCAT::Utils->debian_arch($arch); +# The lock is named after the real path of the root image, which must exist. +mkpath($rootimg_dir) unless ($onlyinitrd); +my $lockerror; +($lockerror, $lock) = xCAT::Utils->acquire_lock_imageop($rootimg_dir); +if ($lockerror) { + print "Error: $lock\n"; + exit 1; +} + unless ($onlyinitrd) { @aptdirs = (); From 3e3ee8f108479cf46abd8f685fc232cc54b4bad8 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, 5 Nov 2026 18:39:24 -0300 Subject: [PATCH 080/114] fix(ubuntu): publish the newest kernel of a root image genimage took the last kernel of a sorted file list. When an image held 6.8.0-99-generic and 6.8.0-100-generic, it published -99 and built the initrds for it. The uname of the image build also reported -99 to the package scripts, and it ignored an explicit kernelver. genimage and that uname now compare kernel releases number by number, so both choose -100. An explicit kernelver decides for both. --- .../share/xcat/netboot/imgutils/imgutils.pm | 37 +++++++++++++++++++ .../share/xcat/netboot/ubuntu/genimage | 17 +-------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9c71367c18..9af7c10c35 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -249,6 +249,43 @@ sub disable_auto_profiles { return; } +# A kernel release compares number by number, so 6.8.0-100-generic is newer than 6.8.0-99-generic. +sub newest_kernel_version { + my @releases = @_; + my $compare = sub { + my @left = split(/(\d+)/, $_[0]); + my @right = split(/(\d+)/, $_[1]); + while (@left && @right) { + my ($l, $r) = (shift(@left), shift(@right)); + my $order = ($l =~ /^\d+$/ && $r =~ /^\d+$/) ? $l <=> $r : $l cmp $r; + return $order if $order; + } + return @left <=> @right; + }; + my ($newest) = sort { $compare->($b, $a) } @releases; + return $newest; +} + +# Package scripts run this uname in the image, so -r names the kernel that genimage publishes. +sub uname_script { + my ($kernelver) = @_; + my $release = $kernelver ? "echo \"$kernelver\"" : 'ls /lib/modules | sort -V | tail -n 1'; + return "#!/bin/bash \n" + . "case \"\$1\" in \n" + . "\"-m\") \n" + . " ARCH=\"\$(dpkg --print-architecture || \n" + . " rpm -q kernel-\$(\"\$0\" -r) --qf '%{arch}')\" \n" + . " case \"\$ARCH\" in \n" + . " \"amd64\") ARCH=\"x86_64\" ;; \n" + . " \"ppc64el\") ARCH=\"ppc64le\" ;; \n" + . " esac \n" + . " echo \"\$ARCH\" ;; \n" + . "\"-r\") $release ;; \n" + . "\"-s\"|\"\") echo \"Linux\" ;; \n" + . "esac \n" + . "exit 0 \n"; +} + sub varsubinline{ my $line=shift; my $refvardict=shift; diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index d97cf8ce1e..1c2714b00c 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -733,7 +733,7 @@ foreach (@KVERS) { @KVERS = <$rootimg_dir/lib/modules/*> unless (scalar(@KVERS)); -$basekernelver = basename(pop @KVERS) if (scalar(@KVERS)); +$basekernelver = imgutils::newest_kernel_version(map { basename($_) } @KVERS) if (scalar(@KVERS)); $basekernelver = `uname -r` unless ($basekernelver); @@ -2269,20 +2269,7 @@ sub use_hackuname { # write the hacked uname script my $unamefile; open($unamefile, ">", "$rootimg_dir/bin/uname"); - print $unamefile "#!/bin/bash \n"; - print $unamefile "case \"\$1\" in \n"; - print $unamefile "\"-m\") \n"; - print $unamefile " ARCH=\"\$(dpkg --print-architecture || \n"; - print $unamefile " rpm -q kernel-\$(\"\$0\" -r) --qf '%{arch}')\" \n"; - print $unamefile " case \"\$ARCH\" in \n"; - print $unamefile " \"amd64\") ARCH=\"x86_64\" ;; \n"; - print $unamefile " \"ppc64el\") ARCH=\"ppc64le\" ;; \n"; - print $unamefile " esac \n"; - print $unamefile " echo \"\$ARCH\" ;; \n"; - print $unamefile "\"-r\") cd /lib/modules && for d in * ; do : ; done && echo \$d ;; \n"; - print $unamefile "\"-s\"|\"\") echo \"Linux\" ;; \n"; - print $unamefile "esac \n"; - print $unamefile "exit 0 \n"; + print $unamefile imgutils::uname_script($kernelver); close $unamefile; chmod(0755, "$rootimg_dir/bin/uname"); } From 38e00d0cf2cce47579fa9a3478e794f6386b30d0 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, 5 Nov 2026 18:39:24 -0300 Subject: [PATCH 081/114] test(ubuntu): cover the kernel that genimage publishes --- xCAT-test/unit/imgutils_kernel_version.t | 24 ++++++++++++++++ xCAT-test/unit/imgutils_uname_script.t | 35 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 xCAT-test/unit/imgutils_kernel_version.t create mode 100644 xCAT-test/unit/imgutils_uname_script.t diff --git a/xCAT-test/unit/imgutils_kernel_version.t b/xCAT-test/unit/imgutils_kernel_version.t new file mode 100644 index 0000000000..ff4fd9e3f9 --- /dev/null +++ b/xCAT-test/unit/imgutils_kernel_version.t @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +for my $case ( + [ [qw(6.8.0-99-generic 6.8.0-100-generic)], '6.8.0-100-generic', 'an ABI of 100 is newer than an ABI of 99' ], + [ [qw(6.10.0-1-generic 6.9.0-1-generic)], '6.10.0-1-generic', 'kernel 6.10 is newer than kernel 6.9' ], + [ [qw(6.8.0-100-generic 7.0.0-42-generic)], '7.0.0-42-generic', 'a newer kernel wins over a larger ABI' ], + [ [qw(7.0.0-42-generic)], '7.0.0-42-generic', 'an image with one kernel gets that kernel' ], +) { + my ($releases, $newest, $label) = @$case; + is(imgutils::newest_kernel_version(@$releases), $newest, $label); + is(imgutils::newest_kernel_version(reverse @$releases), $newest, "$label, in either order"); +} + +is(imgutils::newest_kernel_version(), undef, 'an image without a kernel gets no kernel release'); + +done_testing(); diff --git a/xCAT-test/unit/imgutils_uname_script.t b/xCAT-test/unit/imgutils_uname_script.t new file mode 100644 index 0000000000..c75603cca2 --- /dev/null +++ b/xCAT-test/unit/imgutils_uname_script.t @@ -0,0 +1,35 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +plan skip_all => 'bash is not installed' unless -x '/bin/bash'; + +# The script runs in the image, which lists its kernels in /lib/modules. This ls lists two of them. +my $bin = tempdir(CLEANUP => 1); +write_text("$bin/ls", "#!/bin/sh\n[ \"\$1\" = /lib/modules ] && printf '6.8.0-99-generic\\n6.8.0-100-generic\\n'\n"); +chmod(0755, "$bin/ls") or die "chmod: $!"; + +sub uname { + my ($kernelver, @options) = @_; + my $script = tempdir(CLEANUP => 1) . '/uname'; + write_text($script, imgutils::uname_script($kernelver)); + local $ENV{PATH} = "$bin:$ENV{PATH}"; + my $output = `/bin/bash $script @options`; + chomp($output); + return $output; +} + +is(uname('', '-r'), '6.8.0-100-generic', 'uname -r names the newest kernel of the image'); +is(uname('6.8.0-99-generic', '-r'), '6.8.0-99-generic', 'uname -r names an explicit kernelver'); +is(uname('', '-s'), 'Linux', 'uname -s names Linux'); +is(uname(''), 'Linux', 'uname without an option names Linux'); + +done_testing(); From 4ea954099ac6319271c888b1e01290850357b445 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, 5 Nov 2026 18:39:24 -0300 Subject: [PATCH 082/114] fix(ubuntu): reuse the root image of an earlier genimage run genimage ran debootstrap on every run. For Ubuntu 19.04 and later, debootstrap extracts with tar -k, so a second run on an existing root image failed at base-files and blamed the mirror. genimage now skips debootstrap when an earlier run finished it and updates the image with apt. The image holds the dummy resolv.conf and the otherpkgs apt sources of that run. Before the first apt command, genimage removes the apt sources that it writes again later and gives the image the hosts and resolv.conf of the build host. A .bak file that an interrupted run left is kept, so the image still gets its own file back. genimage stops with an error and leaves the root image unchanged in three cases. The root image holds another Ubuntu release or architecture, the debootstrap directory of an unfinished run, or the bin/uname-binary backup of an interrupted run. --- .../share/xcat/netboot/imgutils/imgutils.pm | 58 +++++++++++++++++++ .../share/xcat/netboot/ubuntu/genimage | 28 ++++----- 2 files changed, 72 insertions(+), 14 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9af7c10c35..0ecd365b1f 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -249,6 +249,64 @@ sub disable_auto_profiles { return; } +# debootstrap deletes $rootimg_dir/debootstrap when it finishes, and its tar -k fails over a finished root. +sub debootstrap_finished { + my ($rootimg_dir) = @_; + die("Error: $rootimg_dir holds an unfinished debootstrap. Remove $rootimg_dir and run genimage again.\n") + if -e "$rootimg_dir/debootstrap"; + return -e "$rootimg_dir/var/lib/dpkg/status" ? 1 : 0; +} + +# genimage moves the .bak files back, and a .bak that an interrupted run left holds the image's own file. +sub use_host_resolver { + my ($rootimg_dir) = @_; + foreach my $file ('hosts', 'resolv.conf') { + my $image = "$rootimg_dir/etc/$file"; + move($image, "$image.bak") unless -e "$image.bak" || -l "$image.bak"; + unlink($image); + File::Copy::copy("/etc/$file", $image); + } + return; +} + +# A finished image holds the dummy resolv.conf and the apt sources of the run that built it. +sub prepare_reused_root { + my ($rootimg_dir) = @_; + unlink(map { "$rootimg_dir/etc/apt/sources.list.d/$_" } qw(genimage.apt.list genimage1.apt.list)); + use_host_resolver($rootimg_dir); + return; +} + +# apt would move a root image of another release or architecture partway to the requested one. +sub check_reused_root { + my ($rootimg_dir, $suite, $arch) = @_; + my ($codename, $image_arch); + my $os_release = -e "$rootimg_dir/usr/lib/os-release" ? "$rootimg_dir/usr/lib/os-release" : "$rootimg_dir/etc/os-release"; + my %field; + foreach my $file ($os_release, "$rootimg_dir/etc/lsb-release") { + my $fh; + next if -l $file || !open($fh, '<', $file); + %field = (%field, map { /^(VERSION_CODENAME|UBUNTU_CODENAME|DISTRIB_CODENAME)=(["']?)(\S+?)\2\s*$/ ? ($1 => $3) : () } <$fh>); + close($fh); + } + # Ubuntu 16.04 images before base-files 9.4ubuntu4.3 have only UBUNTU_CODENAME, and 14.04 images only DISTRIB_CODENAME. + $codename = $field{VERSION_CODENAME} // $field{UBUNTU_CODENAME} // $field{DISTRIB_CODENAME}; + if (open(my $fh, '<', "$rootimg_dir/var/lib/dpkg/status")) { + local $/ = ''; + ($image_arch) = map { /^Package: dpkg\n(?:.+\n)*?Architecture: (\S+)/ ? $1 : () } <$fh>; + close($fh); + } + (my $release = $suite) =~ s/-(?:updates|security|backports|proposed)$//; + die("Error: genimage cannot tell the Ubuntu release and architecture of $rootimg_dir. Remove $rootimg_dir and run genimage again.\n") + unless $codename && $image_arch; + die("Error: $rootimg_dir holds Ubuntu $codename for $image_arch, not $release for $arch. Remove $rootimg_dir or use another rootimgdir.\n") + unless $codename eq $release && $image_arch eq $arch; + # dpkg owns bin/uname, so genimage cannot tell whether the backup or the file in place is current. + die("Error: $rootimg_dir holds bin/uname-binary, which an interrupted genimage run left. Restore bin/uname from it or remove $rootimg_dir, then run genimage again.\n") + if -e "$rootimg_dir/bin/uname-binary" || -l "$rootimg_dir/bin/uname-binary"; + return 1; +} + # A kernel release compares number by number, so 6.8.0-100-generic is newer than 6.8.0-99-generic. sub newest_kernel_version { my @releases = @_; diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index 1c2714b00c..ddcf0a607e 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -327,11 +327,6 @@ unless ($onlyinitrd) { close($aptconfig); mkpath "$rootimg_dir/etc"; - my $fd; - open($fd, ">>", "$rootimg_dir/etc/fstab"); - print $fd "#Dummy fstab for dpkg postscripts to see\n"; - close($fd); - my $non_interactive; if (!$prompt) { $non_interactive = "-y"; } @@ -369,8 +364,19 @@ unless ($onlyinitrd) { $aptcmd2 = "--verbose --arch $uarch $dist $rootimg_dir file://$srcdir"; } - print "Run cmd [$aptcmd1 $aptcmd2] to create rootimage bootstraps\n"; - my $rc = system("$aptcmd1 $aptcmd2"); + my $rc = 0; + if (imgutils::debootstrap_finished($rootimg_dir)) { + imgutils::check_reused_root($rootimg_dir, $dist, $uarch); + print "Updating the existing root image in $rootimg_dir\n"; + imgutils::prepare_reused_root($rootimg_dir); + } else { + my $fd; + open($fd, ">>", "$rootimg_dir/etc/fstab"); + print $fd "#Dummy fstab for dpkg postscripts to see\n"; + close($fd); + print "Run cmd [$aptcmd1 $aptcmd2] to create rootimage bootstraps\n"; + $rc = system("$aptcmd1 $aptcmd2"); + } if ($rc) { my $os=xCAT::Utils->osver("os"); if ($os ne 'ubuntu') { @@ -531,13 +537,7 @@ unless ($onlyinitrd) { } close($aptconfig); - #backup the /etc/hosts & /etc/resolv.conf - move("$rootimg_dir/etc/hosts", "$rootimg_dir/etc/hosts.bak"); - move("$rootimg_dir/etc/resolv.conf", "$rootimg_dir/etc/resolv.conf.bak"); - - #copy the mn's /etc/hosts & /etc/resolv.conf to the rootimage - copy("/etc/hosts", "$rootimg_dir/etc/hosts"); - copy("/etc/resolv.conf", "$rootimg_dir/etc/resolv.conf"); + imgutils::use_host_resolver($rootimg_dir); #Now let's handle extra packages unless ($imagename) { From 9d40a2e0d37410b84df0cabbe8524bde9b369c50 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, 5 Nov 2026 18:39:24 -0300 Subject: [PATCH 083/114] test(ubuntu): cover genimage reuse of a finished root image --- .../unit/imgutils_debootstrap_finished.t | 49 ++++++++ xCAT-test/unit/imgutils_host_resolver.t | 77 +++++++++++++ xCAT-test/unit/imgutils_reused_root.t | 51 +++++++++ xCAT-test/unit/imgutils_reused_root_release.t | 105 ++++++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 xCAT-test/unit/imgutils_debootstrap_finished.t create mode 100644 xCAT-test/unit/imgutils_host_resolver.t create mode 100644 xCAT-test/unit/imgutils_reused_root.t create mode 100644 xCAT-test/unit/imgutils_reused_root_release.t diff --git a/xCAT-test/unit/imgutils_debootstrap_finished.t b/xCAT-test/unit/imgutils_debootstrap_finished.t new file mode 100644 index 0000000000..bd7138308a --- /dev/null +++ b/xCAT-test/unit/imgutils_debootstrap_finished.t @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Path qw(make_path); +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +sub image_root { + my (@files) = @_; + my $root = tempdir(CLEANUP => 1) . '/rootimg'; + make_path($root); + for my $file (@files) { + if ($file =~ m{/$}) { + make_path("$root/$file"); + } else { + make_path("$root/" . ($file =~ s{/[^/]+$}{}r)); + write_text("$root/$file", ''); + } + } + return $root; +} + +is(imgutils::debootstrap_finished(tempdir(CLEANUP => 1) . '/rootimg'), 0, + 'a missing root image needs debootstrap'); +is(imgutils::debootstrap_finished(image_root('etc/fstab')), 0, + 'a root image with only the dummy fstab of genimage needs debootstrap'); +is(imgutils::debootstrap_finished(image_root('var/lib/dpkg/')), 0, + 'a root image without a dpkg status file needs debootstrap'); +is(imgutils::debootstrap_finished(image_root('etc/fstab', 'var/lib/dpkg/status')), 1, + 'a root image that debootstrap finished is reused'); + +for my $case ( + [ 'debootstrap/debootstrap.log', 'var/lib/dpkg/status' ], + [ 'debootstrap/' ], +) { + my $root = image_root(@$case); + my $finished = eval { imgutils::debootstrap_finished($root) }; + is($finished, undef, "an unfinished root image with @$case stops genimage"); + like($@, qr/^Error: \Q$root\E holds an unfinished debootstrap\. Remove \Q$root\E /, + "the error for a root image with @$case names the root image to remove"); +} + +done_testing(); diff --git a/xCAT-test/unit/imgutils_host_resolver.t b/xCAT-test/unit/imgutils_host_resolver.t new file mode 100644 index 0000000000..761e46024e --- /dev/null +++ b/xCAT-test/unit/imgutils_host_resolver.t @@ -0,0 +1,77 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +plan skip_all => 'the build host has no /etc/hosts or /etc/resolv.conf' + unless -r '/etc/hosts' && -r '/etc/resolv.conf'; + +my %host = map { $_ => read_text("/etc/$_") } qw(hosts resolv.conf); +my $stub = '../run/systemd/resolve/stub-resolv.conf'; +my $dummy = '#Dummy resolv.conf to make boot cleaner'; + +# A root image as an earlier genimage run leaves it: resolv.conf links to the stub that holds the dummy. +sub image_root { + my $root = tempdir(CLEANUP => 1); + make_path("$root/etc", "$root/run/systemd/resolve"); + write_text("$root/etc/hosts", "127.0.0.1 localhost\n"); + write_text("$root/run/systemd/resolve/stub-resolv.conf", $dummy); + symlink($stub, "$root/etc/resolv.conf") or die "symlink: $!"; + return $root; +} + +sub has_host_files { + my ($root, $label) = @_; + for my $file (qw(hosts resolv.conf)) { + ok(!-l "$root/etc/$file", "$label: etc/$file is a file, not a link"); + is(read_text("$root/etc/$file"), $host{$file}, "$label: etc/$file holds the file of the build host"); + } + return; +} + +{ + my $root = image_root(); + for my $pass (1, 2) { + imgutils::use_host_resolver($root); + has_host_files($root, "pass $pass"); + is(read_text("$root/etc/hosts.bak"), "127.0.0.1 localhost\n", "pass $pass: hosts.bak holds the hosts of the image"); + is(readlink("$root/etc/resolv.conf.bak"), $stub, "pass $pass: resolv.conf.bak is the link of the image"); + } + is(read_text("$root/run/systemd/resolve/stub-resolv.conf"), $dummy, 'the stub that the link names is not written'); +} + +{ + my $root = image_root(); + my $outside = tempdir(CLEANUP => 1) . '/stub-resolv.conf'; + write_text($outside, "nameserver 192.0.2.1\n"); + unlink("$root/etc/resolv.conf"); + symlink($outside, "$root/etc/resolv.conf") or die "symlink: $!"; + imgutils::use_host_resolver($root); + is(readlink("$root/etc/resolv.conf.bak"), $outside, 'an absolute link is moved aside, not followed'); + + # A package script can turn resolv.conf back into a link while the .bak files exist. + unlink("$root/etc/resolv.conf"); + symlink($outside, "$root/etc/resolv.conf") or die "symlink: $!"; + imgutils::use_host_resolver($root); + has_host_files($root, 'after resolv.conf is linked again'); + is(readlink("$root/etc/resolv.conf.bak"), $outside, 'after resolv.conf is linked again: resolv.conf.bak still holds the link of the image'); + is(read_text($outside), "nameserver 192.0.2.1\n", 'a file outside the image is never written through a link'); +} + +{ + my $root = image_root(); + unlink("$root/etc/hosts"); + imgutils::use_host_resolver($root); + has_host_files($root, 'an image without hosts'); + ok(!-e "$root/etc/hosts.bak", 'an image without hosts gets no hosts.bak'); +} + +done_testing(); diff --git a/xCAT-test/unit/imgutils_reused_root.t b/xCAT-test/unit/imgutils_reused_root.t new file mode 100644 index 0000000000..dc7971e962 --- /dev/null +++ b/xCAT-test/unit/imgutils_reused_root.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +plan skip_all => 'the build host has no /etc/hosts or /etc/resolv.conf' + unless -r '/etc/hosts' && -r '/etc/resolv.conf'; + +sub sources { + my ($dir) = @_; + opendir(my $dh, $dir) or die "opendir $dir: $!"; + my @files = sort grep { !/^\./ } readdir($dh); + closedir($dh); + return \@files; +} + +my $root = tempdir(CLEANUP => 1); +my $sources = "$root/etc/apt/sources.list.d"; +my $site = "deb http://192.0.2.2/site ./\n"; +make_path($sources); +write_text("$sources/$_", "deb http://192.0.2.1/retired ./\n") for qw(genimage.apt.list genimage1.apt.list); +write_text("$sources/site.list", $site); +write_text("$root/etc/hosts", "127.0.0.1 localhost\n"); +write_text("$root/etc/resolv.conf", '#Dummy resolv.conf to make boot cleaner'); + +for my $pass (1, 2) { + imgutils::prepare_reused_root($root); + is_deeply(sources($sources), ['site.list'], "pass $pass: only the apt sources that genimage writes are removed"); + is(read_text("$sources/site.list"), $site, "pass $pass: a site source is kept as it is"); + is(read_text("$root/etc/resolv.conf"), read_text('/etc/resolv.conf'), + "pass $pass: the image gets the resolv.conf of the build host"); + is(read_text("$root/etc/resolv.conf.bak"), '#Dummy resolv.conf to make boot cleaner', + "pass $pass: resolv.conf.bak holds the resolv.conf of the image"); +} + +{ + my $bare = tempdir(CLEANUP => 1); + make_path("$bare/etc"); + imgutils::prepare_reused_root($bare); + is(read_text("$bare/etc/hosts"), read_text('/etc/hosts'), 'an image without apt sources still gets the hosts of the build host'); +} + +done_testing(); diff --git a/xCAT-test/unit/imgutils_reused_root_release.t b/xCAT-test/unit/imgutils_reused_root_release.t new file mode 100644 index 0000000000..04276341e6 --- /dev/null +++ b/xCAT-test/unit/imgutils_reused_root_release.t @@ -0,0 +1,105 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Find; +use File::Path qw(make_path); +use File::Slurper qw(write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +# A finished root image with the os-release and the dpkg status that Ubuntu writes. +sub image_root { + my (%overrides) = @_; + my %image = (codename => 'resolute', arch => 'riscv64', field => 'VERSION_CODENAME', %overrides); + my $root = tempdir(CLEANUP => 1); + make_path("$root/usr/lib", "$root/etc", "$root/var/lib/dpkg"); + write_text("$root/usr/lib/os-release", "NAME=\"Ubuntu\"\nVERSION_ID=\"26.04\"\n$image{field}=$image{codename}\nID=ubuntu\n") + if defined $image{codename}; + symlink('../usr/lib/os-release', "$root/etc/os-release") or die "symlink: $!"; + write_text("$root/var/lib/dpkg/status", + "Package: debconf\nStatus: install ok installed\nArchitecture: all\n\n" + . "Package: dpkg\nEssential: yes\nStatus: install ok installed\nArchitecture: $image{arch}\nVersion: 1.23.5ubuntu1\n\n" + . "Package: dpkg-dev\nStatus: install ok installed\nArchitecture: all\n"); + return $root; +} + +sub snapshot { + my ($root) = @_; + my @entries; + find({ wanted => sub { push @entries, join(' ', $File::Find::name, (lstat)[1, 2, 7, 9]) }, no_chdir => 1 }, $root); + return [sort @entries]; +} + +for my $case ( + [ 'resolute', 'riscv64', 'the release and architecture that built the image' ], + [ 'resolute-updates', 'riscv64', 'the updates pocket of that release' ], + [ 'resolute-security', 'riscv64', 'the security pocket of that release' ], +) { + my ($suite, $arch, $label) = @$case; + is(eval { imgutils::check_reused_root(image_root(), $suite, $arch) }, 1, "a root image is reused for $label") or diag($@); +} + +{ + my $root = image_root(codename => '"resolute"'); + is(eval { imgutils::check_reused_root($root, 'resolute', 'riscv64') }, 1, 'a quoted VERSION_CODENAME is read') or diag($@); +} + +{ + my $root = image_root(codename => 'xenial', arch => 'amd64', field => 'UBUNTU_CODENAME'); + is(eval { imgutils::check_reused_root($root, 'xenial', 'amd64') }, 1, 'an Ubuntu 16.04 image with only UBUNTU_CODENAME is reused') or diag($@); +} + +{ + # Ubuntu 14.04 names its release only in lsb-release. + my $root = image_root(codename => undef, arch => 'amd64'); + unlink("$root/etc/os-release"); + write_text("$root/etc/os-release", "NAME=\"Ubuntu\"\nVERSION_ID=\"14.04\"\nID=ubuntu\n"); + write_text("$root/etc/lsb-release", "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=14.04\nDISTRIB_CODENAME=trusty\n"); + is(eval { imgutils::check_reused_root($root, 'trusty', 'amd64') }, 1, 'an Ubuntu 14.04 image with only DISTRIB_CODENAME is reused') or diag($@); + is(eval { imgutils::check_reused_root($root, 'xenial', 'amd64') }, undef, 'an Ubuntu 14.04 image is not reused for Ubuntu 16.04'); + like($@, qr/holds Ubuntu trusty for amd64, not xenial for amd64/, 'the error names the release of the Ubuntu 14.04 image'); +} + +for my $case ( + [ [], 'noble', 'riscv64', qr/holds Ubuntu resolute for riscv64, not noble for riscv64\. Remove /, 'another release' ], + [ [], 'resolute', 'amd64', qr/holds Ubuntu resolute for riscv64, not resolute for amd64\. Remove /, 'another architecture' ], + [ [ codename => undef ], 'resolute', 'riscv64', qr/cannot tell the Ubuntu release and architecture/, 'no os-release' ], + [ [ arch => '' ], 'resolute', 'riscv64', qr/cannot tell the Ubuntu release and architecture/, 'no dpkg architecture' ], +) { + my ($image, $suite, $arch, $error, $label) = @$case; + my $root = image_root(@$image); + my $before = snapshot($root); + my $result = eval { imgutils::check_reused_root($root, $suite, $arch) }; + is($result, undef, "a root image is not reused for $label"); + like($@, $error, "the error for $label names the mismatch"); + is_deeply(snapshot($root), $before, "a root image refused for $label is left as it was"); +} + +{ + my $root = image_root(); + make_path("$root/bin"); + write_text("$root/bin/uname-binary", "uname\n"); + my $before = snapshot($root); + is(eval { imgutils::check_reused_root($root, 'resolute', 'riscv64') }, undef, + 'a root image with the uname backup of an interrupted run is not reused'); + like($@, qr/holds bin\/uname-binary, which an interrupted genimage run left\. Restore bin\/uname from it or remove /, + 'the error says how to recover the uname of the image'); + is_deeply(snapshot($root), $before, 'a root image with the uname backup is left as it was'); +} + +{ + # An absolute link would read the os-release of the build host, which can name the same release. + my $root = image_root(codename => undef); + my $host = tempdir(CLEANUP => 1) . '/os-release'; + write_text($host, "VERSION_CODENAME=resolute\n"); + unlink("$root/etc/os-release"); + symlink($host, "$root/etc/os-release") or die "symlink: $!"; + is(eval { imgutils::check_reused_root($root, 'resolute', 'riscv64') }, undef, 'an os-release link that leaves the image is not followed'); +} + +done_testing(); From acc8089c2afea7b0335f71eb430e5bd0a772155b 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, 5 Nov 2026 21:38:54 -0300 Subject: [PATCH 084/114] refactor(genimage): publish a staged kernel with several initial ramdisks publish_boot_files publishes one kernel with one initial ramdisk, so a genimage that builds the statelite and the stateless ramdisk cannot use it. publish_staged_boot_files publishes the kernel and the ramdisks of several modes from one staging directory. When a rename fails, it puts back every file that it already replaced. publish_boot_files keeps its interface for the openEuler build. --- .../share/xcat/netboot/imgutils/imgutils.pm | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 9c71367c18..611098d17a 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -135,23 +135,41 @@ sub publish_boot_files { my ($native_bootdir, $destdir, $initrd, $mode) = @_; move($initrd, "$native_bootdir/initrd-$mode.gz") or die("Error: failed to move the initial ramdisk for $mode: $!\n"); - my $old_kernel = -e "$destdir/kernel" || -l "$destdir/kernel"; - if ($old_kernel) { - link("$destdir/kernel", "$native_bootdir/previous-kernel") - or die("Error: failed to preserve the previous kernel: $!\n"); + return publish_staged_boot_files($native_bootdir, $destdir, $mode); +} + +# nodeset copies the kernel and the initial ramdisks as one set, so a failure puts back every file already replaced. +sub publish_staged_boot_files { + my ($native_bootdir, $destdir, @modes) = @_; + my @files = ([ 'kernel', 'kernel' ], map { [ "initrd-$_.gz", "initial ramdisk for $_" ] } @modes); + foreach my $file (@files) { + my ($name, $what) = @$file; + next unless -e "$destdir/$name" || -l "$destdir/$name"; + link("$destdir/$name", "$native_bootdir/previous-$name") + or die("Error: failed to preserve the previous $what: $!\n"); } - rename("$native_bootdir/kernel", "$destdir/kernel") - or die("Error: failed to publish the kernel: $!\n"); - unless (rename("$native_bootdir/initrd-$mode.gz", "$destdir/initrd-$mode.gz")) { - my $error = $!; - my $restored = $old_kernel - ? rename("$native_bootdir/previous-kernel", "$destdir/kernel") - : unlink("$destdir/kernel"); - unless ($restored) { - $native_bootdir->unlink_on_destroy(0); - die("Error: failed to publish the initial ramdisk: $error; kernel rollback failed: $!. Boot files retained in $native_bootdir\n"); + my @published; + foreach my $file (@files) { + my ($name, $what) = @$file; + if (rename("$native_bootdir/$name", "$destdir/$name")) { + push @published, $file; + next; } - die("Error: failed to publish the initial ramdisk for $mode: $error\n"); + my $error = $!; + my @failed; + foreach my $done (reverse @published) { + my ($done_name, $done_what) = @$done; + my $previous = "$native_bootdir/previous-$done_name"; + my $restored = (-e $previous || -l $previous) + ? rename($previous, "$destdir/$done_name") + : unlink("$destdir/$done_name"); + push @failed, "$done_what rollback failed: $!" unless $restored; + } + if (@failed) { + $native_bootdir->unlink_on_destroy(0); + die("Error: failed to publish the $what: $error; " . join('; ', @failed) . ". Boot files retained in $native_bootdir\n"); + } + die("Error: failed to publish the $what: $error\n"); } return 1; } From fe3740f9dc2b3dac1dae29620b2d281c07f739ed 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, 5 Nov 2026 21:38:54 -0300 Subject: [PATCH 085/114] test(genimage): cover the publication of a kernel with several ramdisks --- xCAT-test/unit/imgutils_staged_boot_files.t | 126 ++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 xCAT-test/unit/imgutils_staged_boot_files.t diff --git a/xCAT-test/unit/imgutils_staged_boot_files.t b/xCAT-test/unit/imgutils_staged_boot_files.t new file mode 100644 index 0000000000..44b1787c3e --- /dev/null +++ b/xCAT-test/unit/imgutils_staged_boot_files.t @@ -0,0 +1,126 @@ +#!/usr/bin/env perl +use strict; +use warnings; +## no critic (TestingAndDebugging::ProhibitNoWarnings, Variables::RequireLocalizedPunctuationVars) +use Errno qw(EACCES); +use FindBin; +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; + +BEGIN { + *CORE::GLOBAL::rename = sub { return CORE::rename($_[0], $_[1]); }; + *CORE::GLOBAL::link = sub { return CORE::link($_[0], $_[1]); }; +} +use imgutils; + +my @modes = qw(statelite stateless); +my @names = ('kernel', map { "initrd-$_.gz" } @modes); + +# Publishes a staged kernel and two ramdisks over an older set, failing the named link, rename, or rollback. +sub publish_case { + my (%case) = @_; + my $dir = tempdir(CLEANUP => 1); + my $staging = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $dir, CLEANUP => 1); + write_text("$staging/$_", "new $_\n") for @names; + if ($case{old}) { + write_text("$dir/$_", "old $_\n") for @names; + } + my ($ok, $error); + { + no warnings 'redefine'; + local *CORE::GLOBAL::link = sub { + if (defined $case{link} && $_[0] eq "$dir/$case{link}") { + $! = EACCES; + return 0; + } + return CORE::link($_[0], $_[1]); + }; + local *CORE::GLOBAL::rename = sub { + if ((defined $case{rename} && $_[0] eq "$staging/$case{rename}") + || (defined $case{rollback} && $_[0] eq "$staging/previous-$case{rollback}")) { + $! = EACCES; + return 0; + } + return CORE::rename($_[0], $_[1]); + }; + $ok = eval { imgutils::publish_staged_boot_files($staging, $dir, @modes) }; + $error = $@; + } + undef $staging; + my %state = map { $_ => (-e "$dir/$_" ? read_text("$dir/$_") : undef) } @names; + return ($ok, $error, $dir, \%state); +} + +sub set_of { + my ($age) = @_; + return { map { $_ => "$age $_\n" } @names }; +} + +for my $old (1, 0) { + my $label = $old ? 'over an older set' : 'on a first build'; + my ($ok, $error, $dir, $state) = publish_case(old => $old); + ok($ok, "publication $label completes") or diag($error); + is_deeply($state, set_of('new'), "publication $label puts the new kernel and both ramdisks in place"); + is_deeply([ glob("$dir/.genimage*") ], [], "publication $label removes the staging directory"); +} + +for my $name (@names) { + my ($ok, $error, $dir, $state) = publish_case(old => 1, link => $name); + ok(!$ok, "a failed backup of $name stops the publication"); + like($error, qr/^Error: failed to preserve the previous (?:kernel|initial ramdisk for \w+): /, "the error names the $name backup"); + is_deeply($state, set_of('old'), "a failed backup of $name keeps the older set"); +} + +for my $name (@names) { + my ($ok, $error, $dir, $state) = publish_case(old => 1, rename => $name); + ok(!$ok, "a failed rename of $name stops the publication"); + like($error, qr/^Error: failed to publish the (?:kernel|initial ramdisk for \w+): /, "the error names the $name rename"); + is_deeply($state, set_of('old'), "a failed rename of $name puts the older set back"); + is_deeply([ glob("$dir/.genimage*") ], [], "a failed rename of $name removes the staging directory"); +} + +{ + my ($ok, $error, $dir, $state) = publish_case(old => 0, rename => 'initrd-stateless.gz'); + ok(!$ok, 'a failed rename on a first build stops the publication'); + is_deeply($state, { map { $_ => undef } @names }, 'a failed rename on a first build leaves no kernel or ramdisk'); +} + +SKIP: { + skip 'link() of a symbolic link is checked on Linux', 2 unless $^O eq 'linux'; + my $dir = tempdir(CLEANUP => 1); + my $staging = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $dir, CLEANUP => 1); + write_text("$staging/$_", "new $_\n") for @names; + symlink('missing-kernel', "$dir/kernel") or die "symlink: $!"; + write_text("$dir/$_", "old $_\n") for grep { $_ ne 'kernel' } @names; + my $ok; + { + no warnings 'redefine'; + local *CORE::GLOBAL::rename = sub { + if ($_[0] eq "$staging/initrd-stateless.gz") { + $! = EACCES; + return 0; + } + return CORE::rename($_[0], $_[1]); + }; + $ok = eval { imgutils::publish_staged_boot_files($staging, $dir, @modes) }; + } + ok(!$ok, 'a failed rename over a dangling kernel link stops the publication'); + is(readlink("$dir/kernel"), 'missing-kernel', 'a dangling kernel link is put back instead of removed'); +} + +{ + my ($ok, $error, $dir, $state) = publish_case(old => 1, rename => 'initrd-stateless.gz', rollback => 'initrd-statelite.gz'); + ok(!$ok, 'a failed rollback stops the publication'); + like($error, qr/initial ramdisk for statelite rollback failed: .*Boot files retained in \Q$dir\E\/\.genimage-boot\./, + 'the error names the file that could not be put back and the directory that keeps it'); + is($state->{kernel}, "old kernel\n", 'the kernel is still put back after a failed rollback of a ramdisk'); + my ($kept) = glob("$dir/.genimage-boot.*/previous-initrd-statelite.gz"); + ok(defined $kept, 'the staging directory keeps the previous ramdisk that could not be put back'); + is(defined $kept ? read_text($kept) : undef, "old initrd-statelite.gz\n", 'the kept file is the previous ramdisk'); +} + +done_testing(); From 35b7e5a91f36ee653424476dab1eab2b2f32d7ed 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, 5 Nov 2026 21:38:54 -0300 Subject: [PATCH 086/114] fix(ubuntu): publish the kernel and ramdisks of genimage together genimage copied the kernel to the image directory before it built the initial ramdisks. When dracut failed for either ramdisk, a new kernel stayed next to the old ramdisks, and nodeset copied that set. The legacy ramdisk ignored a failed cpio pipeline and published what the compressor wrote. genimage now builds the kernel and both ramdisks in a staging directory in the image directory. It publishes them together with publish_staged_boot_files after both ramdisks are built, and writes the root image check and UFTP markers after that. A failure leaves the previous kernel and ramdisks in place. --- .../share/xcat/netboot/ubuntu/genimage | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index abfdc8216a..8b4142dad8 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -732,16 +732,20 @@ chomp($kernelver); #$updates{'kernelver'} = $kernelver if ($tempfile); -# copy the kernel to $destdir +# The kernel and the initial ramdisks wait here until genimage publishes them together. +my $native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1); +my $stateless_uftp_receiver; +my $kernel_copy; if (-e "$rootimg_dir/boot/vmlinux-$kernelver") { - cp("$rootimg_dir/boot/vmlinux-$kernelver", "$destdir/kernel"); + $kernel_copy = cp("$rootimg_dir/boot/vmlinux-$kernelver", "$native_bootdir/kernel"); } elsif (-e "$rootimg_dir/boot/vmlinuz-$kernelver") { - cp("$rootimg_dir/boot/vmlinuz-$kernelver", "$destdir/kernel"); + $kernel_copy = cp("$rootimg_dir/boot/vmlinuz-$kernelver", "$native_bootdir/kernel"); } elsif (-e "$rootimg_dir/boot/image-$kernelver") { - cp("$rootimg_dir/boot/image-$kernelver", "$destdir/kernel"); + $kernel_copy = cp("$rootimg_dir/boot/image-$kernelver", "$native_bootdir/kernel"); } else { xdie("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot"); } +die("Error: failed to copy the kernel to $native_bootdir: $!\n") unless $kernel_copy; # Load driver update disk, and copy them to the root image my @dd_drivers = &load_dd(); @@ -938,6 +942,11 @@ if ($dracutmode) { push @ndrivers, @drivers; mkinitrd("stateless"); } +eval { imgutils::publish_staged_boot_files($native_bootdir, $destdir, 'statelite', 'stateless') } or die($@); +if ($dracutmode) { + mark_rootimg_check('stateless'); + imgutils::mark_uftp_receiver("$destdir/initrd-stateless.gz", $stateless_uftp_receiver); +} sub getlibs { my $file = shift; @@ -1061,10 +1070,9 @@ sub mkinitrd_dracut { or die("Error: failed to generate the initial ramdisk for $mode.\n"); eval { imgutils::check_uftp_initrd($rootimg_dir, "/tmp/initrd.$$.gz", $mode) } or xdie($@) if $uftp_receiver; print "the initial ramdisk for $mode is generated successfully.\n"; - if (move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz")) { - mark_rootimg_check($mode); - imgutils::mark_uftp_receiver("$destdir/initrd-$mode.gz", $uftp_receiver) if $mode eq 'stateless'; - } + move("$rootimg_dir/tmp/initrd.$$.gz", "$native_bootdir/initrd-$mode.gz") + or die("Error: failed to stage the initial ramdisk for $mode: $!\n"); + $stateless_uftp_receiver = $uftp_receiver if $mode eq 'stateless'; } # nodeset warns unless this marker says that the stateless initial ramdisk checks the root image checksum. @@ -1884,9 +1892,11 @@ EOMS } #copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_"); - print "\ncd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz \n"; - system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz"); + my $initrd = "$native_bootdir/initrd-$mode.gz"; + print "\ncd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $initrd \n"; + my $rc = system('bash', '-c', "set -o pipefail; cd /tmp/xcatinitrd.$$ && find . | cpio -H newc -o | $compress -9 -c - > $initrd"); system("rm -rf /tmp/xcatinitrd.$$"); + die("Error: failed to generate the initial ramdisk for $mode.\n") if $rc; } From e859b4e39a2a18740c3214add96b2d9d6b2644a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 02:44:25 -0300 Subject: [PATCH 087/114] fix(geninitrd): report a failed genimage run geninitrd ran genimage --onlyinitrd for netboot and statelite images and ignored its exit status. When genimage failed, geninitrd still exited with 0. The errors that the genimage client writes to stderr did not reach the user. geninitrd now passes the genimage output to the client with stderr included. When genimage ends with a status other than 0, geninitrd reports an error and exits with the genimage exit code, or with 1 when genimage could not run. --- xCAT-server/lib/xcat/plugins/geninitrd.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/geninitrd.pm b/xCAT-server/lib/xcat/plugins/geninitrd.pm index 6f9388cef6..a16f231119 100644 --- a/xCAT-server/lib/xcat/plugins/geninitrd.pm +++ b/xCAT-server/lib/xcat/plugins/geninitrd.pm @@ -148,8 +148,13 @@ sub geninitrd { xCAT::MsgUtils->message("E", { error => ["The rootimgdir attribute for the osimage should be set."], errorcode => ["1"] }, $callback); return; } - my @output = `genimage $osimage --onlyinitrd`; + my @output = `genimage $osimage --onlyinitrd 2>&1`; + my $status = $?; xCAT::MsgUtils->message("I", { data => \@output }, $callback); + if ($status) { + my $rc = ($status > 0 && $status >> 8) || 1; + xCAT::MsgUtils->message("E", { error => ["genimage $osimage --onlyinitrd failed with rc $rc."] }, $callback, $rc); + } #$doreq->({ command => ['genimage'], # arg => [$osimage, '--onlyinitrd'] }, $callback); From 473c8dc9473beee1191895382a04a07f40700546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 02:44:26 -0300 Subject: [PATCH 088/114] test(geninitrd): cover the exit status of genimage --- xCAT-test/unit/geninitrd_genimage_status.t | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 xCAT-test/unit/geninitrd_genimage_status.t diff --git a/xCAT-test/unit/geninitrd_genimage_status.t b/xCAT-test/unit/geninitrd_genimage_status.t new file mode 100644 index 0000000000..d4e110bac1 --- /dev/null +++ b/xCAT-test/unit/geninitrd_genimage_status.t @@ -0,0 +1,96 @@ +#!/usr/bin/env perl +use strict; +use warnings; +## no critic (TestingAndDebugging::ProhibitNoWarnings) +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use FindBin; +use Storable qw(dclone); +use Test::More; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use XCAT::Test::File qw(repo_path); + +local $ENV{XCATROOT} = repo_path('xCAT-server'); +require(repo_path('xCAT-server/lib/xcat/plugins/geninitrd.pm')); + +my $rootimgdir = tempdir(CLEANUP => 1); +make_path("$rootimgdir/rootimg/lib/modules"); +my %attribs = ( + osimage => { provmethod => 'netboot', osvers => 'ubuntu26.04', osarch => 'riscv64' }, + linuximage => { rootimgdir => $rootimgdir, pkgdir => '/install/ubuntu26.04/riscv64' }, +); + +# The genimage client prints build output on stdout and its own errors on stderr. +my $bindir = tempdir(CLEANUP => 1); +open(my $script, '>', "$bindir/genimage") or die "genimage: $!"; +print $script <<'EOS'; +#!/bin/sh +echo "$@" > "$GENIMAGE_ARGS" +echo 'the initial ramdisks are built' +echo 'Error: genimage command failed' >&2 +exit "$GENIMAGE_RC" +EOS +close($script) or die "genimage: $!"; +chmod(0755, "$bindir/genimage") or die "genimage: $!"; +my $emptydir = tempdir(CLEANUP => 1); + +sub geninitrd_with { + my (%case) = @_; + my $args = "$bindir/args"; + unlink($args); + my @responses; + { + no warnings qw(redefine once); + local *xCAT::Table::new = sub { + my ($class, $table) = @_; + die "Unexpected table $table\n" unless $attribs{$table}; + return bless { attribs => $attribs{$table} }, 'Local::ImageTable'; + }; + local $ENV{PATH} = $case{path}; + local $ENV{GENIMAGE_RC} = $case{rc} // 0; + local $ENV{GENIMAGE_ARGS} = $args; + xCAT_plugin::geninitrd::process_request({ command => ['geninitrd'], arg => ['compute'] }, + sub { push @responses, dclone($_[0]) }, sub { die "Unexpected subrequest\n" }); + } + my %result; + if (open(my $fh, '<', $args)) { + $result{args} = do { local $/; <$fh> }; + close($fh); + } + for my $key (qw(info error errorcode)) { + $result{$key} = [ map { @{ $_->{$key} // [] } } @responses ]; + } + return \%result; +} + +{ + my $result = geninitrd_with(path => $bindir, rc => 0); + is($result->{args}, "compute --onlyinitrd\n", 'geninitrd runs genimage --onlyinitrd for the image'); + is_deeply($result->{error}, [], 'a genimage that succeeds reports no error'); + is_deeply($result->{errorcode}, [], 'a genimage that succeeds sets no exit code'); + ok((grep { /the initial ramdisks are built/ } @{ $result->{info} }), 'the genimage output reaches the client'); +} + +for my $rc (1, 2, 17) { + my $result = geninitrd_with(path => $bindir, rc => $rc); + is_deeply($result->{error}, ["genimage compute --onlyinitrd failed with rc $rc."], "a genimage that ends with $rc reports the failure"); + is_deeply($result->{errorcode}, [$rc], "the exit code of geninitrd is $rc"); + ok((grep { /Error: genimage command failed/ } @{ $result->{info} }), "the genimage error output reaches the client after rc $rc"); +} + +{ + my $result = geninitrd_with(path => $emptydir); + is_deeply($result->{error}, ['genimage compute --onlyinitrd failed with rc 1.'], 'a genimage that cannot run reports the failure'); + is_deeply($result->{errorcode}, [1], 'the exit code of geninitrd is 1 when genimage cannot run'); +} + +done_testing(); + +package Local::ImageTable; + +sub getAttribs { + my ($self) = @_; + return { %{ $self->{attribs} } }; +} From 555732abf9388f2b191abcbdc809e60c1404a117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:52:56 -0300 Subject: [PATCH 089/114] refactor(genimage): share the kernel copy and the cpio packing The Ubuntu and the Red Hat-family genimage each had their own code to find and copy the kernel of the image and to pack a cpio initial ramdisk. imgutils now has copy_kernel and pack_initrd for this, and the Ubuntu genimage uses them. copy_kernel also takes lib/modules//vmlinuz, which the Red Hat-family genimage already takes. --- .../share/xcat/netboot/imgutils/imgutils.pm | 20 +++++++++++++++++++ .../share/xcat/netboot/ubuntu/genimage | 18 ++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 611098d17a..0eb10c6d3f 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -131,6 +131,26 @@ sub skip_kdump_without_dump_memory { close($fh) or die "Cannot write $dropin_dir/xcat-dump-memory.conf: $!\n"; } +sub copy_kernel { + my ($rootimg_dir, $kernelver, $dir) = @_; + my ($kernel) = grep { -e $_ } map { "$rootimg_dir/$_" } + ("boot/vmlinux-$kernelver", "boot/vmlinuz-$kernelver", "boot/image-$kernelver", "lib/modules/$kernelver/vmlinuz"); + die("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot\n") unless $kernel; + File::Copy::cp($kernel, "$dir/kernel") or die("Error: failed to copy the kernel to $dir: $!\n"); + return 1; +} + +# Removes $dir after packing it, also when a command of the pipeline fails. +sub pack_initrd { + my ($dir, $initrd, $compress, $mode) = @_; + my $command = "cd $dir && find . | cpio -H newc -o | $compress -9 -c - > $initrd"; + print "\n$command\n"; + my $rc = system('bash', '-c', "set -o pipefail; $command"); + rmtree($dir); + die("Error: failed to generate the initial ramdisk for $mode.\n") if $rc; + return 1; +} + sub publish_boot_files { my ($native_bootdir, $destdir, $initrd, $mode) = @_; move($initrd, "$native_bootdir/initrd-$mode.gz") diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index 8b4142dad8..19cd733d3e 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -735,17 +735,7 @@ chomp($kernelver); # The kernel and the initial ramdisks wait here until genimage publishes them together. my $native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1); my $stateless_uftp_receiver; -my $kernel_copy; -if (-e "$rootimg_dir/boot/vmlinux-$kernelver") { - $kernel_copy = cp("$rootimg_dir/boot/vmlinux-$kernelver", "$native_bootdir/kernel"); -} elsif (-e "$rootimg_dir/boot/vmlinuz-$kernelver") { - $kernel_copy = cp("$rootimg_dir/boot/vmlinuz-$kernelver", "$native_bootdir/kernel"); -} elsif (-e "$rootimg_dir/boot/image-$kernelver") { - $kernel_copy = cp("$rootimg_dir/boot/image-$kernelver", "$native_bootdir/kernel"); -} else { - xdie("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot"); -} -die("Error: failed to copy the kernel to $native_bootdir: $!\n") unless $kernel_copy; +eval { imgutils::copy_kernel($rootimg_dir, $kernelver, $native_bootdir) } or xdie($@); # Load driver update disk, and copy them to the root image my @dd_drivers = &load_dd(); @@ -1892,11 +1882,7 @@ EOMS } #copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_"); - my $initrd = "$native_bootdir/initrd-$mode.gz"; - print "\ncd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $initrd \n"; - my $rc = system('bash', '-c', "set -o pipefail; cd /tmp/xcatinitrd.$$ && find . | cpio -H newc -o | $compress -9 -c - > $initrd"); - system("rm -rf /tmp/xcatinitrd.$$"); - die("Error: failed to generate the initial ramdisk for $mode.\n") if $rc; + imgutils::pack_initrd("/tmp/xcatinitrd.$$", "$native_bootdir/initrd-$mode.gz", $compress, $mode); } From 173ab102e547988691f0406539db9ab90ea9bf06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:52:57 -0300 Subject: [PATCH 090/114] test(genimage): cover the kernel copy and the cpio packing --- xCAT-test/unit/imgutils_boot_file_build.t | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 xCAT-test/unit/imgutils_boot_file_build.t diff --git a/xCAT-test/unit/imgutils_boot_file_build.t b/xCAT-test/unit/imgutils_boot_file_build.t new file mode 100644 index 0000000000..b18db9d807 --- /dev/null +++ b/xCAT-test/unit/imgutils_boot_file_build.t @@ -0,0 +1,105 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +my $release = '6.12.0-124.el10.x86_64'; + +# Copies the kernel of $release from an image root that holds the named files. +sub copy_case { + my (@files) = @_; + my $root = tempdir(CLEANUP => 1); + for my $file (@files) { + make_path("$root/" . ($file =~ s{/[^/]+$}{}r)); + write_text("$root/$file", "$file\n"); + chmod(0755, "$root/$file"); + } + my $dir = tempdir(CLEANUP => 1); + my $ok = eval { imgutils::copy_kernel($root, $release, $dir) }; + return ($ok, $@, $dir); +} + +for my $files ( + [ "boot/vmlinux-$release", "boot/vmlinuz-$release", "boot/image-$release", "lib/modules/$release/vmlinuz" ], + [ "boot/vmlinuz-$release", "boot/image-$release", "lib/modules/$release/vmlinuz" ], + [ "boot/image-$release", "lib/modules/$release/vmlinuz" ], + [ "lib/modules/$release/vmlinuz" ], +) { + my ($ok, $error, $dir) = copy_case(@$files); + ok($ok, "copies a kernel from an image with @$files") or diag($error); + is(read_text("$dir/kernel"), "$files->[0]\n", "copies $files->[0] from an image with @$files"); + is((stat("$dir/kernel"))[2] & oct(7777), oct(755), "keeps the mode of $files->[0]"); +} + +{ + my ($ok, $error, $dir) = copy_case('boot/vmlinuz-6.12.0-55.el10.x86_64', 'lib/modules/6.12.0-55.el10.x86_64/vmlinuz'); + ok(!$ok, 'fails when the image has no kernel of the release'); + like($error, qr/couldn't find the kernel file matched \Q$release\E/, 'names the release of the missing kernel'); + ok(!-e "$dir/kernel", 'copies no kernel of another release'); +} + +{ + my $root = tempdir(CLEANUP => 1); + make_path("$root/boot"); + write_text("$root/boot/vmlinuz-$release", "kernel\n"); + my $ok = eval { imgutils::copy_kernel($root, $release, "$root/missing") }; + ok(!$ok, 'fails when the kernel cannot be copied'); + like($@, qr/^Error: failed to copy the kernel to \Q$root\E\/missing: /, 'reports the failed copy'); +} + +# Packs a directory of two files, with each named command replaced by one that fails without output. +sub pack_case { + my (@failing) = @_; + my $dir = tempdir(CLEANUP => 1); + my $src = "$dir/initrd"; + make_path("$src/bin", "$dir/bin"); + write_text("$src/init", "init\n"); + write_text("$src/bin/netstart", "netstart\n"); + for my $command (@failing) { + write_text("$dir/bin/$command", "#!/bin/sh\nexit 1\n"); + chmod(0755, "$dir/bin/$command"); + } + my ($ok, $error); + { + local $ENV{PATH} = "$dir/bin:$ENV{PATH}"; + local *STDOUT; + open(STDOUT, '>', \my $printed) or die "STDOUT: $!"; + $ok = eval { imgutils::pack_initrd($src, "$dir/initrd.gz", 'gzip', 'stateless') }; + $error = $@; + } + return ($ok, $error, $dir, $src); +} + +{ + my ($ok, $error, $dir, $src) = pack_case(); + ok($ok, 'packs the initial ramdisk') or diag($error); + my @listing = sort map { chomp; $_ } `gzip -dc $dir/initrd.gz | cpio -it 2>/dev/null`; + is_deeply(\@listing, [ '.', 'bin', 'bin/netstart', 'init' ], 'the initial ramdisk holds the packed directory'); + ok(!-e $src, 'removes the packed directory'); +} + +for my $command (qw(find cpio gzip)) { + my ($ok, $error, $dir, $src) = pack_case($command); + ok(!$ok, "fails when $command fails"); + is($error, "Error: failed to generate the initial ramdisk for stateless.\n", "reports the failed $command"); + ok(!-e $src, "removes the packed directory when $command fails"); +} + +{ + my $dir = tempdir(CLEANUP => 1); + local *STDOUT; + open(STDOUT, '>', \my $printed) or die "STDOUT: $!"; + my $ok = eval { imgutils::pack_initrd("$dir/missing", "$dir/initrd.gz", 'gzip', 'statelite') }; + ok(!$ok, 'fails when the directory to pack does not exist'); + is($@, "Error: failed to generate the initial ramdisk for statelite.\n", 'reports the missing directory'); +} + +done_testing(); From 1f6f56e559aed11ce254ad7ec0f000979a9ee30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:54:20 -0300 Subject: [PATCH 091/114] test(genimage): drop the checks of the per-ramdisk publication imgutils_staged_boot_files.t covers the publication of boot files. The remaining checks of the unit test openeuler_genimage_bootfiles.t cover disable_vendor_repositories, so the file now has that name. The native EL cases checked that genimage keeps copying the kernel into place before dracut runs, which the next change removes. --- .../native/openeuler_genimage_bootfiles.t | 9 -- xCAT-test/unit/imgutils_vendor_repositories.t | 51 +++++++ xCAT-test/unit/openeuler_genimage_bootfiles.t | 140 ------------------ 3 files changed, 51 insertions(+), 149 deletions(-) create mode 100644 xCAT-test/unit/imgutils_vendor_repositories.t delete mode 100644 xCAT-test/unit/openeuler_genimage_bootfiles.t diff --git a/xCAT-test/native/openeuler_genimage_bootfiles.t b/xCAT-test/native/openeuler_genimage_bootfiles.t index 8ee520a1ad..e5d14173ec 100644 --- a/xCAT-test/native/openeuler_genimage_bootfiles.t +++ b/xCAT-test/native/openeuler_genimage_bootfiles.t @@ -59,15 +59,6 @@ is(read_text("$case/image/initrd-stateless.gz"), "old initrd\n", 'lock refusal p is_deeply($state->{commands}, [], 'lock refusal does not run mount cleanup against the active build'); is_deeply([glob("$case/image/.genimage*")], [], 'lock refusal creates no staging directory'); -for my $failure (qw(none kernel-copy dracut move-initrd)) { - ($rc, $state, $output, $case) = run_case('rhels9.6', $failure, 'vmlinuz', 1); - is($rc == 0 ? 0 : 1, $failure eq 'dracut' ? 1 : 0, "EL $failure retains its exit behavior") or diag($output); - is(read_text("$case/image/kernel"), $failure eq 'kernel-copy' ? "old kernel\n" : "new kernel\n", - "EL $failure retains kernel copy behavior"); - is($state->{dracut_calls}, $failure eq 'dracut' ? 1 : 2, "EL $failure retains both initrd modes"); - is($state->{lock_calls}, 0, "EL $failure retains its existing onlyinitrd lock behavior"); -} - done_testing(); sub run_case { diff --git a/xCAT-test/unit/imgutils_vendor_repositories.t b/xCAT-test/unit/imgutils_vendor_repositories.t new file mode 100644 index 0000000000..23be6ab85d --- /dev/null +++ b/xCAT-test/unit/imgutils_vendor_repositories.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use File::Temp qw(tempdir); +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; +use Test::More; +use imgutils; + +plan skip_all => 'requires Linux sed' unless $^O eq 'linux'; +my $dir = tempdir(CLEANUP => 1); + +my @legacy_repositories = qw(Rocky-BaseOS.repo almalinux.repo CentOS-Base.repo oracle-linux-ol10.repo); +my @custom_repositories = qw(local-repository-0.repo xCAT-custom.repo administrator.repo); +my $enabled = "[fixture]\nenabled=1\ngpgcheck=1\nbaseurl=https://repo.invalid/\n"; +my $disabled = "[fixture]\nenabled=0\ngpgcheck=1\nbaseurl=https://repo.invalid/\n"; +my $native = "[OS]\nenabled=1\ngpgcheck=1\n[update]\n \tenabled = 1\n[disabled]\nenabled=0\n#enabled=1\n"; +my $native_disabled = "[OS]\nenabled=0\ngpgcheck=1\n[update]\nenabled=0\n[disabled]\nenabled=0\n#enabled=1\n"; +for my $repository_case ( + ['enabled', $native, $native_disabled], + ['already-disabled', $native_disabled, $native_disabled], + ['absent', undef, undef], +) { + my ($name, $input, $expected) = @$repository_case; + subtest $name => sub { + my $root = tempdir(DIR => $dir, CLEANUP => 1); + my $repos = "$root/etc/yum.repos.d"; + make_path($repos); + write_text("$repos/$_", $enabled) for (@legacy_repositories, @custom_repositories); + write_text("$repos/openEuler.repo", $input) if defined $input; + for my $pass (1, 2) { + imgutils::disable_vendor_repositories($root); + if (defined $expected) { + is(read_text("$repos/openEuler.repo"), $expected, + "pass $pass disables only active native repository assignments"); + } else { + ok(!-e "$repos/openEuler.repo", "pass $pass does not create an absent vendor file"); + } + is(read_text("$repos/$_"), $disabled, "pass $pass preserves policy for $_") + for @legacy_repositories; + is(read_text("$repos/$_"), $enabled, "pass $pass leaves $_ unchanged") + for @custom_repositories; + } + }; +} + +done_testing(); diff --git a/xCAT-test/unit/openeuler_genimage_bootfiles.t b/xCAT-test/unit/openeuler_genimage_bootfiles.t deleted file mode 100644 index a4cbbcaa07..0000000000 --- a/xCAT-test/unit/openeuler_genimage_bootfiles.t +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Errno qw(EACCES EIO); -use FindBin; -use File::Path qw(make_path); -use File::Slurper qw(read_text write_text); -use File::Temp qw(tempdir); -use lib "$FindBin::Bin/../../perl-xCAT"; -use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; -use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils"; -use Test::More; - -BEGIN { - *CORE::GLOBAL::rename = sub { return CORE::rename($_[0], $_[1]); }; - *CORE::GLOBAL::link = sub { return CORE::link($_[0], $_[1]); }; -} -use imgutils; - -my $dir = tempdir(CLEANUP => 1); - -for my $mode (qw(stateless statelite)) { - for my $failure (qw(none move-initrd backup-kernel publish-kernel publish-initrd)) { - my ($ok, $error, $case) = publish_case($mode, $failure, 1); - my $label = "$mode $failure"; - if ($failure eq 'none') { - ok($ok, "$label completes") or diag($error); - is(read_text("$case/kernel"), "new kernel\n", "$label publishes the kernel"); - is(read_text("$case/initrd-$mode.gz"), "new initrd\n", "$label publishes the initrd"); - } else { - ok(!$ok, "$label fails"); - like($error, qr/Error: failed to (?:move|publish|preserve).*?(?:kernel|ramdisk)/i, - "$label reports the failed boot file operation"); - is(read_text("$case/kernel"), "old kernel\n", "$label preserves the previous kernel"); - is(read_text("$case/initrd-$mode.gz"), "old initrd\n", "$label preserves the previous initrd"); - } - is_deeply([glob("$case/.genimage*")], [], "$label removes boot staging files"); - } -} - -my ($ok, $error, $case) = publish_case('stateless', 'publish-initrd', 0); -ok(!$ok, 'first build publication failure is fatal'); -ok(!-e "$case/kernel", 'first build failure removes the unpaired kernel'); -ok(!-e "$case/initrd-stateless.gz", 'first build failure does not expose an initrd'); -is_deeply([glob("$case/.genimage*")], [], 'first build failure removes boot staging files'); - -($ok, $error, $case) = publish_case('stateless', 'rollback', 1); -ok(!$ok, 'rollback failure is fatal'); -my @backups = glob("$case/.genimage*/previous-kernel"); -is(scalar(@backups), 1, 'rollback failure retains one previous kernel backup'); -is(read_text($backups[0]), "old kernel\n", 'retained backup contains the previous kernel'); -like($error, qr/kernel rollback failed: .*Boot files retained in \Q$case\E\/\.genimage/, - 'rollback failure reports the recoverable backup directory'); -is(read_text("$case/initrd-stateless.gz"), "old initrd\n", 'rollback failure preserves previous initrd'); - -subtest 'vendor repositories' => sub { - plan skip_all => 'requires Linux sed' unless $^O eq 'linux'; - my @legacy_repositories = qw(Rocky-BaseOS.repo almalinux.repo CentOS-Base.repo oracle-linux-ol10.repo); - my @custom_repositories = qw(local-repository-0.repo xCAT-custom.repo administrator.repo); - my $enabled = "[fixture]\nenabled=1\ngpgcheck=1\nbaseurl=https://repo.invalid/\n"; - my $disabled = "[fixture]\nenabled=0\ngpgcheck=1\nbaseurl=https://repo.invalid/\n"; - my $native = "[OS]\nenabled=1\ngpgcheck=1\n[update]\n \tenabled = 1\n[disabled]\nenabled=0\n#enabled=1\n"; - my $native_disabled = "[OS]\nenabled=0\ngpgcheck=1\n[update]\nenabled=0\n[disabled]\nenabled=0\n#enabled=1\n"; - for my $repository_case ( - ['enabled', $native, $native_disabled], - ['already-disabled', $native_disabled, $native_disabled], - ['absent', undef, undef], - ) { - my ($name, $input, $expected) = @$repository_case; - subtest $name => sub { - my $root = tempdir(DIR => $dir, CLEANUP => 1); - my $repos = "$root/etc/yum.repos.d"; - make_path($repos); - write_text("$repos/$_", $enabled) for (@legacy_repositories, @custom_repositories); - write_text("$repos/openEuler.repo", $input) if defined $input; - for my $pass (1, 2) { - imgutils::disable_vendor_repositories($root); - if (defined $expected) { - is(read_text("$repos/openEuler.repo"), $expected, - "pass $pass disables only active native repository assignments"); - } else { - ok(!-e "$repos/openEuler.repo", "pass $pass does not create an absent vendor file"); - } - is(read_text("$repos/$_"), $disabled, "pass $pass preserves policy for $_") - for @legacy_repositories; - is(read_text("$repos/$_"), $enabled, "pass $pass leaves $_ unchanged") - for @custom_repositories; - } - }; - } -}; - -done_testing(); - -sub publish_case { - my ($mode, $failure, $old) = @_; - my $case = tempdir(DIR => $dir, CLEANUP => 1); - make_path("$case/tmp"); - my $staging = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $case, CLEANUP => 1); - write_text("$staging/kernel", "new kernel\n"); - write_text("$case/tmp/initrd.gz", "new initrd\n"); - if ($old) { - write_text("$case/kernel", "old kernel\n"); - write_text("$case/initrd-$mode.gz", "old initrd\n"); - } - - my $move = \&imgutils::move; - my ($ok, $error); - { - no warnings 'redefine'; - local *imgutils::move = sub { - if ($failure eq 'move-initrd') { - $! = EIO; - return 0; - } - return $move->(@_); - }; - local *CORE::GLOBAL::link = sub { - if ($failure eq 'backup-kernel') { - $! = EACCES; - return 0; - } - return CORE::link($_[0], $_[1]); - }; - local *CORE::GLOBAL::rename = sub { - if (($failure =~ /^(?:publish-initrd|rollback)$/ - && $_[1] eq "$case/initrd-$mode.gz") - || ($failure eq 'publish-kernel' && $_[1] eq "$case/kernel") - || ($failure eq 'rollback' && $_[0] =~ m{/previous-kernel$})) { - $! = EACCES; - return 0; - } - return CORE::rename($_[0], $_[1]); - }; - $ok = eval { imgutils::publish_boot_files($staging, $case, "$case/tmp/initrd.gz", $mode); }; - $error = $@; - } - undef $staging; - return ($ok, $error, $case); -} From 876ff7bfe0be19a686097bf2dfb20b71ef034717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 14:54:46 -0300 Subject: [PATCH 092/114] fix(genimage): publish the EL kernel and ramdisks together The Red Hat-family genimage staged and published the boot files only for openEuler. For the other releases, it copied the kernel into the image directory before it built the initial ramdisks, and it ignored a failed kernel copy and a failed move of a ramdisk. When dracut failed, the new kernel stayed next to the ramdisks of the earlier build. On images without dracut, a failed cpio replaced the ramdisks with empty archives. genimage now builds the kernel and both ramdisks in a temporary directory inside the image directory for every release, and publishes them with publish_staged_boot_files after both ramdisks are built. It stops when the kernel copy, dracut, the move of a ramdisk or any command of the cpio pipeline fails. openEuler keeps its single stateless ramdisk. --- .../share/xcat/netboot/imgutils/imgutils.pm | 9 +-- xCAT-server/share/xcat/netboot/rh/genimage | 56 ++++++------------- 2 files changed, 17 insertions(+), 48 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 0eb10c6d3f..2b7653defd 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -7,7 +7,7 @@ use strict; use warnings "all"; use File::Basename; -use File::Copy qw(move); +use File::Copy (); use File::Find; use File::Path; use Cwd qw(realpath); @@ -151,13 +151,6 @@ sub pack_initrd { return 1; } -sub publish_boot_files { - my ($native_bootdir, $destdir, $initrd, $mode) = @_; - move($initrd, "$native_bootdir/initrd-$mode.gz") - or die("Error: failed to move the initial ramdisk for $mode: $!\n"); - return publish_staged_boot_files($native_bootdir, $destdir, $mode); -} - # nodeset copies the kernel and the initial ramdisks as one set, so a failure puts back every file already replaced. sub publish_staged_boot_files { my ($native_bootdir, $destdir, @modes) = @_; diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index eb6782f712..80cab0c764 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -72,11 +72,11 @@ my $lock; my $envar; my $gpgcheck; my $native_bootdir; +my $stateless_uftp_receiver; sub xdie { - unlink("$rootimg_dir/tmp/initrd.$$.gz") - if $rootimg_dir && defined(imgutils::openeuler_release_version($osver)); + unlink("$rootimg_dir/tmp/initrd.$$.gz") if $rootimg_dir; system("rm -rf /tmp/xcatinitrd.$$"); umount_chroot($rootimg_dir); die @_; @@ -719,26 +719,9 @@ chomp($kernelver); #$updates{'kernelver'} = $kernelver if ($tempfile); -# copy the kernel to $destdir -my $kernel_output = "$destdir/kernel"; -if (defined(imgutils::openeuler_release_version($osver))) { - $native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1); - $kernel_output = "$native_bootdir/kernel"; -} -my $kernel_copy; -if (-e "$rootimg_dir/boot/vmlinux-$kernelver") { - $kernel_copy = cp("$rootimg_dir/boot/vmlinux-$kernelver", $kernel_output); -} elsif (-e "$rootimg_dir/boot/vmlinuz-$kernelver") { - $kernel_copy = cp("$rootimg_dir/boot/vmlinuz-$kernelver", $kernel_output); -} elsif (-e "$rootimg_dir/boot/image-$kernelver") { - $kernel_copy = cp("$rootimg_dir/boot/image-$kernelver", $kernel_output); -} elsif (-e "$rootimg_dir/lib/modules/$kernelver/vmlinuz") { - $kernel_copy = cp("$rootimg_dir/lib/modules/$kernelver/vmlinuz", $kernel_output); -} else { - xdie("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot"); -} -xdie("Error: failed to copy the kernel to $kernel_output: $!\n") - if $native_bootdir && !$kernel_copy; +# The kernel and the initial ramdisks wait here until genimage publishes them together. +$native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1); +eval { imgutils::copy_kernel($rootimg_dir, $kernelver, $native_bootdir) } or xdie($@); # Load driver update disk, and copy them to the root image my @dd_drivers = &load_dd(); @@ -818,7 +801,7 @@ if ((-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut")) print "Enter the dracut mode. Dracut version: $dracutver. Dracut directory: $dracutdir.\n"; } xdie("Error: failed to generate the initial ramdisk: native image has no dracut installation\n") - if $native_bootdir && !$dracutmode; + if !$dracutmode && defined(imgutils::openeuler_release_version($osver)); imgutils::disable_vendor_repositories($rootimg_dir); imgutils::skip_kdump_without_dump_memory($rootimg_dir); @@ -1014,6 +997,12 @@ if ($dracutmode) { mkinitrd("statelite"); mkinitrd("stateless"); } +my @initrd_modes = defined(imgutils::openeuler_release_version($osver)) ? ('stateless') : ('statelite', 'stateless'); +eval { imgutils::publish_staged_boot_files($native_bootdir, $destdir, @initrd_modes) } or xdie($@); +if ($dracutmode) { + mark_rootimg_check('stateless'); + mark_uftp_receiver('stateless', $stateless_uftp_receiver); +} sub getlibs { my $file = shift; @@ -1305,22 +1294,10 @@ sub mkinitrd_dracut { or xdie("Error: failed to generate the initial ramdisk for $mode.\n"); umount_chroot($rootimg_dir); eval { imgutils::check_uftp_initrd($rootimg_dir, "/tmp/initrd.$$.gz", $mode) } or xdie($@) if $uftp_receiver; - if ($native_bootdir) { - eval { - imgutils::publish_boot_files($native_bootdir, $destdir, - "$rootimg_dir/tmp/initrd.$$.gz", $mode); - } or xdie($@); - print "the initial ramdisk for $mode is generated successfully.\n"; - mark_rootimg_check($mode); - mark_uftp_receiver($mode, $uftp_receiver); - return; - } + move("$rootimg_dir/tmp/initrd.$$.gz", "$native_bootdir/initrd-$mode.gz") + or xdie("Error: failed to move the initial ramdisk for $mode: $!\n"); print "the initial ramdisk for $mode is generated successfully.\n"; - print("Move $rootimg_dir/tmp/initrd.$$.gz -> $destdir/initrd-$mode.gz\n"); - if (move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz")) { - mark_rootimg_check($mode); - mark_uftp_receiver($mode, $uftp_receiver); - } + $stateless_uftp_receiver = $uftp_receiver if $mode eq 'stateless'; } # nodeset warns unless this marker says that the stateless initial ramdisk checks the root image checksum. @@ -2058,8 +2035,7 @@ EOMS system("mkdir -p /tmp/xcatinitrd.$$/var/run/netreport"); #copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_"); - system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd-$mode.gz"); - system("rm -rf /tmp/xcatinitrd.$$"); + eval { imgutils::pack_initrd("/tmp/xcatinitrd.$$", "$native_bootdir/initrd-$mode.gz", 'gzip', $mode) } or xdie($@); } From 6b2c183246bbb0de274979858e8ae0506031fb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:08:51 -0300 Subject: [PATCH 093/114] test(genimage): cover the staged publication of EL boot files --- .../native/openeuler_genimage_bootfiles.t | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/xCAT-test/native/openeuler_genimage_bootfiles.t b/xCAT-test/native/openeuler_genimage_bootfiles.t index e5d14173ec..fb53044b10 100644 --- a/xCAT-test/native/openeuler_genimage_bootfiles.t +++ b/xCAT-test/native/openeuler_genimage_bootfiles.t @@ -59,6 +59,27 @@ is(read_text("$case/image/initrd-stateless.gz"), "old initrd\n", 'lock refusal p is_deeply($state->{commands}, [], 'lock refusal does not run mount cleanup against the active build'); is_deeply([glob("$case/image/.genimage*")], [], 'lock refusal creates no staging directory'); +my %el_dracut_calls = (none => 2, 'kernel-copy' => 0, dracut => 1, 'move-initrd' => 1, 'publish-initrd' => 2); +for my $failure (qw(none kernel-copy dracut move-initrd publish-initrd)) { + ($rc, $state, $output, $case) = run_case('rhels9.6', $failure, 'vmlinuz', 1); + my $label = "EL $failure"; + my $set = $failure eq 'none' ? 'new' : 'old'; + if ($failure eq 'none') { + is($rc, 0, "$label completes") or diag($output); + } else { + isnt($rc, 0, "$label fails"); + like($output, qr/Error: failed to (?:copy|generate|move|publish).*?(?:kernel|ramdisk)/i, + "$label reports the failed boot file operation"); + } + is(read_text("$case/image/kernel"), "$set kernel\n", "$label leaves the $set kernel"); + is(read_text("$case/image/initrd-$_.gz"), "$set initrd\n", "$label leaves the $set $_ initrd") + for qw(statelite stateless); + is($state->{dracut_calls}, $el_dracut_calls{$failure}, "$label stops at the first failed step"); + is($state->{lock_calls}, 0, "$label retains its existing onlyinitrd lock behavior"); + is_deeply([glob("$case/image/rootimg/tmp/initrd.*.gz")], [], "$label removes temporary dracut output"); + is_deeply([glob("$case/image/.genimage*")], [], "$label removes boot staging files"); +} + done_testing(); sub run_case { @@ -77,7 +98,7 @@ sub run_case { chmod 0000, $kernel_file if $failure eq 'kernel-copy'; if ($old) { write_text("$case/image/kernel", "old kernel\n"); - write_text("$case/image/initrd-stateless.gz", "old initrd\n"); + write_text("$case/image/initrd-$_.gz", "old initrd\n") for qw(statelite stateless); } if ($repositories) { make_path("$root/etc/yum.repos.d"); From 4fc0d3e211d29cc0d91911f39d5f13e3f7304339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:10:27 -0300 Subject: [PATCH 094/114] docs(genimage): describe how genimage builds and publishes boot files The page also names the genimage scripts that do not follow the rules yet. --- .../guides/code/genimage_boot_files.rst | 53 +++++++++++++++++++ docs/source/developers/guides/code/index.rst | 1 + 2 files changed, 54 insertions(+) create mode 100644 docs/source/developers/guides/code/genimage_boot_files.rst diff --git a/docs/source/developers/guides/code/genimage_boot_files.rst b/docs/source/developers/guides/code/genimage_boot_files.rst new file mode 100644 index 0000000000..8c075d3947 --- /dev/null +++ b/docs/source/developers/guides/code/genimage_boot_files.rst @@ -0,0 +1,53 @@ +genimage Boot Files +=================== + +Every ``genimage`` script builds a kernel and one or more initial ramdisks for +a diskless image, and writes them to the image directory, the ``rootimgdir`` of +the osimage. ``geninitrd`` runs ``genimage --onlyinitrd``, which takes the +same steps. +``nodeset`` copies the kernel and the ramdisks as one set, so the files in the +image directory must always come from the same build. + +Rules +----- + +#. Build the boot files in a staging directory inside the image directory. + Create it with ``File::Temp->newdir`` in the image directory, so that each + file moves into place with a ``rename`` on the same file system. +#. Copy the kernel of the image with ``imgutils::copy_kernel``. +#. Pack a ramdisk without dracut with ``imgutils::pack_initrd``. It stops + when any command of the ``find``, ``cpio`` and compression pipeline fails. +#. Stop when a step fails: the kernel copy, dracut, the move of a ramdisk into + the staging directory, or the cpio pipeline. Exit with a status other than + 0, and leave the earlier boot files in the image directory. +#. Publish the kernel and all the ramdisks with + ``imgutils::publish_staged_boot_files`` after the last ramdisk is built. If + a move fails, it puts back the files that it already replaced. +#. Write the ``rootimgcheck`` and UFTP markers after the publication. They + describe the published stateless ramdisk. +#. Put code that more than one ``genimage`` script needs in ``imgutils.pm``. + Do not copy it into another script. When a fix applies to more than one + release, do not limit it to one release. + +Scripts +------- + +``rh/genimage`` follows these rules. It is the ``genimage`` of RHEL, +AlmaLinux, Rocky Linux, CentOS, Oracle Linux, Scientific Linux, Fedora and +openEuler. ``ubuntu/genimage`` also follows them. + +The ``sles``, ``suse``, ``debian`` and ``fedora12`` scripts still write the +kernel and the ramdisks directly into the image directory. + +Tests +----- + +``xCAT-test/unit/imgutils_boot_file_build.t`` and +``xCAT-test/unit/imgutils_staged_boot_files.t`` cover the ``imgutils`` +functions. ``xCAT-test/native/openeuler_genimage_bootfiles.t`` runs +``rh/genimage --onlyinitrd`` for openEuler and EL images, with a failure in +each step. + +A change to the boot file steps of a ``genimage`` script also needs a +``geninitrd`` run on a real image with a failed dracut. After the run, the +image directory must hold the earlier kernel and ramdisks. diff --git a/docs/source/developers/guides/code/index.rst b/docs/source/developers/guides/code/index.rst index 968bf79795..9ec74159bd 100644 --- a/docs/source/developers/guides/code/index.rst +++ b/docs/source/developers/guides/code/index.rst @@ -9,5 +9,6 @@ Code Development debug.rst dhcp_backend_validation_matrix.rst genesis_openembedded_plan.rst + genimage_boot_files.rst kea_dhcp_backend_plan.rst tips.rst From 9a02347d973c17cb55cfbebf7826ca530464b9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:19:24 -0300 Subject: [PATCH 095/114] fix(genimage): put back a boot file that a failed rename moved On NFS, a rename can take effect and still report a failure after the client retries the request. publish_staged_boot_files then put back only the files that it published before, so the new file stayed next to the older set, and the staging cleanup removed its backup. When the staged copy of the file is gone after a failed rename, publish_staged_boot_files now puts back that file too. --- xCAT-server/share/xcat/netboot/imgutils/imgutils.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 2b7653defd..653a0b8254 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -169,8 +169,10 @@ sub publish_staged_boot_files { next; } my $error = $!; + # NFS can apply a rename and still report a failure, so put back a staged file that is gone. + my @attempted = (-e "$native_bootdir/$name" || -l "$native_bootdir/$name") ? () : ($file); my @failed; - foreach my $done (reverse @published) { + foreach my $done (@attempted, reverse @published) { my ($done_name, $done_what) = @$done; my $previous = "$native_bootdir/previous-$done_name"; my $restored = (-e $previous || -l $previous) From 7f51e1da883b0e86f37d333fe06fad36099010c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:19:24 -0300 Subject: [PATCH 096/114] test(genimage): cover a rename that fails after it moved the file --- xCAT-test/unit/imgutils_staged_boot_files.t | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/xCAT-test/unit/imgutils_staged_boot_files.t b/xCAT-test/unit/imgutils_staged_boot_files.t index 44b1787c3e..7bdd85d6d8 100644 --- a/xCAT-test/unit/imgutils_staged_boot_files.t +++ b/xCAT-test/unit/imgutils_staged_boot_files.t @@ -2,7 +2,7 @@ use strict; use warnings; ## no critic (TestingAndDebugging::ProhibitNoWarnings, Variables::RequireLocalizedPunctuationVars) -use Errno qw(EACCES); +use Errno qw(EACCES EIO); use FindBin; use File::Slurper qw(read_text write_text); use File::Temp qw(tempdir); @@ -20,7 +20,7 @@ use imgutils; my @modes = qw(statelite stateless); my @names = ('kernel', map { "initrd-$_.gz" } @modes); -# Publishes a staged kernel and two ramdisks over an older set, failing the named link, rename, or rollback. +# Publishes a staged kernel and two ramdisks over an older set, failing the named link, rename, applied rename, or rollback. sub publish_case { my (%case) = @_; my $dir = tempdir(CLEANUP => 1); @@ -40,6 +40,11 @@ sub publish_case { return CORE::link($_[0], $_[1]); }; local *CORE::GLOBAL::rename = sub { + if (defined $case{applied} && $_[0] eq "$staging/$case{applied}") { + CORE::rename($_[0], $_[1]); + $! = EIO; + return 0; + } if ((defined $case{rename} && $_[0] eq "$staging/$case{rename}") || (defined $case{rollback} && $_[0] eq "$staging/previous-$case{rollback}")) { $! = EACCES; @@ -83,6 +88,19 @@ for my $name (@names) { is_deeply([ glob("$dir/.genimage*") ], [], "a failed rename of $name removes the staging directory"); } +for my $name (@names) { + my ($ok, $error, $dir, $state) = publish_case(old => 1, applied => $name); + ok(!$ok, "a rename of $name that reports a failure after it moved the file stops the publication"); + is_deeply($state, set_of('old'), "a rename of $name that reports a failure after it moved the file puts the older set back"); + is_deeply([ glob("$dir/.genimage*") ], [], "a rename of $name that reports a failure after it moved the file removes the staging directory"); +} + +{ + my ($ok, $error, $dir, $state) = publish_case(old => 0, applied => 'initrd-stateless.gz'); + ok(!$ok, 'a rename that reports a failure after it moved the file on a first build stops the publication'); + is_deeply($state, { map { $_ => undef } @names }, 'a rename that reports a failure after it moved the file on a first build leaves no kernel or ramdisk'); +} + { my ($ok, $error, $dir, $state) = publish_case(old => 0, rename => 'initrd-stateless.gz'); ok(!$ok, 'a failed rename on a first build stops the publication'); From 8a059f4665fe9e87db23cb5540368346c831ade7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:25:36 -0300 Subject: [PATCH 097/114] fix(genimage): restore boot files from the recorded backups publish_staged_boot_files looked for the backup of a file during the rollback to decide whether to restore it or remove the published file. When that lookup failed, it removed the published file, and the staging cleanup then removed the backup. publish_staged_boot_files now records each backup that it makes and rolls back from that record. A file without an earlier copy is one for which link reports ENOENT. Any other link error stops the publication. --- .../share/xcat/netboot/imgutils/imgutils.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index 653a0b8254..ba612c6dec 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -155,11 +155,14 @@ sub pack_initrd { sub publish_staged_boot_files { my ($native_bootdir, $destdir, @modes) = @_; my @files = ([ 'kernel', 'kernel' ], map { [ "initrd-$_.gz", "initial ramdisk for $_" ] } @modes); + my %backup; foreach my $file (@files) { my ($name, $what) = @$file; - next unless -e "$destdir/$name" || -l "$destdir/$name"; - link("$destdir/$name", "$native_bootdir/previous-$name") - or die("Error: failed to preserve the previous $what: $!\n"); + if (link("$destdir/$name", "$native_bootdir/previous-$name")) { + $backup{$name} = 1; + } elsif (!$!{ENOENT}) { + die("Error: failed to preserve the previous $what: $!\n"); + } } my @published; foreach my $file (@files) { @@ -174,9 +177,8 @@ sub publish_staged_boot_files { my @failed; foreach my $done (@attempted, reverse @published) { my ($done_name, $done_what) = @$done; - my $previous = "$native_bootdir/previous-$done_name"; - my $restored = (-e $previous || -l $previous) - ? rename($previous, "$destdir/$done_name") + my $restored = $backup{$done_name} + ? rename("$native_bootdir/previous-$done_name", "$destdir/$done_name") : unlink("$destdir/$done_name"); push @failed, "$done_what rollback failed: $!" unless $restored; } From 454fe5978472e6b78fae958d820d191ca3a635be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:25:36 -0300 Subject: [PATCH 098/114] test(genimage): cover a rollback whose backup is gone --- xCAT-test/unit/imgutils_staged_boot_files.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xCAT-test/unit/imgutils_staged_boot_files.t b/xCAT-test/unit/imgutils_staged_boot_files.t index 7bdd85d6d8..2650607fca 100644 --- a/xCAT-test/unit/imgutils_staged_boot_files.t +++ b/xCAT-test/unit/imgutils_staged_boot_files.t @@ -20,7 +20,7 @@ use imgutils; my @modes = qw(statelite stateless); my @names = ('kernel', map { "initrd-$_.gz" } @modes); -# Publishes a staged kernel and two ramdisks over an older set, failing the named link, rename, applied rename, or rollback. +# Publishes a staged kernel and two ramdisks over an older set, with the faults that %case names. sub publish_case { my (%case) = @_; my $dir = tempdir(CLEANUP => 1); @@ -47,6 +47,7 @@ sub publish_case { } if ((defined $case{rename} && $_[0] eq "$staging/$case{rename}") || (defined $case{rollback} && $_[0] eq "$staging/previous-$case{rollback}")) { + unlink("$staging/previous-$case{lost}") if defined $case{lost}; $! = EACCES; return 0; } @@ -141,4 +142,14 @@ SKIP: { is(defined $kept ? read_text($kept) : undef, "old initrd-statelite.gz\n", 'the kept file is the previous ramdisk'); } +{ + my ($ok, $error, $dir, $state) = publish_case(old => 1, rename => 'initrd-stateless.gz', lost => 'kernel'); + ok(!$ok, 'a rollback whose backup is gone stops the publication'); + like($error, qr/kernel rollback failed: .*Boot files retained in \Q$dir\E\/\.genimage-boot\./, + 'the error names the kernel whose backup is gone'); + is($state->{kernel}, "new kernel\n", 'the published kernel is not removed when its backup is gone'); + is($state->{'initrd-statelite.gz'}, "old initrd-statelite.gz\n", 'the ramdisk with a backup is still put back'); + ok(scalar(glob("$dir/.genimage-boot.*")), 'the staging directory is kept when a backup is gone'); +} + done_testing(); From cb750451140f713977ef6db71ddd3d4016c96fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:31:38 -0300 Subject: [PATCH 099/114] test(genimage): stop checking that EL geninitrd runs without the lock --- xCAT-test/native/openeuler_genimage_bootfiles.t | 1 - 1 file changed, 1 deletion(-) diff --git a/xCAT-test/native/openeuler_genimage_bootfiles.t b/xCAT-test/native/openeuler_genimage_bootfiles.t index fb53044b10..d8ad2d048e 100644 --- a/xCAT-test/native/openeuler_genimage_bootfiles.t +++ b/xCAT-test/native/openeuler_genimage_bootfiles.t @@ -75,7 +75,6 @@ for my $failure (qw(none kernel-copy dracut move-initrd publish-initrd)) { is(read_text("$case/image/initrd-$_.gz"), "$set initrd\n", "$label leaves the $set $_ initrd") for qw(statelite stateless); is($state->{dracut_calls}, $el_dracut_calls{$failure}, "$label stops at the first failed step"); - is($state->{lock_calls}, 0, "$label retains its existing onlyinitrd lock behavior"); is_deeply([glob("$case/image/rootimg/tmp/initrd.*.gz")], [], "$label removes temporary dracut output"); is_deeply([glob("$case/image/.genimage*")], [], "$label removes boot staging files"); } From a53b65a96d770d6e2c78fad5af913248b5f63cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:31:39 -0300 Subject: [PATCH 100/114] fix(genimage): take the image lock for every EL geninitrd run The Red Hat-family genimage took the image operation lock with --onlyinitrd only for openEuler. Two geninitrd runs on another release, or a geninitrd run during packimage, could publish and roll back boot files over each other. genimage now takes the lock with --onlyinitrd for every release, as it already does for a full build. --- xCAT-server/share/xcat/netboot/rh/genimage | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 80cab0c764..924c15f7cd 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -303,13 +303,11 @@ if($onlyinitrd){ print("the root image directory \"$rootimg_dir\"does not exist, please run \"genimage $imagename\" to generate the root image directory first!\n"); exit 1; } - if (defined(imgutils::openeuler_release_version($osver))) { - my $retcode; - ($retcode, $lock) = xCAT::Utils->acquire_lock_imageop($rootimg_dir); - if ($retcode) { - print "Could not acquire image operation lock for $rootimg_dir\n"; - exit 1; - } + my $retcode; + ($retcode, $lock) = xCAT::Utils->acquire_lock_imageop($rootimg_dir); + if ($retcode) { + print "Could not acquire image operation lock for $rootimg_dir\n"; + exit 1; } }else { From 9df65310a8332e11a6cc4e4faa2a31362c9b715c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:32:09 -0300 Subject: [PATCH 101/114] test(genimage): cover the image lock of EL geninitrd --- .../native/openeuler_genimage_bootfiles.t | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/xCAT-test/native/openeuler_genimage_bootfiles.t b/xCAT-test/native/openeuler_genimage_bootfiles.t index d8ad2d048e..a594995650 100644 --- a/xCAT-test/native/openeuler_genimage_bootfiles.t +++ b/xCAT-test/native/openeuler_genimage_bootfiles.t @@ -49,15 +49,19 @@ for my $kernel (qw(vmlinux image modules)) { is(read_text("$case/image/kernel"), "new kernel\n", "$kernel layout publishes its kernel"); is(read_text("$case/image/initrd-stateless.gz"), "new initrd\n", "$kernel layout publishes its initrd"); } -my ($rc, $state, $output, $case) = run_case('openeuler24.03sp3', 'lock', 'vmlinuz', 1); -isnt($rc, 0, 'lock refusal is fatal'); -like($output, qr/Could not acquire image operation lock/, 'lock refusal reports the contested image'); -is($state->{lock_calls}, 1, 'lock refusal uses the existing lock owner'); -is($state->{dracut_calls}, 0, 'lock refusal does not run dracut'); -is(read_text("$case/image/kernel"), "old kernel\n", 'lock refusal preserves kernel'); -is(read_text("$case/image/initrd-stateless.gz"), "old initrd\n", 'lock refusal preserves initrd'); -is_deeply($state->{commands}, [], 'lock refusal does not run mount cleanup against the active build'); -is_deeply([glob("$case/image/.genimage*")], [], 'lock refusal creates no staging directory'); +my ($rc, $state, $output, $case); +for my $os (qw(openeuler24.03sp3 rhels9.6)) { + ($rc, $state, $output, $case) = run_case($os, 'lock', 'vmlinuz', 1); + isnt($rc, 0, "$os lock refusal is fatal"); + like($output, qr/Could not acquire image operation lock/, "$os lock refusal reports the contested image"); + is($state->{lock_calls}, 1, "$os lock refusal uses the existing lock owner"); + is($state->{dracut_calls}, 0, "$os lock refusal does not run dracut"); + is(read_text("$case/image/kernel"), "old kernel\n", "$os lock refusal preserves kernel"); + is(read_text("$case/image/initrd-$_.gz"), "old initrd\n", "$os lock refusal preserves the $_ initrd") + for qw(statelite stateless); + is_deeply($state->{commands}, [], "$os lock refusal does not run mount cleanup against the active build"); + is_deeply([glob("$case/image/.genimage*")], [], "$os lock refusal creates no staging directory"); +} my %el_dracut_calls = (none => 2, 'kernel-copy' => 0, dracut => 1, 'move-initrd' => 1, 'publish-initrd' => 2); for my $failure (qw(none kernel-copy dracut move-initrd publish-initrd)) { @@ -75,6 +79,7 @@ for my $failure (qw(none kernel-copy dracut move-initrd publish-initrd)) { is(read_text("$case/image/initrd-$_.gz"), "$set initrd\n", "$label leaves the $set $_ initrd") for qw(statelite stateless); is($state->{dracut_calls}, $el_dracut_calls{$failure}, "$label stops at the first failed step"); + is($state->{lock_calls}, 1, "$label acquires the image operation lock"); is_deeply([glob("$case/image/rootimg/tmp/initrd.*.gz")], [], "$label removes temporary dracut output"); is_deeply([glob("$case/image/.genimage*")], [], "$label removes boot staging files"); } From cec5fd2557ba7448aca59b88ad5e5fde623428d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 6 Nov 2026 15:32:09 -0300 Subject: [PATCH 102/114] docs(genimage): require the image lock for boot file publication --- docs/source/developers/guides/code/genimage_boot_files.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/source/developers/guides/code/genimage_boot_files.rst b/docs/source/developers/guides/code/genimage_boot_files.rst index 8c075d3947..1e72f84e94 100644 --- a/docs/source/developers/guides/code/genimage_boot_files.rst +++ b/docs/source/developers/guides/code/genimage_boot_files.rst @@ -11,6 +11,10 @@ image directory must always come from the same build. Rules ----- +#. Hold the image operation lock of the root image, + ``xCAT::Utils->acquire_lock_imageop``, also with ``--onlyinitrd``. The + rollback of a failed publication restores earlier files, so two runs on + the same image must not overlap. #. Build the boot files in a staging directory inside the image directory. Create it with ``File::Temp->newdir`` in the image directory, so that each file moves into place with a ``rename`` on the same file system. @@ -34,7 +38,8 @@ Scripts ``rh/genimage`` follows these rules. It is the ``genimage`` of RHEL, AlmaLinux, Rocky Linux, CentOS, Oracle Linux, Scientific Linux, Fedora and -openEuler. ``ubuntu/genimage`` also follows them. +openEuler. ``ubuntu/genimage`` follows them, except that it does not take +the image operation lock. The ``sles``, ``suse``, ``debian`` and ``fedora12`` scripts still write the kernel and the ramdisks directly into the image directory. From 21b24f1e7d0dadbd574a7e5a53f46f8fa7907996 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:34:05 -0300 Subject: [PATCH 103/114] fix(xcat-core): use_host_resolver dies on an undefined subroutine move imgutils.pm imports File::Copy with an empty list, so the module exports no function and a bare move() is not defined. use_host_resolver calls move() unqualified, so it dies with "Undefined subroutine &imgutils::move called" the first time genimage reaches it, before it has moved either file aside. Every other call site in the file already qualifies the name: File::Copy::cp at line 139, File::Copy::copy at 208 and at 302, the last of them two lines below the defect. The call is now qualified the same way. xCAT-test/unit/imgutils_host_resolver.t and imgutils_reused_root.t both die at load on the unfixed tree and pass with the fix, 34 tests. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-server/share/xcat/netboot/imgutils/imgutils.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm index d32a336767..048ec29115 100644 --- a/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm +++ b/xCAT-server/share/xcat/netboot/imgutils/imgutils.pm @@ -297,7 +297,7 @@ sub use_host_resolver { my ($rootimg_dir) = @_; foreach my $file ('hosts', 'resolv.conf') { my $image = "$rootimg_dir/etc/$file"; - move($image, "$image.bak") unless -e "$image.bak" || -l "$image.bak"; + File::Copy::move($image, "$image.bak") unless -e "$image.bak" || -l "$image.bak"; unlink($image); File::Copy::copy("/etc/$file", $image); } From 93f27a267475455082e916eca82d0f56f4a22be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 02:52:12 -0300 Subject: [PATCH 104/114] fix(netboot): hand the NetworkManager lease of the initrd to diskless roots xcatroot passes the DHCP lease of the initrd to the root image only from /tmp/dhclient.*.lease, which the old dracut network scripts write. An initrd that runs NetworkManager keeps its lease in /var/lib/NetworkManager. The NetworkManager of the root takes over the same connection, finds no lease and starts again with DHCPDISCOVER while the address stays on the interface. A DHCP server that does not answer in time makes NetworkManager-wait-online fail, and when the DHCP timeout expires NetworkManager removes the address from the boot interface. xcatroot now also copies the NetworkManager leases, so the root renews the lease of the initrd with a DHCPREQUEST. Only the stateless xcatroot of dracut_047 changes; statelite and the other dracut modules keep their handoff. --- xCAT-server/share/xcat/netboot/rh/dracut_047/xcatroot | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xCAT-server/share/xcat/netboot/rh/dracut_047/xcatroot b/xCAT-server/share/xcat/netboot/rh/dracut_047/xcatroot index e0edf3c349..c426ebcd9a 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut_047/xcatroot +++ b/xCAT-server/share/xcat/netboot/rh/dracut_047/xcatroot @@ -394,6 +394,12 @@ if [ -z $STATEMNT ]; then cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases" [ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases" done + # NetworkManager in the root reuses the connection of the initrd and reads its lease by the same name. + for lf in /var/lib/NetworkManager/*.lease; do + [ -f "$lf" ] || continue + mkdir -p "$NEWROOT/var/lib/NetworkManager" + cp "$lf" "$NEWROOT/var/lib/NetworkManager/" + done ifname="$(getarg ifname=)" netdev="$(getarg netdev=)" From 25793a41f044663bd94dbb07cbe638c42e2bc2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:08:26 -0300 Subject: [PATCH 105/114] test(netboot): hand the NetworkManager lease of the initrd to diskless roots The stateless xcatroot of dracut_047, run in a chroot with NetworkManager leases of the dhclient and internal clients in the initrd, must copy both into the root under their own names. CI now runs the xcatroot test as root. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/openeuler_xcatroot.t | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 6034769ca7..c0ede80ac8 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -50,7 +50,7 @@ jobs: status=0 sudo sh -c 'cd "$1" && bats xCAT-test/native/getinstdisk_selection.bats' sh "$workdir" || status=1 sudo sh -c 'cd "$1" && bats xCAT-test/native/syslog_log_directory.bats' sh "$workdir" || status=1 - sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/template_root_password.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1 + sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/template_root_password.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t xCAT-test/native/openeuler_xcatroot.t' sh "$workdir" || status=1 exit "$status" - name: Prepare xCAT syslog directory if: ${{ !cancelled() }} diff --git a/xCAT-test/native/openeuler_xcatroot.t b/xCAT-test/native/openeuler_xcatroot.t index e6480dda9a..478365134a 100644 --- a/xCAT-test/native/openeuler_xcatroot.t +++ b/xCAT-test/native/openeuler_xcatroot.t @@ -28,6 +28,9 @@ exec chroot "$root" /bin/bash -c ' printf "PAYLOAD="; cat /sysroot/native-marker if [ -f /sysroot/localdisk-ran ]; then echo LOCALDISK_RAN; fi if [ -f /hooks/initqueue/xcat.sh ]; then echo INITQUEUE_READY; fi + for lease in /sysroot/var/lib/NetworkManager/*.lease; do + [ -f "$lease" ] && printf "NMLEASE=%s:%s\n" "${lease##*/}" "$(cat "$lease")" + done exit "$rc" ' SH @@ -40,7 +43,7 @@ for my $variant (qw(dracut_047 dracut_105/stateless dracut_105/statelite)) { my $case = tempdir(DIR => $dir, CLEANUP => 1); my $root = "$case/root"; my $payload = "$case/payload"; - make_path(map { "$root/$_" } qw(usr lib etc tmp sysroot hooks/initqueue)); + make_path(map { "$root/$_" } qw(usr lib etc tmp sysroot hooks/initqueue var/lib/NetworkManager)); symlink('usr/bin', "$root/bin") or die $!; symlink('usr/sbin', "$root/sbin") or die $!; symlink('usr/lib64', "$root/lib64") or die $!; @@ -53,6 +56,7 @@ for my $variant (qw(dracut_047 dracut_105/stateless dracut_105/statelite)) { } write_file("$root/etc/resolv.conf", "nameserver 192.0.2.1\n"); write_file("$root/tmp/dhclient.eth0.lease", "fixture lease\n"); + write_file("$root/var/lib/NetworkManager/$_-0f3e5a12-eth0.lease", "$_ lease\n") for qw(dhclient internal); write_file("$root/lib/dracut-lib.sh", <<'SH'); hookdir=/hooks logger() { :; } @@ -93,6 +97,10 @@ SH like($output, qr/^PAYLOAD=native payload$/m, "$label extracts the actual image payload"); like($output, qr/^INITQUEUE_READY$/m, "$label reaches the initqueue handoff"); unlike($output, qr{localdisk: (?:No such file|Permission denied)}, "$label avoids an invalid optional script invocation"); + if ($variant eq 'dracut_047') { + like($output, qr/^NMLEASE=$_-0f3e5a12-eth0\.lease:$_ lease$/m, + "$label hands the $_ lease of NetworkManager to the root") for qw(dhclient internal); + } if ($localdisk eq 'executable') { like($output, qr/^LOCALDISK_RAN$/m, "$label retains the legacy executable hook"); } else { From d52b2d463bf774a353ed64a0727ff905c8ec4ed0 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, 2 Nov 2026 22:50:57 -0300 Subject: [PATCH 106/114] fix(install): run the SELinux relabel after the EL post scripts post.rhels8 and post.rhels10 end with exit 0. The kickstart templates include them inline in the %post script, so the exit ends that script before #SELINUXRELABEL#, and restorecon never runs on an enforcing or permissive node. Both scripts now end with their last command, so the templates reach the relabel after the xCAT post scripts wrote their files. --- xCAT-server/share/xcat/install/scripts/post.rhels10 | 2 -- xCAT-server/share/xcat/install/scripts/post.rhels8 | 2 -- 2 files changed, 4 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels10 b/xCAT-server/share/xcat/install/scripts/post.rhels10 index 75e8647476..42158dc8c7 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels10 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels10 @@ -16,5 +16,3 @@ do sed -i -e 's/^[[:space:]]*enabled[[:space:]]*=[[:space:]]*1/enabled=0/' /etc/yum.repos.d/$repo_file fi done - -exit 0 diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels8 b/xCAT-server/share/xcat/install/scripts/post.rhels8 index e396315c4b..11d185a198 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels8 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels8 @@ -41,5 +41,3 @@ do sed -i -e 's/^[[:space:]]*enabled[[:space:]]*=[[:space:]]*1/enabled=0/' /etc/yum.repos.d/$repo_file fi done - -exit 0 From d198efde019c8898c616b6a79b98d85f6465366d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:33:41 -0300 Subject: [PATCH 107/114] test(install): run riscv64 %post --nochroot blocks outside the chroot The riscv64 profile test runs every rendered %post block as if it ran in the installed system. Anaconda runs a --nochroot block in the installer, with the installed system at /mnt/sysimage, so give such a block that view. --- xCAT-test/native/install_profile_riscv64.t | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xCAT-test/native/install_profile_riscv64.t b/xCAT-test/native/install_profile_riscv64.t index 2fe46f52ca..3703c9c460 100644 --- a/xCAT-test/native/install_profile_riscv64.t +++ b/xCAT-test/native/install_profile_riscv64.t @@ -189,9 +189,13 @@ for my $rendered (@rendered_profiles) { my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/; $interpreter //= '/bin/sh'; write_text("$root/post.sh", $post->[1]); - my ($rc, $log) = sandbox_run($root, { - env => {XCAT_EFI_LOG => '/fixture/efi.log'}, - }, 'timeout', '30', $interpreter, '/fixture/post.sh'); + my %options = (env => {XCAT_EFI_LOG => '/fixture/efi.log'}); + # anaconda runs a --nochroot block in the installer, with the installed system at /mnt/sysimage + if ($post->[0] =~ /(?:^|\s)--nochroot(?:\s|$)/) { + $options{writable} = {map { ("$root/$_->[0]" => "/mnt/sysimage/$_->[1]") } + ['boot', 'boot'], ['etc', 'etc'], ['log', 'var/log']}; + } + my ($rc, $log) = sandbox_run($root, \%options, 'timeout', '30', $interpreter, '/fixture/post.sh'); is($rc, 0, 'post block ' . ++$index . ' completes') or diag($log, read_text("$root/log/xcat/xcat.log")); } From 2770ff0840decef2318e3e8957ef083669ddef27 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, 2 Nov 2026 22:51:02 -0300 Subject: [PATCH 108/114] test(install): run the SELinux relabel after the EL post scripts Each kickstart template with #SELINUXRELABEL#, rendered for an enforcing node and run in a sandbox through its downloaded postscript, must call restorecon once, after the postscript ran and post.rhels8 or post.rhels10 disabled the vendor repository. A disabled node must get no relabel. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/selinux_kickstart_relabel.t | 100 +++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/selinux_kickstart_relabel.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 6034769ca7..319399beeb 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -110,7 +110,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/selinux_kickstart_relabel.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/selinux_kickstart_relabel.t b/xCAT-test/native/selinux_kickstart_relabel.t new file mode 100644 index 0000000000..f7ed776282 --- /dev/null +++ b/xCAT-test/native/selinux_kickstart_relabel.t @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Copy qw(copy); +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; + +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database set_row render_template); + +plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux'; +my $database = template_database(); +set_row('passwd', {key => 'system', username => 'root'}, {password => '$6$fixture$encrypted'}); + +my $install = repo_path('xCAT-server/share/xcat/install'); +my @templates = ( + ['rh/compute.rhels8.tmpl', 'rocky8.10', 'x86_64', 'rh'], + ['rh/compute.rhels9.tmpl', 'alma9.6', 'x86_64', 'rh'], + ['rh/compute.rhels10.tmpl', 'rhels10.0', 'x86_64', 'rh'], + ['rh/compute.rhels10.riscv64.tmpl', 'rhels10.0', 'riscv64', 'rh'], + ['rocky/service.rocky10.riscv64.tmpl', 'rocky10.2', 'riscv64', 'rocky'], + ['openeuler/compute.openeuler.tmpl', 'openeuler24.03sp3', 'x86_64', 'openeuler'], +); + +# The stand-in records what the xCAT post scripts had done when the relabel ran. +my $restorecon = <<'SH'; +#!/bin/sh +{ + printf 'args=%s\n' "$*" + [ -e /fixture/postscript-ran ] && echo 'postscript=ran' + grep -q '^enabled=0$' /etc/yum.repos.d/rocky.repo && echo 'vendor-repository=disabled' +} >>/fixture/restorecon.calls +SH + +sub post_root { + my $root = sandbox_root(); + make_path("$root/sbin", "$root/etc/systemd/system", "$root/etc/yum.repos.d", "$root/boot/efi/EFI/BOOT"); + write_text("$root/sbin/restorecon", $restorecon); + chmod 0755, "$root/sbin/restorecon" or die $!; + write_text("$root/etc/yum.repos.d/rocky.repo", "[baseos]\nname=BaseOS\nenabled=1\n"); + write_text("$root/boot/efi/EFI/BOOT/BOOTRISCV64.EFI", "loader\n"); + write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n"); + copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!; + write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n"); + for my $name (qw(curl logger sleep updateflag.awk nmcli openssl)) { + copy(repo_path('xCAT-test/fixtures/install-profile/command'), "$root/bin/$name") or die $!; + chmod 0755, "$root/bin/$name" or die $!; + } + return $root; +} + +for my $case (@templates) { + my ($template, $os, $arch, $platform) = @$case; + for my $mode (qw(enforcing disabled)) { + subtest "$template $mode" => sub { + set_row('nodetype', {node => 'node'}, {os => $os, arch => $arch, provmethod => 'install'}); + set_row('noderes', {node => 'node'}, {selinux => $mode}); + (my $pkglist = "$install/$template") =~ s/\.tmpl$/.pkglist/; + my $output = "$database/ks"; + render_template($database, "$install/$template", $output, 'node', (-r $pkglist ? $pkglist : ''), + '/install/media', $platform, undef, {xcatmaster => '192.0.2.1'}); + my $rendered = read_text($output); + my @posts; + while ($rendered =~ /^%post([^\n]*)\n(.*?)^%end/msg) { + push @posts, [$1, $2]; + } + ok(@posts, 'renders a %post section'); + + my $root = post_root(); + my $index = 0; + for my $post (@posts) { + my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/; + write_text("$root/post.sh", $post->[1]); + my ($rc, $log) = sandbox_run($root, {read_only => {"$root/sbin" => '/usr/sbin'}}, + 'timeout', '30', $interpreter // '/bin/sh', '/fixture/post.sh'); + is($rc, 0, '%post section ' . ++$index . ' completes') + or diag($log, read_text("$root/log/xcat/xcat.log")); + } + ok(-e "$root/postscript-ran", 'runs the rendered sequence through the downloaded postscript'); + ok(!-e "$root/unexpected-command", 'external fixtures accept the requested operations'); + is(read_text("$root/etc/yum.repos.d/rocky.repo"), "[baseos]\nname=BaseOS\nenabled=0\n", + 'disables the installed vendor repository'); + my $calls = -e "$root/restorecon.calls" ? read_text("$root/restorecon.calls") : undef; + if ($mode eq 'disabled') { + is($calls, undef, 'does not relabel a disabled node'); + } else { + is($calls, "args=-RF /xcatpost /opt/xcat /etc /root /var/log\npostscript=ran\nvendor-repository=disabled\n", + 'relabels once, after the xCAT post scripts wrote their files'); + } + }; + } +} + +done_testing(); From 944ac3f6e994e3446c51db92f084747a25b91b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:10:50 -0300 Subject: [PATCH 109/114] fix(install): keep custom partition files out of the install log pre.rhels8 and pre.rhels10 print /tmp/partitionfile into the pre-install log, so that the partition scheme can be inspected after the installation. A custom partitionfile can hold credentials, such as the --passphrase of an encrypted partition or a boot loader --password, and the log then holds them in clear text. With site.xcatdebugmode 1 or 2, %pre also traces the decoding of a custom partitionfile or partition script, and the trace spells out every decoded byte. The pre-install log now shows the partition scheme only when xCAT generated it, and says that a custom partition file is not logged. The decoding of a custom partitionfile or partition script runs untraced. /tmp/partitionfile, which anaconda reads, is unchanged. --- xCAT-server/lib/perl/xCAT/Template.pm | 6 ++++-- xCAT-server/share/xcat/install/scripts/pre.rhels10 | 7 ++++++- xCAT-server/share/xcat/install/scripts/pre.rhels8 | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index e681dee5ae..9fce2796ba 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -456,7 +456,8 @@ sub subvars { $partcontent .= "rm -rf /tmp/partitionfile\n"; # Put the code to decode the partitionfile - $partcontent .= "base64decode/tmp/partscript\n"; + # A traced decode prints the partition data, which can hold a passphrase. + $partcontent .= "(set +x; base64decode/tmp/partscript)\n"; $partcontent .= "chmod 755 /tmp/partscript\n"; $partcontent .= "/tmp/partscript\n"; @@ -517,7 +518,8 @@ sub subvars { $partcontent .= "rm -rf /tmp/partitionfile\n"; # Put the code to decode the partitionfile - $partcontent .= "base64decode/tmp/partitionfile\n"; + # A traced decode prints the partition data, which can hold a passphrase. + $partcontent .= "(set +x; base64decode/tmp/partitionfile)\n"; #replace the #XCA_PARTITION_SCRIPT# $inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/; diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels10 b/xCAT-server/share/xcat/install/scripts/pre.rhels10 index 80d6d40741..affecf081f 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.rhels10 +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels10 @@ -309,7 +309,12 @@ fi # save the content of /tmp/partitionfile in /var/log/xcat/xcat.log # so that we can inspect the partition scheme after installation echo "================ The Partition Scheme ===============" -cat /tmp/partitionfile +# A custom partition file can hold credentials, and this log reaches the node. +if [ -e /tmp/partitionfile.enc ] || [ -e /tmp/partscript.enc ]; then + echo "The custom partition file is not logged." +else + cat /tmp/partitionfile +fi echo "=====================================================" msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label" # The following code is to generate the repository for the installation diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels8 b/xCAT-server/share/xcat/install/scripts/pre.rhels8 index b9900825b7..978fd1e7fe 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.rhels8 +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels8 @@ -310,7 +310,12 @@ fi # save the content of /tmp/partitionfile in /var/log/xcat/xcat.log # so that we can inspect the partition scheme after installation echo "================ The Partition Scheme ===============" -cat /tmp/partitionfile +# A custom partition file can hold credentials, and this log reaches the node. +if [ -e /tmp/partitionfile.enc ] || [ -e /tmp/partscript.enc ]; then + echo "The custom partition file is not logged." +else + cat /tmp/partitionfile +fi echo "=====================================================" msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label" # The following code is to generate the repository for the installation From e1d9900b3eca278471a3c87365fe7c0e479434a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:10:51 -0300 Subject: [PATCH 110/114] test(install): keep custom partition files out of the install log Render the rhels9 and rhels10 kickstarts with no partitionfile, a custom partitionfile and a custom partition script, each with xcatdebugmode 0, 1 and 2, and run %pre in a sandbox. The custom input holds credentials in the =, separated, quoted, escaped and split option forms, a boot loader password and a root password. The pre-install log must show the generated partition scheme, or a notice for custom input, with neither a credential nor a traced decoded byte of the custom input, and anaconda must still get the custom partition definitions. Run the new test in the profile artifact job. --- .github/workflows/xcat_test.yml | 2 +- .../native/kickstart_partition_scheme_log.t | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/kickstart_partition_scheme_log.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 6034769ca7..4b7a611cb1 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -110,7 +110,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/kickstart_partition_scheme_log.t b/xCAT-test/native/kickstart_partition_scheme_log.t new file mode 100644 index 0000000000..e04af4b6f6 --- /dev/null +++ b/xCAT-test/native/kickstart_partition_scheme_log.t @@ -0,0 +1,101 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use File::Path qw(make_path); +use File::Slurper qw(read_binary write_binary); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database set_row render_template); + +plan skip_all => 'installer execution requires Linux namespaces' unless $^O eq 'linux'; +my $database = template_database(); +set_row('site', {key => 'nodestatus'}, {value => 0}); +write_binary("$database/image.pkglist", ''); + +# Credentials in the forms that kickstart's shell-style parser accepts. +my $custom = join("\n", + 'part /data --fstype=xfs --size=1024 --encrypted --passphrase=s3cret-one --ondisk=sdb', + 'logvol /home --vgname=vg --name=home --size=1 --encrypted --passphrase "s3cret two"', + "raid /srv --level=1 --device=md0 --encrypted --passphrase='s3cret three' raid.01 raid.02", + 'part /esc --size=1 --encrypted --passphrase=prefix\\ s3cret\\ four --ondisk=sdb', + 'part /quote --size=1 --encrypted --pass"phrase"="s3cret \\"five\\"" --ondisk=sdb', + 'bootloader --iscrypted --password=s3cret-six', + 'rootpw --plaintext s3cret-seven'); +write_binary("$database/partitionfile", "$custom\n"); +write_binary("$database/partscript", "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n$custom\nEOF\n"); + +# Commands that the pre-installation scripts call in the installer. +sub installer_root { + my $root = sandbox_root(); + make_path("$root/libexec"); + write_binary("$root/partitions", "major minor #blocks name\n\n 8 16 524288000 sdb\n"); + write_binary("$root/bin/udevadm", <<'SH'); +#!/bin/sh +case "$*" in + 'info --attribute-walk --name=sdb') printf ' ATTRS{size}=="1024000000"\n DRIVERS=="ahci"\n' ;; + 'info --query=property --name='*) printf 'DEVTYPE=disk\n' ;; + *) exit 97 ;; +esac +SH + write_binary("$root/bin/find", "#!/bin/sh\nprintf '/usr/bin/awk\\n'\n"); + write_binary("$root/libexec/platform-python", "#!/bin/sh\nexit 0\n"); + write_binary("$root/bin/mknod", "#!/bin/sh\n: >\"\$1\"\n"); + for my $name (qw(logger vgs vgchange vgremove chown)) { + write_binary("$root/bin/$name", "#!/bin/sh\nexit 0\n"); + } + chmod oct('755'), glob("$root/bin/*"), "$root/libexec/platform-python" or die $!; + return $root; +} + +for my $case (['rh/compute.rhels9.tmpl', 'alma9.6'], ['rh/compute.rhels10.tmpl', 'rhels10']) { + my ($template, $os) = @$case; + for my $input (['generated', undef], ['custom file', "$database/partitionfile"], + ['custom script', "s:$database/partscript"]) { + my ($kind, $partitionfile) = @$input; + for my $mode (0, 1, 2) { + subtest "$template, $kind, xcatdebugmode $mode" => sub { + set_row('site', {key => 'xcatdebugmode'}, {value => $mode}); + set_row('nodetype', {node => 'node'}, {os => $os, arch => 'x86_64', provmethod => 'install'}); + render_template($database, repo_path("xCAT-server/share/xcat/install/$template"), "$database/ks", + 'node', "$database/image.pkglist", "/install/$os/x86_64", 'rh', $partitionfile, + {xcatmaster => '192.0.2.1'}, osarch => 'x86_64'); + my ($pre) = read_binary("$database/ks") =~ /^%pre\b[^\n]*\n(.*?)^%end$/ms; + write_binary("$database/pre.sh", $pre // ''); + my $root = installer_root(); + my ($rc, $output) = sandbox_run($root, { + read_only => {"$root/partitions" => '/proc/partitions', "$root/libexec" => '/usr/libexec', + "$database/pre.sh" => '/pre.sh'}, + env => {MASTER_IP => '192.0.2.1', log_label => 'install'}, + }, '/bin/bash', '-c', '. /pre.sh'); + is($rc, 0, 'the %pre block completes') or diag($output); + my $log = -f "$root/tmp/pre-install.log" ? read_binary("$root/tmp/pre-install.log") : ''; + my ($scheme) = $log =~ /^=+ The Partition Scheme =+\n(.*?)^=+$/ms; + if ($mode) { + like($log, qr/^\++ /m, 'traces the %pre block into the pre-install log'); + } + if (!defined $partitionfile) { + like($scheme // '', qr/^volgroup xcatvg /m, 'logs the partition scheme that xCAT generated'); + return; + } + like($scheme // '', qr/^The custom partition file is not logged\.$/m, + 'logs a notice in place of the custom partition file'); + unlike($scheme // '', qr/^(?:part|logvol|raid|bootloader|rootpw) /m, + 'logs no line of the custom partition file'); + unlike($log . $output, qr/s3cret/, 'leaves no credential in the log or the trace'); + # The decoder prints three bytes at a time, so a traced decode spells them out in hex. + my $traced = join('', map { pack('H*', join('', /\\x([0-9A-Fa-f]{2})/g)) } + $log =~ /^\++ printf '([^']*)'$/mg); + unlike($traced, qr/s3cret/, 'traces no decoded byte of the custom input'); + like(read_binary("$root/tmp/partitionfile"), qr/\A\Q$custom\E\n?\z/, + 'hands anaconda the custom partition definitions'); + }; + } + } +} +set_row('site', {key => 'xcatdebugmode'}, {value => 0}); + +done_testing(); From b45dc1e85fe633bb462078ea5ab0b5179ff564dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:33:48 -0300 Subject: [PATCH 111/114] fix(install): copy the kickstart pre-install log from the installer The EL8 and later kickstart templates append /tmp/pre-install.log to /var/log/xcat/xcat.log in the chroot %post. Anaconda runs that block in the installed system, whose /tmp does not hold the installer's log, so the %pre output, such as the install disk and the partition layout, never reaches the node's xcat.log. Copy the log in a %post --nochroot block before the main %post, from the installer's /tmp to the installed system at /mnt/sysimage. The EL6 and EL7 templates use %include for this and are unchanged. --- xCAT-server/share/xcat/install/centos/compute.centos8.tmpl | 6 +++++- .../share/xcat/install/openeuler/compute.openeuler.tmpl | 6 +++++- .../share/xcat/install/rh/compute.rhels10.riscv64.tmpl | 6 +++++- xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl | 6 +++++- xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl | 6 +++++- xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl | 6 +++++- .../share/xcat/install/rocky/service.rocky10.riscv64.tmpl | 6 +++++- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl b/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl index 3719fd0c6f..47883b685c 100644 --- a/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl +++ b/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl @@ -48,9 +48,13 @@ echo "Running Kickstart Pre-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8# } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng# diff --git a/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl b/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl index a022871a5f..81693da645 100644 --- a/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl +++ b/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl @@ -27,9 +27,13 @@ echo "Running Kickstart Pre-installation script..." } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash --erroronfail mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.openeuler# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl index 63e697b6bb..6ad5f24316 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl @@ -55,9 +55,13 @@ echo "Running Kickstart Pre-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10# } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl index 3c90ba493d..8e5596971b 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl @@ -42,9 +42,13 @@ echo "Running Kickstart Pre-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10# } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl index 64daf4a34f..e758bc7489 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl @@ -47,9 +47,13 @@ echo "Running Kickstart Pre-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8# } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl index 6cb3a98883..bffe965899 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl @@ -42,9 +42,13 @@ echo "Running Kickstart Pre-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8# } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng# diff --git a/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl b/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl index bc1cc270bd..2866a3b1d3 100644 --- a/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl +++ b/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl @@ -55,9 +55,13 @@ echo "Running Kickstart Pre-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8# } &>>/tmp/pre-install.log %end +# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read. +%post --nochroot --interpreter=/bin/bash +mkdir -p /mnt/sysimage/var/log/xcat/ +cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log +%end %post --interpreter=/bin/bash mkdir -p /var/log/xcat/ -cat /tmp/pre-install.log >>/var/log/xcat/xcat.log { echo "Running Kickstart Post-installation script..." #INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng# From 568db909722f264950217e5cba22b0ce5719cb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:02:07 -0300 Subject: [PATCH 112/114] test(install): cover the kickstart pre-install log handoff Run the rendered %post --nochroot blocks of each kickstart template whose %pre writes /tmp/pre-install.log the way anaconda runs them: in the installer, with its own /tmp and the installed system at /mnt/sysimage. Each run must append the log to a new or an existing xcat.log. The riscv64 profile test now keeps the installer's /tmp out of the installed root too. Both fail on the old templates, whose chroot %post reads a /tmp that does not hold the log. Run the new test in the profile artifact job. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/install_profile_riscv64.t | 10 ++- xCAT-test/native/kickstart_pre_install_log.t | 80 ++++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 xCAT-test/native/kickstart_pre_install_log.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 4b7a611cb1..11b71e4635 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -110,7 +110,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t xCAT-test/native/kickstart_pre_install_log.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/install_profile_riscv64.t b/xCAT-test/native/install_profile_riscv64.t index 3703c9c460..4eb540dc79 100644 --- a/xCAT-test/native/install_profile_riscv64.t +++ b/xCAT-test/native/install_profile_riscv64.t @@ -173,7 +173,8 @@ for my $rendered (@rendered_profiles) { my $root = installed_root(1, sandbox_root()); make_path("$root/etc/systemd/system/multi-user.target.wants", "$root/etc/yum.repos.d"); write_text("$root/etc/yum.repos.d/rocky.repo", "[baseos]\nname=BaseOS\nenabled=1\n"); - write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n"); + make_path("$root/installer-tmp"); + write_text("$root/installer-tmp/pre-install.log", "pre-install fixture diagnostic\n"); copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!; write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n"); for my $name (qw(uname findmnt lsblk efibootmgr)) { @@ -190,10 +191,11 @@ for my $rendered (@rendered_profiles) { $interpreter //= '/bin/sh'; write_text("$root/post.sh", $post->[1]); my %options = (env => {XCAT_EFI_LOG => '/fixture/efi.log'}); - # anaconda runs a --nochroot block in the installer, with the installed system at /mnt/sysimage + # anaconda runs a --nochroot block in the installer, which has its own /tmp and the installed system at /mnt/sysimage if ($post->[0] =~ /(?:^|\s)--nochroot(?:\s|$)/) { - $options{writable} = {map { ("$root/$_->[0]" => "/mnt/sysimage/$_->[1]") } - ['boot', 'boot'], ['etc', 'etc'], ['log', 'var/log']}; + $options{writable} = {map { ("$root/$_->[0]" => $_->[1]) } + ['installer-tmp', '/tmp'], ['boot', '/mnt/sysimage/boot'], + ['etc', '/mnt/sysimage/etc'], ['log', '/mnt/sysimage/var/log']}; } my ($rc, $log) = sandbox_run($root, \%options, 'timeout', '30', $interpreter, '/fixture/post.sh'); is($rc, 0, 'post block ' . ++$index . ' completes') diff --git a/xCAT-test/native/kickstart_pre_install_log.t b/xCAT-test/native/kickstart_pre_install_log.t new file mode 100644 index 0000000000..a1440aac80 --- /dev/null +++ b/xCAT-test/native/kickstart_pre_install_log.t @@ -0,0 +1,80 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; + +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database set_row render_template); + +plan skip_all => 'kickstart execution requires Linux' unless $^O eq 'linux'; +my $database = template_database(); + +# The kickstart templates whose %pre writes /tmp/pre-install.log, each with an OS that uses it. +my @templates = ( + [ 'rh/compute.rhels10.tmpl', 'rhels10.0', 'x86_64', 'rh' ], + [ 'rh/compute.rhels9.tmpl', 'alma9.6', 'x86_64', 'rh' ], + [ 'rh/compute.rhels8.tmpl', 'rocky8.10', 'x86_64', 'rh' ], + [ 'centos/compute.centos8.tmpl', 'centos8', 'x86_64', 'centos' ], + [ 'openeuler/compute.openeuler.tmpl', 'openeuler24.03sp3', 'x86_64', 'openeuler' ], + [ 'rh/compute.rhels10.riscv64.tmpl', 'rhels10.0', 'riscv64', 'rh' ], + [ 'rocky/service.rocky10.riscv64.tmpl', 'rocky10.2', 'riscv64', 'rocky' ], +); +my $diagnostic = "pre-install fixture diagnostic\n"; + +for my $case (@templates) { + my ($template, $os, $arch, $platform) = @$case; + subtest $template => sub { + set_row('nodetype', {node => 'node'}, {os => $os, arch => $arch, provmethod => 'install'}); + my $path = repo_path("xCAT-server/share/xcat/install/$template"); + (my $pkglist = $path) =~ s/\.tmpl$/.pkglist/; + $pkglist = '' unless -r $pkglist; + my $output = "$database/ks"; + render_template($database, $path, $output, 'node', $pkglist, '/install/media', $platform, undef, + {xcatmaster => '192.0.2.1'}); + my $ks = read_text($output); + like($ks, qr/^%pre\b.*?pre-install\.log.*?^%end/ms, 'the %pre block writes the pre-install log'); + + my @posts; + while ($ks =~ /^%post([^\n]*)\n(.*?)^%end/msg) { + push @posts, [$1, $2]; + } + my @installer = grep { $posts[$_][0] =~ /(?:^|\s)--nochroot(?:\s|$)/ } 0 .. $#posts; + my ($chroot) = grep { $posts[$_][0] !~ /(?:^|\s)--nochroot(?:\s|$)/ } 0 .. $#posts; + ok(defined $chroot, 'has a %post block that runs in the installed system'); + + # anaconda keeps the installer's /tmp out of the chroot, so only a --nochroot block can read the log + for my $earlier ('', "earlier entry\n") { + my $label = length($earlier) ? 'an existing log' : 'a new log'; + my $root = sandbox_root(); + my $xcatlog = "$root/log/xcat/xcat.log"; + make_path("$root/installer-tmp"); + write_text("$root/installer-tmp/pre-install.log", $diagnostic); + if (length($earlier)) { + make_path("$root/log/xcat"); + write_text($xcatlog, $earlier); + chmod(oct('644'), $xcatlog) or die $!; + } + for my $index (@installer) { + my ($interpreter) = $posts[$index][0] =~ /--interpreter=(\S+)/; + write_text("$root/post.sh", $posts[$index][1]); + my ($rc, $log) = sandbox_run($root, { + writable => {"$root/installer-tmp" => '/tmp', "$root/log" => '/mnt/sysimage/var/log'}, + }, $interpreter // '/bin/sh', '/fixture/post.sh'); + is($rc, 0, "%post --nochroot block $index completes for $label") or diag($log); + } + is(-f $xcatlog ? read_text($xcatlog) : '', $earlier . $diagnostic, + "appends the pre-install log to $label of the installed system"); + } + ok(@installer && defined $chroot && $installer[0] < $chroot, + 'copies it before the first %post block in the installed system writes that log'); + }; +} + +done_testing(); From 63bd36cfd46f59cd982ab22cde04dc72ff94caae 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, 2 Nov 2026 23:00:17 -0300 Subject: [PATCH 113/114] fix(install): leave the USB NIC of the BMC down on installed EL nodes post.rhels8 turns on every NIC that has link during the installation. The USB NIC of a BMC host interface always has link, so the installed node starts DHCP on it at boot, gets no lease, and NetworkManager-wait-online fails. post.rhels8 now skips NICs bound to a USB class driver: cdc_ether, cdc_ncm, cdc_eem or rndis_host, which Linux binds to the USB gadget of a BMC. USB Ethernet adapters with their own driver, the other NICs with link, and NICs without a sysfs entry come up as before. --- xCAT-server/share/xcat/install/scripts/post.rhels8 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels8 b/xCAT-server/share/xcat/install/scripts/post.rhels8 index e396315c4b..953d14ec60 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels8 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels8 @@ -12,6 +12,10 @@ if compgen -G "/etc/sysconfig/network-scripts/ifcfg-*" >/dev/null 2>&1; then do [ "${i##*/}" = "ifcfg-lo" ] && continue nicname="${i##*-}" + # A BMC host interface uses a USB class driver and has link but usually no DHCP server. + case "$(readlink -f "/sys/class/net/$nicname/device/driver" 2>/dev/null)" in + */cdc_ether|*/cdc_ncm|*/cdc_eem|*/rndis_host) continue ;; + esac if ethtool "$nicname" 2>/dev/null | grep -E -i -q "Link detected.*yes" >/dev/null 2>&1 then case "$XCATDEBUGMODE" in From c3c466c9a09ca8f6de7fec7f545dfcd21fb6ae9b 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, 2 Nov 2026 23:00:17 -0300 Subject: [PATCH 114/114] test(install): leave the USB NIC of the BMC down on installed EL nodes The rendered post.rhels8, run in a sandbox with a fixture sysfs, must turn on the PCI NICs with link, a USB Ethernet adapter with its own driver, and a NIC with no sysfs entry, and leave a cdc_ether NIC with link down. When only the cdc_ether NIC has link, it must fall back to the connections active in the installer. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/post_rhels8_link_nics.t | 74 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/post_rhels8_link_nics.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index fff449a798..f570188c70 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -110,7 +110,7 @@ jobs: run: | log=$(mktemp) trap 'rm -f -- "$log"' EXIT - prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t xCAT-test/native/kickstart_pre_install_log.t | tee "$log" + prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/post_rhels8_link_nics.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t xCAT-test/native/kickstart_pre_install_log.t | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/post_rhels8_link_nics.t b/xCAT-test/native/post_rhels8_link_nics.t new file mode 100644 index 0000000000..ed1895b621 --- /dev/null +++ b/xCAT-test/native/post_rhels8_link_nics.t @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; + +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); +use XCAT::Test::Template qw(template_database render_template); + +plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux'; +my $database = template_database(); +my $script = "$database/post.rhels8"; +render_template($database, repo_path('xCAT-server/share/xcat/install/scripts/post.rhels8'), $script, + 'node', '', '/install/media', 'rh', undef, {xcatmaster => '192.0.2.1'}); + +my %device = ( + e1000e => ['/sys/devices/pci0000:00/0000:00:03.0', '/sys/bus/pci/drivers/e1000e'], + cdc_ether => ['/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0', '/sys/bus/usb/drivers/cdc_ether'], + r8152 => ['/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0', '/sys/bus/usb/drivers/r8152'], +); + +# Each NIC has an ifcfg file with ONBOOT=no, a driver (or no sysfs entry) and a link state. +sub run_post { + my (%nics) = @_; + my $root = sandbox_root(); + make_path("$root/etc/sysconfig/network-scripts", "$root/link"); + for my $nic (keys %nics) { + my ($driver, $link) = @{$nics{$nic}}; + write_text("$root/etc/sysconfig/network-scripts/ifcfg-$nic", "DEVICE=$nic\nBOOTPROTO=dhcp\nONBOOT=no\n"); + write_text("$root/link/$nic", '') if $link; + next unless $driver; + my ($bus, $module) = @{$device{$driver}}; + my $device = "$bus/$nic"; + make_path("$root$device", "$root$module", "$root/sys/class/net/$nic"); + symlink($device, "$root/sys/class/net/$nic/device") or die $!; + symlink($module, "$root$device/driver") or die $!; + } + write_text("$root/bin/ethtool", + "#!/bin/sh\n[ -e \"/fixture/link/\$1\" ] && state=yes || state=no\nprintf '\\tLink detected: %s\\n' \"\$state\"\n"); + write_text("$root/bin/nmcli", "#!/bin/sh\nprintf '%s\\n' \"\$*\" >>/fixture/nmcli.calls\n"); + chmod 0755, "$root/bin/ethtool", "$root/bin/nmcli" or die $!; + write_text("$root/post.sh", read_text($script)); + my ($rc, $log) = sandbox_run($root, {read_only => {"$root/sys" => '/sys'}}, '/bin/bash', '/fixture/post.sh'); + is($rc, 0, 'post.rhels8 completes') or diag($log); + my %onboot = map { + my ($value) = read_text("$root/etc/sysconfig/network-scripts/ifcfg-$_") =~ /^ONBOOT=(\w+)$/m; + ($_ => $value) + } keys %nics; + return (\%onboot, -e "$root/nmcli.calls" ? read_text("$root/nmcli.calls") : ''); +} + +{ + my ($onboot, $nmcli) = run_post( + eno1 => ['e1000e', 1], usb0 => ['cdc_ether', 1], enx1 => ['r8152', 1], eno2 => ['e1000e', 0], + renamed0 => [undef, 1], + ); + is_deeply($onboot, {eno1 => 'yes', usb0 => 'no', enx1 => 'yes', eno2 => 'no', renamed0 => 'yes'}, + 'activates the NICs with link, a USB Ethernet adapter included, except the USB NIC of the BMC'); + is($nmcli, '', 'leaves the NetworkManager profiles to the ifcfg files'); +} + +{ + my ($onboot, $nmcli) = run_post(eno1 => ['e1000e', 0], usb0 => ['cdc_ether', 1]); + is_deeply($onboot, {eno1 => 'no', usb0 => 'no'}, 'does not activate a USB NIC that is the only one with link'); + like($nmcli, qr/^-g NAME,STATE con show$/m, 'falls back to the connections active in the installer'); +} + +done_testing();