From a6212e838437e35024214b6ddabdcada4b9f8d07 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 3 Sep 2026 14:40:31 -0300 Subject: [PATCH] fix(xcat-core): makentp and the NTP selector disagree on when chrony is usable xCAT::NTP::Backend->available reported chrony as available on chronyd alone, while makentp configured chrony only where systemctl was present too. On a host with chronyd and no systemctl the selector returned chrony with no downgrade, makentp fell through to the ntpd path, and the admin saw either a silent switch or "Please make sure ntpd is installed". available now requires chronyd and systemctl for chrony, so the selector answers on the same terms makentp acts on, and makentp branches on the name alone. choose therefore downgrades to ntpd, or reports install, in the case it used to pass over. A commands argument injects the command probe, in the same shape as the existing available argument. ntp_backend_selection.t covers both commands. Six of its assertions fail without this change. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- perl-xCAT/xCAT/NTP/Backend.pm | 19 +++++++++++++++++-- xCAT-server/lib/xcat/plugins/makentp.pm | 3 +-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/perl-xCAT/xCAT/NTP/Backend.pm b/perl-xCAT/xCAT/NTP/Backend.pm index aac49081b..89dec10d5 100644 --- a/perl-xCAT/xCAT/NTP/Backend.pm +++ b/perl-xCAT/xCAT/NTP/Backend.pm @@ -32,6 +32,7 @@ sub normalize { # requested -- override (default: site.ntpbackend, else 'auto') # os_name/version -- OS identity (default: detected) # available -- optional { chrony => 0/1, ntpd => 0/1 } to bypass command detection (tests) +# commands -- optional { => 0/1 } to bypass the PATH probe for one command # check_available -- when true, downgrade to whichever daemon is installed, and flag install=1 # when neither is. sub choose { @@ -96,11 +97,25 @@ sub available { return $args{available}{$backend} ? 1 : 0; } - return _command_exists('chronyd') if $backend eq 'chrony'; - return _command_exists('ntpd') if $backend eq 'ntpd'; + # xCAT drives chrony through systemd: makentp configures it only where systemctl is present, + # and setupntp hands over to ntpd without it. chronyd alone is not a usable chrony backend. + if ( $backend eq 'chrony' ) { + return ( _has_command( 'chronyd', %args ) && _has_command( 'systemctl', %args ) ) ? 1 : 0; + } + return _has_command( 'ntpd', %args ) if $backend eq 'ntpd'; return 0; } +sub _has_command { + my ( $command, %args ) = @_; + + if ( ref( $args{commands} ) eq 'HASH' && exists $args{commands}{$command} ) { + return $args{commands}{$command} ? 1 : 0; + } + + return _command_exists($command); +} + sub _site_backend { my $backend = eval { require xCAT::TableUtils; diff --git a/xCAT-server/lib/xcat/plugins/makentp.pm b/xCAT-server/lib/xcat/plugins/makentp.pm index 49a35f85e..189a951a3 100644 --- a/xCAT-server/lib/xcat/plugins/makentp.pm +++ b/xCAT-server/lib/xcat/plugins/makentp.pm @@ -327,10 +327,9 @@ sub process_request { send_msg(\%request, 1, $ntp_action->{error}); return 1; } - my $have_systemctl = (-x "/usr/bin/systemctl" || -x "/bin/systemctl"); # Handle chronyd here, - if ($ntp_action->{name} eq 'chrony' && $have_systemctl) { + if ($ntp_action->{name} eq 'chrony') { send_msg(\%request, 0, "Will configure chronyd instead."); my $cmd = setupntp_command($ntp_action->{name}, $ntp_servers);