Skip to content

Commit

Permalink
Replace ntp-config and ntpd with chrony
Browse files Browse the repository at this point in the history
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
  • Loading branch information
saiarcot895 committed Oct 9, 2024
1 parent 6ca1169 commit 5ae9cbe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
12 changes: 6 additions & 6 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7083,10 +7083,10 @@ def add_ntp_server(ctx, ntp_ip_address, association_type, iburst, version):
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
click.echo("NTP server {} added to configuration".format(ntp_ip_address))
try:
click.echo("Restarting ntp-config service...")
clicommon.run_command(['systemctl', 'restart', 'ntp-config'], display_cmd=False)
click.echo("Restarting chrony service...")
clicommon.run_command(['systemctl', 'restart', 'chrony'], display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service ntp-config failed with error {}".format(e))
ctx.fail("Restart service chrony failed with error {}".format(e))

@ntp.command('del')
@click.argument('ntp_ip_address', metavar='<ntp_ip_address>', required=True)
Expand All @@ -7107,10 +7107,10 @@ def del_ntp_server(ctx, ntp_ip_address):
else:
ctx.fail("NTP server {} is not configured.".format(ntp_ip_address))
try:
click.echo("Restarting ntp-config service...")
clicommon.run_command(['systemctl', 'restart', 'ntp-config'], display_cmd=False)
click.echo("Restarting chrony service...")
clicommon.run_command(['systemctl', 'restart', 'chrony'], display_cmd=False)
except SystemExit as e:
ctx.fail("Restart service ntp-config failed with error {}".format(e))
ctx.fail("Restart service chrony failed with error {}".format(e))

#
# 'sflow' group ('config sflow ...')
Expand Down
21 changes: 7 additions & 14 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,22 +1928,15 @@ def bgp(verbose):
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def ntp(ctx, verbose):
"""Show NTP information"""
from pkg_resources import parse_version
ntpstat_cmd = ["ntpstat"]
ntpcmd = ["ntpq", "-p", "-n"]
chronyc_tracking_cmd = ["chronyc", "tracking"]
chronyc_sources_cmd = ["chronyc", "sources"]
if is_mgmt_vrf_enabled(ctx) is True:
#ManagementVRF is enabled. Call ntpq using "ip vrf exec" or cgexec based on linux version
os_info = os.uname()
release = os_info[2].split('-')
if parse_version(release[0]) > parse_version("4.9.0"):
ntpstat_cmd = ['sudo', 'ip', 'vrf', 'exec', 'mgmt', 'ntpstat']
ntpcmd = ['sudo', 'ip', 'vrf', 'exec', 'mgmt', 'ntpq', '-p', '-n']
else:
ntpstat_cmd = ['sudo', 'cgexec', '-g', 'l3mdev:mgmt', 'ntpstat']
ntpcmd = ['sudo', 'cgexec', '-g', 'l3mdev:mgmt', 'ntpq', '-p', '-n']
#ManagementVRF is enabled. Call chronyc using "ip vrf exec" based on linux version
chronyc_tracking_cmd = ["sudo", "ip", "vrf", "exec", "mgmt"] + chronyc_tracking_cmd
chronyc_sources_cmd = ["sudo", "ip", "vrf", "exec", "mgmt"] + chronyc_sources_cmd

run_command(ntpstat_cmd, display_cmd=verbose)
run_command(ntpcmd, display_cmd=verbose)
run_command(chronyc_tracking_cmd, display_cmd=verbose)
run_command(chronyc_sources_cmd, display_cmd=verbose)

#
# 'uptime' command ("show uptime")
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
sys.path.insert(0, modules_path)

generated_services_list = [
'ntp-config.service',
'warmboot-finalizer.service',
'watchdog-control.service',
'rsyslog-config.service',
Expand Down

0 comments on commit 5ae9cbe

Please sign in to comment.