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