mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-23 10:52:29 +00:00
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>
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user