From 0925e2b599d429bbfae68a71f83aa57e331834ef Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Tue, 1 Sep 2026 21:33:36 -0300 Subject: [PATCH] test(makentp): the suite really disabled timesyncd on the host running it Hoisting the systemd-timesyncd stop/disable above the ntpd hand-off moved it inside the window makentp_ntp_deps.t extracts as $select, and that harness stubbed only logger and check_executes. So the extracted region called the real systemctl -- and the unit suite runs as root in CI. Probed with a recording systemctl first on PATH, `prove makentp_ntp_deps.t` made 12 real invocations, stop and disable for each of the six selection cases; on the Ubuntu review MN a stand-in timesyncd unit went from enabled/active to disabled/inactive while the suite reported PASS. That is the "never let a test escape its scratch tree" rule, and it failed silently: the assertions passed either way, so nothing said the host had been changed. Shadow every command the region can reach, not only the ones it reached when this was written -- the region moves. Bash resolves functions ahead of $PATH, so these win without touching PATH. The stubs use echo rather than printf '...': the harness runs `bash -c '...'`, so a single quote inside the prelude closes that string early. The existing logger stub gets away with it; three more did not, and the ntpd selection cases failed until they were rewritten. Verified after: zero real systemctl invocations from the whole unit suite under the same probe, and 18/18 still pass. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/makentp_ntp_deps.t | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xCAT-test/unit/makentp_ntp_deps.t b/xCAT-test/unit/makentp_ntp_deps.t index a0cb38143..199e2674d 100644 --- a/xCAT-test/unit/makentp_ntp_deps.t +++ b/xCAT-test/unit/makentp_ntp_deps.t @@ -135,7 +135,15 @@ foreach my $case ( ) { my ($argv, $missing, $want, $name) = @$case; my $root = File::Temp::tempdir(CLEANUP => 1); + # Every command the extracted region can reach has to be shadowed, not just the ones it + # reached when this was written: the region moves. systemctl is here because the + # systemd-timesyncd stop/disable was hoisted above the ntpd hand-off and landed inside this + # window -- unstubbed, and the suite runs as root in CI, it really disabled timesyncd on the + # host running the tests. Bash resolves functions ahead of $PATH, so these win. my $prelude = "logger() { printf '%s\\n' \"\$*\" >>\"$root/log\"; return 0; }\n" + . "systemctl() { echo \"systemctl \$*\" >>\"$root/calls\"; return 0; }\n" + . "timedatectl() { echo \"timedatectl \$*\" >>\"$root/calls\"; return 0; }\n" + . "hwclock() { echo \"hwclock \$*\" >>\"$root/calls\"; return 0; }\n" . "check_executes() { for c in \"\$@\"; do [ \"\$c\" = \"$missing\" ] && return 1; done; return 0; }\n" . "log_label=xcat\nset -- $argv\n"; my $out = `bash -c 'exec 2>/dev/null; $prelude$args$select