2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-20 17:32:15 +00:00

Merge remote-tracking branch 'origin/fix/xcat-test-dhcp4-unit-name-on-ubuntu' into releases/2.20.0-rc9

This commit is contained in:
Daniel Hilst
2026-11-08 16:32:20 -03:00
7 changed files with 140 additions and 11 deletions
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
# Restart the DHCPv4 server this management node actually runs.
#
# xCAT's Kea unit is kea-dhcp4 on EL and kea-dhcp4-server on Debian and Ubuntu. The cases probed
# the EL name alone, so the probe was false on Ubuntu and the fallback restarted
# isc-dhcp-server -- which is absent where Kea is the backend. The restart then exited 5 with
# "Unit isc-dhcp-server.service not found" and failed the case.
set -u
UNITS=${XCAT_DHCP4_UNITS:-"kea-dhcp4 kea-dhcp4-server isc-dhcp-server dhcpd"}
# --print-unit names the active unit instead of restarting it, for a caller that asks which
# backend this node runs. A caller testing for Kea must not probe the EL unit name alone.
print_only=no
if [ "${1:-}" = --print-unit ]; then
print_only=yes
fi
for unit in $UNITS; do
if systemctl is-active "$unit" >/dev/null 2>&1; then
if [ "$print_only" = yes ]; then
printf '%s\n' "$unit"
exit 0
fi
exec systemctl restart "$unit"
fi
done
echo "no DHCPv4 server is active on this node; tried: $UNITS" >&2
exit 1
@@ -478,8 +478,8 @@ sub set_up_test_env_for_node_discovery {
"rm -f /var/log/consoles/node-*",
"rmdef $discovery_target_node",
"rm -f /var/lib/dhcp/* /var/lib/kea/kea-leases4.csv 2>/dev/null; true",
"if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then true; else mkdir -p /var/lib/dhcpd; touch /var/lib/dhcpd/dhcpd.leases; fi",
"if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi",
"if /opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh --print-unit | grep -q '^kea'; then true; else mkdir -p /var/lib/dhcpd; touch /var/lib/dhcpd/dhcpd.leases; fi",
"/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh",
"$predef_node_cmd",
"makehosts -a $discovery_prodefine_node_name_in_automation",
"makedns $discovery_prodefine_node_name_in_automation");
@@ -34,7 +34,7 @@ cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
check:rc==0
cmd:a=0;while true; do [ $a -eq 100 ] && exit 1;output=$(makedhcp -q $$CN);[ $? -ne 0 ] && exit 1;echo $output|grep $$CN 2>/dev/null && exit 0;a=$[$a+1];sleep 1;done
check:rc==0
@@ -150,7 +150,7 @@ cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
check:rc==0
cmd:a=0;while true; do [ $a -eq 100 ] && exit 1;output=$(makedhcp -q $$CN);[ $? -ne 0 ] && exit 1;echo $output|grep $$CN 2>/dev/null && exit 0;a=$[$a+1];sleep 1;done
check:rc==0
+3 -3
View File
@@ -163,7 +163,7 @@ os:Linux
label:cn_os_ready,dhcp
cmd:makedhcp -a -d
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
cmd:makedhcp -q $$CN
check:rc==0
check:output!~$$CN
@@ -175,7 +175,7 @@ os:ubuntu
label:cn_os_ready,dhcp
cmd:makedhcp -a -d
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
cmd:if [ -f /var/lib/kea/kea-leases4.csv ]; then cat /var/lib/kea/kea-leases4.csv | grep $$CN; elif [ -f /var/lib/dhcp/dhcpd.leases ]; then cat /var/lib/dhcp/dhcpd.leases | grep $$CN; fi
check:output!~$$CN
cmd:makedhcp -a
@@ -186,7 +186,7 @@ os:Linux
label:cn_os_ready,dhcp
cmd:makedhcp -d $$CN
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
cmd:makedhcp -q $$CN
check:output!~$$CN
cmd:makedhcp -a
@@ -24,7 +24,7 @@ cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
check:rc==0
cmd:if [ -f /etc/kea/kea-dhcp4.conf ]; then grep $$CN /etc/kea/kea-dhcp4.conf; elif cat /etc/*release |grep SUSE >/dev/null;then cat /var/lib/dhcp/db/dhcpd.leases|grep $$CN;elif cat /etc/*release |grep "Red Hat\|Rocky\|Alma" >/dev/null;then cat /var/lib/dhcpd/dhcpd.leases|grep $$CN;fi
check:output=~$$CN
@@ -133,7 +133,7 @@ cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
check:rc==0
cmd:if [ -f /etc/kea/kea-dhcp4.conf ]; then grep $$CN /etc/kea/kea-dhcp4.conf; elif cat /etc/*release |grep SUSE >/dev/null;then cat /var/lib/dhcp/db/dhcpd.leases|grep $$CN;elif cat /etc/*release |grep "Red Hat\|Rocky\|Alma" >/dev/null;then cat /var/lib/dhcpd/dhcpd.leases|grep $$CN;fi
check:output=~$$CN
@@ -23,7 +23,7 @@ cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
check:rc==0
cmd:if [ -f /etc/kea/kea-dhcp4.conf ]; then grep $$CN /etc/kea/kea-dhcp4.conf; elif cat /etc/*release |grep SUSE >/dev/null;then cat /var/lib/dhcp/db/dhcpd.leases|grep $$CN;elif cat /etc/*release |grep "Red Hat" >/dev/null;then cat /var/lib/dhcpd/dhcpd.leases|grep $$CN;fi
check:output=~$$CN
@@ -142,7 +142,7 @@ cmd:makedhcp -n
check:rc==0
cmd:makedhcp -a
check:rc==0
cmd:if systemctl is-active kea-dhcp4 >/dev/null 2>&1; then systemctl restart kea-dhcp4; elif cat /etc/*release | grep -qi ubuntu; then service isc-dhcp-server restart; else service dhcpd restart; fi
cmd:/opt/xcat/share/xcat/tools/autotest/testcase/commoncmd/restart_dhcp.sh
check:rc==0
cmd:if [ -f /etc/kea/kea-dhcp4.conf ]; then grep $$CN /etc/kea/kea-dhcp4.conf; elif cat /etc/*release |grep SUSE >/dev/null;then cat /var/lib/dhcp/db/dhcpd.leases|grep $$CN;elif cat /etc/*release |grep "Red Hat" >/dev/null;then cat /var/lib/dhcpd/dhcpd.leases|grep $$CN;fi
check:output=~$$CN
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bats
#
# The cases restarted the DHCPv4 server by probing kea-dhcp4 and falling back to
# isc-dhcp-server on Ubuntu. xCAT's Kea unit on Debian and Ubuntu is kea-dhcp4-server, so the
# probe was false and the fallback named a unit that is not installed there:
# reg_linux_diskless_installation_hierarchy failed on "Unit isc-dhcp-server.service not found"
# with rc 5, measured on xcat24-mn, Ubuntu 24.04.4.
load 'helpers/shell_source'
setup()
{
SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/restart_dhcp.sh')"
BIN="${BATS_TEST_TMPDIR}/bin"
mkdir -p "$BIN"
ACTED="${BATS_TEST_TMPDIR}/acted"
: >"$ACTED"
}
# Stand in for systemctl, reporting exactly one unit active and recording what was restarted.
stub_systemctl()
{
local active="$1"
cat >"$BIN/systemctl" <<SH
#!/bin/bash
printf '%s\n' "\$*" >>"$ACTED"
case "\$1 \$2" in
"is-active $active") exit 0 ;;
is-active*) exit 3 ;;
"restart $active") exit 0 ;;
restart*) printf 'Unit %s.service not found.\n' "\$2" >&2; exit 5 ;;
esac
SH
chmod 0755 "$BIN/systemctl"
}
run_helper()
{
run env PATH="$BIN:$PATH" bash "$SCRIPT"
}
@test "the Ubuntu Kea unit is restarted" {
stub_systemctl kea-dhcp4-server
run_helper
[ "$status" -eq 0 ]
grep -qx 'restart kea-dhcp4-server' "$ACTED"
refute_grep -q 'isc-dhcp-server' "$ACTED"
}
@test "the EL Kea unit is restarted" {
stub_systemctl kea-dhcp4
run_helper
[ "$status" -eq 0 ]
grep -qx 'restart kea-dhcp4' "$ACTED"
}
@test "an ISC backend is still restarted" {
stub_systemctl isc-dhcp-server
run_helper
[ "$status" -eq 0 ]
grep -qx 'restart isc-dhcp-server' "$ACTED"
}
@test "the EL ISC unit is still restarted" {
stub_systemctl dhcpd
run_helper
[ "$status" -eq 0 ]
grep -qx 'restart dhcpd' "$ACTED"
}
@test "no active DHCPv4 server is an error that names what was tried" {
stub_systemctl none-of-them
run_helper
[ "$status" -ne 0 ]
[[ "$output" == *"no DHCPv4 server is active"* ]]
[[ "$output" == *kea-dhcp4-server* ]]
refute_grep -q '^restart' "$ACTED"
}
@test "--print-unit names the Ubuntu Kea unit and restarts nothing" {
stub_systemctl kea-dhcp4-server
run env PATH="$BIN:$PATH" bash "$SCRIPT" --print-unit
[ "$status" -eq 0 ]
[ "$output" = kea-dhcp4-server ]
refute_grep -q '^restart' "$ACTED"
}
@test "--print-unit names an ISC backend, so a caller can tell it from Kea" {
stub_systemctl dhcpd
run env PATH="$BIN:$PATH" bash "$SCRIPT" --print-unit
[ "$status" -eq 0 ]
[ "$output" = dhcpd ]
}
@test "--print-unit fails when no DHCPv4 server is active" {
stub_systemctl none-of-them
run env PATH="$BIN:$PATH" bash "$SCRIPT" --print-unit
[ "$status" -ne 0 ]
}