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 1/2] 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 2/2] 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