From b3d6e1f9aa7fd711a83c7ed29c654de2b0271810 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 3 Sep 2026 14:40:07 -0300 Subject: [PATCH] test(ntp): the selector calls chrony available where makentp will not use it xCAT::NTP::Backend->available reports chrony as available when chronyd exists. makentp configures chrony only when systemctl exists as well, and setupntp hands over to ntpd without it. On a host with chronyd and no systemctl the selector answers chrony, makentp takes the ntpd path anyway, and the admin is told nothing. ntp_backend_selection.t drives available and choose with the command probe injected, so a case can hold chronyd present and systemctl absent without depending on what the test host has installed. Six assertions fail: available reports chrony on chronyd alone, and choose neither downgrades nor asks for an install. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/ntp_backend_selection.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xCAT-test/unit/ntp_backend_selection.t b/xCAT-test/unit/ntp_backend_selection.t index 3f86cf0a2..24df42dc6 100644 --- a/xCAT-test/unit/ntp_backend_selection.t +++ b/xCAT-test/unit/ntp_backend_selection.t @@ -69,4 +69,28 @@ $r = xCAT::NTP::Backend->choose( is( $r->{name}, 'chrony', 'neither present keeps the preferred chrony' ); is( $r->{install}, 1, 'neither present flags install of the preferred daemon' ); +# --- available: chrony needs systemd, not just chronyd ----------------------------------------- +# makentp configures chrony only where systemctl is present, and setupntp hands over to ntpd +# without it. The selector has to call chrony usable on the same terms, or makentp silently takes +# the ntpd path for a backend the selector reported as available. +is( xCAT::NTP::Backend->available( 'chrony', commands => { chronyd => 1, systemctl => 1 } ), 1, + 'chrony is available where chronyd and systemctl are both present' ); +is( xCAT::NTP::Backend->available( 'chrony', commands => { chronyd => 1, systemctl => 0 } ), 0, + 'chronyd without systemctl is not a usable chrony backend' ); +is( xCAT::NTP::Backend->available( 'chrony', commands => { chronyd => 0, systemctl => 1 } ), 0, + 'systemctl without chronyd is not a usable chrony backend either' ); +is( xCAT::NTP::Backend->available( 'ntpd', commands => { ntpd => 1 } ), 1, + 'ntpd needs only ntpd' ); + +$r = xCAT::NTP::Backend->choose( + requested => 'chrony', check_available => 1, + commands => { chronyd => 1, systemctl => 0, ntpd => 1 } ); +is( $r->{name}, 'ntpd', 'chronyd without systemctl downgrades to the daemon that can be used' ); +is( $r->{downgraded}, 'chrony', 'and the downgrade is reported rather than silent' ); + +$r = xCAT::NTP::Backend->choose( + requested => 'chrony', check_available => 1, + commands => { chronyd => 1, systemctl => 0, ntpd => 0 } ); +is( $r->{install}, 1, 'chronyd without systemctl and no ntpd asks for an install' ); + done_testing();