2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00

test(netboot): cover optional UFTP receiver installation

This commit is contained in:
Vinícius Ferrão
2026-11-21 15:37:52 -03:00
parent 1950e1288a
commit 214744f8ff
3 changed files with 76 additions and 1 deletions
@@ -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"
+1 -1
View File
@@ -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")),
@@ -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');