mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-05 04:27:55 +00:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user