2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00
Files
xcat-core/xCAT-test/bats/ubuntu_netboot_initqueue.bats
T
Daniel Hilst 9273a68368 test(xcat-core): the Ubuntu 26.04 netboot initramfs never gets a lease
ubuntu_netboot_initqueue.bats captures two defects in the Ubuntu dracut
module. The boot NIC gets no DHCPv4 lease, because nothing turns on
DHCP for the 70-BOOTIF.network file that systemd-network-generator
writes from BOOTIF=. And xcat-cmdline.sh writes its finished condition
outside $hookdir, so dracut-initqueue ends before the settled hook
that fetches the root runs. Both new cases fail on this tree.

imgutils_ubuntu_dracut_module.t now also checks the inst_simple
sources of the install script.

ubuntu_netboot_root_handler.bats sourced the online hook from sh. On
an Ubuntu host sh is dash, whose "." passes no arguments, so two cases
failed there. The initramfs sh is bash, so the cases now use bash.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
(cherry picked from commit 22cf6d78573f3df38c5d395dde4f50fc5c7a3640)
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-11-12 23:42:48 -03:00

73 lines
2.3 KiB
Bash

#!/usr/bin/env bats
#
# The Ubuntu 26.04 initramfs runs dracut 110 with systemd-networkd. Two conditions must hold
# before its initqueue fetches the root image:
# - the boot NIC gets a DHCPv4 lease, and
# - the initqueue has a finished condition, or it ends before it runs the settled hooks.
load 'helpers/shell_source'
setup()
{
INSTALL="$(require_repo_file 'xCAT-server/share/xcat/netboot/ubuntu/dracut/install.netboot')"
MOD="$(dirname "$INSTALL")"
LOG="${BATS_TEST_TMPDIR}/installed"
: >"$LOG"
HOOKS="${BATS_TEST_TMPDIR}/hooks"
mkdir -p "$HOOKS/initqueue/finished"
}
# Run install.netboot as dracut does, with its helpers stubbed to record what it asks for.
run_install()
{
run env MODDIR="$MOD" LOG="$LOG" bash -c '
moddir=$MODDIR
dracut_install() { :; }
inst() { :; }
inst_hook() { :; }
inst_simple() { printf "inst_simple %s %s\n" "$1" "$2" >>"$LOG"; }
. "$MODDIR/install.netboot"
'
}
# Source xcat-cmdline.sh as dracut-cmdline does, with hookdir set.
run_cmdline()
{
run env MODDIR="$MOD" HOOKS="$HOOKS" bash -c '
hookdir=$HOOKS
. "$MODDIR/xcat-cmdline.sh"
printf "root=%s rootok=%s netroot=%s\n" "$root" "$rootok" "$netroot"
'
}
@test "the cmdline hook gives the initqueue a finished condition in dracut's hook directory" {
run_cmdline
[ "$status" -eq 0 ]
[ "$output" = "root=1 rootok=1 netroot=xcat" ]
[ -f "$HOOKS/initqueue/finished/xcatroot.sh" ]
}
@test "the finished condition holds only after the root image is unpacked" {
run_cmdline
[ "$status" -eq 0 ]
newroot="${BATS_TEST_TMPDIR}/sysroot"
mkdir -p "$newroot"
run env NEWROOT="$newroot" sh "$HOOKS/initqueue/finished/xcatroot.sh"
[ "$status" -ne 0 ]
mkdir "$newroot/proc"
run env NEWROOT="$newroot" sh "$HOOKS/initqueue/finished/xcatroot.sh"
[ "$status" -eq 0 ]
}
@test "the module turns on DHCPv4 for the network that systemd makes from BOOTIF=" {
run_install
[ "$status" -eq 0 ]
line="$(grep -E '^inst_simple .* /etc/systemd/network/70-BOOTIF\.network\.d/[^/]+\.conf$' "$LOG")"
[ -n "$line" ]
src="$(printf '%s\n' "$line" | awk '{print $2}')"
[ "$(dirname "$src")" = "$MOD" ]
[ -f "$src" ]
run awk '/^\[/{s=$0} s=="[Network]" && /^DHCP=/{print}' "$src"
[ "$output" = "DHCP=ipv4" ]
}