2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-22 02:12:16 +00:00
Files
xcat-core/xCAT-test/bats/genesis_ubuntu_awk.bats
T
Daniel Hilst 1d52b46e29 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>
2026-10-24 10:01:16 -03:00

70 lines
2.0 KiB
Bash

#!/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' ]
}