From 79f5291554964c0c50391a726690d7ec0999a7e5 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:32:12 -0300 Subject: [PATCH 1/2] test(xcat-test): the cases restart a DHCPv4 unit that Ubuntu does not have xCAT runs Kea as kea-dhcp4 on EL and as kea-dhcp4-server on Debian and Ubuntu. Ten cmd lines across five case files probed the EL name alone and fell back to isc-dhcp-server on Ubuntu, which is absent where Kea is the backend. reg_linux_diskless_installation_hierarchy failed on it in xcat-test-ubuntu-24-x86_64 #85: rc 5, "Unit isc-dhcp-server.service not found". Measured on xcat24-mn, Ubuntu 24.04.4: kea-dhcp4 inactive, kea-dhcp4-server active, isc-dhcp-server absent. restart_dhcp.sh restarts whichever DHCPv4 unit is active, and --print-unit names it for a caller that asks which backend the node runs. The bats cases drive it with a stub systemctl that reports one unit active and records what was restarted. The eight cases pass with the file as committed, so the discriminating evidence is a mutation: dropping kea-dhcp4-server from the candidate list reds exactly "the Ubuntu Kea unit is restarted" and the message assertion, and leaves the EL, ISC and dhcpd cases green. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../testcase/commoncmd/restart_dhcp.sh | 30 ++++++ xCAT-test/bats/restart_dhcp_backend.bats | 99 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100755 xCAT-test/autotest/testcase/commoncmd/restart_dhcp.sh create mode 100644 xCAT-test/bats/restart_dhcp_backend.bats diff --git a/xCAT-test/autotest/testcase/commoncmd/restart_dhcp.sh b/xCAT-test/autotest/testcase/commoncmd/restart_dhcp.sh new file mode 100755 index 0000000000..20cd2981f2 --- /dev/null +++ b/xCAT-test/autotest/testcase/commoncmd/restart_dhcp.sh @@ -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 diff --git a/xCAT-test/bats/restart_dhcp_backend.bats b/xCAT-test/bats/restart_dhcp_backend.bats new file mode 100644 index 0000000000..d108fb261d --- /dev/null +++ b/xCAT-test/bats/restart_dhcp_backend.bats @@ -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" <>"$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 ] +} From 018987d0fbd231237312c6b3716b072c1cac23f9 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:32:12 -0300 Subject: [PATCH 2/2] fix(xcat-test): the cases restart a DHCPv4 unit that Ubuntu does not have Ten cmd lines in five case files restarted the DHCPv4 server with the same inline probe of kea-dhcp4, falling back to isc-dhcp-server on Ubuntu. Kea is the backend there and its unit is kea-dhcp4-server, so the probe was false and the fallback named a unit that is not installed. The restart exited 5 with "Unit isc-dhcp-server.service not found" and failed the case. Each of those lines now calls commoncmd/restart_dhcp.sh. discovery_test also decided whether to create /var/lib/dhcpd/dhcpd.leases from the same single-unit probe, so on an Ubuntu management node it wrote an ISC leases file beside a Kea backend; it now asks restart_dhcp.sh --print-unit. Each rewritten line keeps the check that followed it. xcattest discards a cmd line that does not start with [#/$\w] and binds its checks to the previous command, so the calls are written as absolute paths. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/autotest/testcase/discovery/discovery_test | 4 ++-- .../installation/reg_linux_diskless_installation_hierarchy | 4 ++-- xCAT-test/autotest/testcase/makedhcp/cases0 | 6 +++--- xCAT-test/autotest/testcase/migration/redhat_migration | 4 ++-- xCAT-test/autotest/testcase/migration/sles_migration | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/xCAT-test/autotest/testcase/discovery/discovery_test b/xCAT-test/autotest/testcase/discovery/discovery_test index 6c2b94b771..f88a9777f7 100755 --- a/xCAT-test/autotest/testcase/discovery/discovery_test +++ b/xCAT-test/autotest/testcase/discovery/discovery_test @@ -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"); diff --git a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_hierarchy b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_hierarchy index fbc24cc23a..1d24d77704 100644 --- a/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_hierarchy +++ b/xCAT-test/autotest/testcase/installation/reg_linux_diskless_installation_hierarchy @@ -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 diff --git a/xCAT-test/autotest/testcase/makedhcp/cases0 b/xCAT-test/autotest/testcase/makedhcp/cases0 index 635f9f2e33..a2f0b0b0ce 100644 --- a/xCAT-test/autotest/testcase/makedhcp/cases0 +++ b/xCAT-test/autotest/testcase/makedhcp/cases0 @@ -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 diff --git a/xCAT-test/autotest/testcase/migration/redhat_migration b/xCAT-test/autotest/testcase/migration/redhat_migration index 23add78588..0a1dd06946 100644 --- a/xCAT-test/autotest/testcase/migration/redhat_migration +++ b/xCAT-test/autotest/testcase/migration/redhat_migration @@ -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 diff --git a/xCAT-test/autotest/testcase/migration/sles_migration b/xCAT-test/autotest/testcase/migration/sles_migration index ff84e27fcd..eddaa124c8 100644 --- a/xCAT-test/autotest/testcase/migration/sles_migration +++ b/xCAT-test/autotest/testcase/migration/sles_migration @@ -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