2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-21 09:52:17 +00:00

Merge pull request #7984 from VersatusHPC/fix/genesis-ubuntu-mawk-rebased

fix(xcat-core): the Ubuntu Genesis image runs its awk programs under mawk
This commit is contained in:
Daniel Hilst
2026-10-29 15:24:52 -03:00
committed by GitHub
6 changed files with 149 additions and 9 deletions
@@ -64,7 +64,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
@@ -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
+36 -7
View File
@@ -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 "<path> (<reason>)" 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
+69
View File
@@ -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' ]
}
@@ -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');
@@ -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.