From 214744f8ff66f27b450458133fa227ebe2a7914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:37:52 -0300 Subject: [PATCH] test(netboot): cover optional UFTP receiver installation --- xCAT-test/bats/dracut_rootimg_helpers.bats | 69 +++++++++++++++++++++ xCAT-test/native/genimage_rootimg_helpers.t | 2 +- xCAT-test/unit/imgutils_rootimg_helpers.t | 6 ++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/xCAT-test/bats/dracut_rootimg_helpers.bats b/xCAT-test/bats/dracut_rootimg_helpers.bats index 3b96cfe611..ffe2c8985c 100644 --- a/xCAT-test/bats/dracut_rootimg_helpers.bats +++ b/xCAT-test/bats/dracut_rootimg_helpers.bats @@ -58,18 +58,87 @@ install_module() ' install "$hook" } +receiver() +{ + printf '#!/bin/sh\n# %s receiver\nexit 0\n' "$1" >"$fixture/$1/uftpd" + chmod 755 "$fixture/$1/uftpd" +} + +add_fetch_helper() +{ + cp "$(repo_path xCAT-server/share/xcat/netboot/imgutils/xcat-rootimg-fetch.sh)" "$fixture/module/" +} + @test 'all stateless hooks deliver the checksum helper without UFTP' { + receiver bin + receiver sbin for variant in $VARIANTS; do stage_module "$variant" install_module [ "$status" -eq 0 ] || { echo "$variant: $output"; return 1; } cmp "$fixture/module/xcat-rootimg-checksum.sh" "$fixture/out/lib/xcat-rootimg-checksum.sh" [ ! -e "$fixture/out/lib/xcat-rootimg-fetch.sh" ] + [ ! -e "$fixture/out/lib/xcat-rootimg-install.sh" ] [ ! -e "$fixture/out/usr/sbin/uftpd" ] [ ! -e "$fixture/out/usr/bin/uftpd" ] done } +@test 'all stateless hooks prefer the sbin receiver when both locations are executable' { + receiver bin + receiver sbin + for variant in $VARIANTS; do + stage_module "$variant" + add_fetch_helper + install_module + [ "$status" -eq 0 ] || { echo "$variant: $output"; return 1; } + cmp "$fixture/module/xcat-rootimg-fetch.sh" "$fixture/out/lib/xcat-rootimg-fetch.sh" + cmp "$fixture/sbin/uftpd" "$fixture/out/usr/sbin/uftpd" + [ ! -e "$fixture/out/usr/bin/uftpd" ] + done +} + +@test 'all stateless hooks install the bin receiver when the sbin receiver is absent or not executable' { + receiver bin + for variant in $VARIANTS; do + for sbin in absent nonexecutable; do + rm -f "$fixture/sbin/uftpd" + if [ "$sbin" = nonexecutable ]; then + receiver sbin + chmod 644 "$fixture/sbin/uftpd" + fi + stage_module "$variant" + add_fetch_helper + install_module + [ "$status" -eq 0 ] || { echo "$variant: $output"; return 1; } + cmp "$fixture/bin/uftpd" "$fixture/out/usr/bin/uftpd" + [ ! -e "$fixture/out/usr/sbin/uftpd" ] + done + done +} + +@test 'all stateless hooks retain the fetch helper when neither receiver location is executable' { + for variant in $VARIANTS; do + stage_module "$variant" + add_fetch_helper + install_module + [ "$status" -eq 0 ] || { echo "$variant: $output"; return 1; } + cmp "$fixture/module/xcat-rootimg-fetch.sh" "$fixture/out/lib/xcat-rootimg-fetch.sh" + [ ! -e "$fixture/out/usr/sbin/uftpd" ] + [ ! -e "$fixture/out/usr/bin/uftpd" ] + done +} + +@test 'all stateless hooks stop when the installation policy helper is missing' { + for variant in $VARIANTS; do + stage_module "$variant" + rm "$fixture/module/xcat-rootimg-install.sh" + install_module + [ "$status" -ne 0 ] || { echo "$variant accepted a missing installation helper"; return 1; } + [[ "$output" == *xcat-rootimg-install.sh* ]] + done +} + @test 'all stateless hooks stop when the checksum helper cannot be installed' { for variant in $VARIANTS; do stage_module "$variant" diff --git a/xCAT-test/native/genimage_rootimg_helpers.t b/xCAT-test/native/genimage_rootimg_helpers.t index 40479c46e2..fe3a83809c 100644 --- a/xCAT-test/native/genimage_rootimg_helpers.t +++ b/xCAT-test/native/genimage_rootimg_helpers.t @@ -71,7 +71,7 @@ SH for my $index (1, 2) { my $path = "$box->{root}/work/staged-$index/$module"; ok(-d $path, 'dracut receives the generated module'); - for my $name (qw(xcat-rootimg-checksum.sh)) { + for my $name (qw(xcat-rootimg-checksum.sh xcat-rootimg-install.sh)) { if ($index == $stateless || $family eq 'sles') { ok(-f "$path/$name", "dracut module retains $name without a UFTP receiver"); is(scalar(read_binary("$path/$name")), diff --git a/xCAT-test/unit/imgutils_rootimg_helpers.t b/xCAT-test/unit/imgutils_rootimg_helpers.t index 33d306b9e6..6e273ac147 100644 --- a/xCAT-test/unit/imgutils_rootimg_helpers.t +++ b/xCAT-test/unit/imgutils_rootimg_helpers.t @@ -21,6 +21,11 @@ my $copy = "$module/$name"; imgutils::stage_rootimg_helpers($module, 1); is(scalar(read_binary($copy)), scalar(read_binary($source)), 'checksum-only images receive the helper'); is((stat($copy))[2] & oct('7777'), oct('644'), 'the sourced helper is readable but not executable'); +my $installer = "$module/xcat-rootimg-install.sh"; +is(scalar(read_binary($installer)), + scalar(read_binary("$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils/xcat-rootimg-install.sh")), + 'the build helper is staged independently of UFTP eligibility'); +is((stat($installer))[2] & oct('7777'), oct('644'), 'the build helper is readable but not executable'); write_binary($copy, 'old helper'); chmod(oct('777'), $copy) or die $!; imgutils::stage_rootimg_helpers($module, 1); @@ -29,6 +34,7 @@ is((stat($copy))[2] & oct('7777'), oct('644'), 'a repeated build restores the he imgutils::stage_rootimg_helpers($module, 0); ok(!-e $copy, 'disabled staging removes the previous checksum helper'); +ok(!-e $installer, 'a disabled build removes the previous installation helper'); symlink("$tmp/missing", $copy) or die $!; imgutils::stage_rootimg_helpers($module, 0); ok(!-l $copy, 'a disabled build removes a dangling helper link');