Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using chrony instead of ntpd #3574

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7055,8 +7055,11 @@ def ntp(ctx):

@ntp.command('add')
@click.argument('ntp_ip_address', metavar='<ntp_ip_address>', required=True)
@click.option('--association-type', type=click.Choice(["server", "pool"], case_sensitive=False), default="server", help="Define the association type for this NTP server")
@click.option('--iburst', is_flag=True, help="Enable iburst for this NTP server")
@click.option('--version', type=int, help="Specify the version for this NTP server")
@click.pass_context
def add_ntp_server(ctx, ntp_ip_address):
def add_ntp_server(ctx, ntp_ip_address, association_type, iburst, version):
""" Add NTP server IP """
if ADHOC_VALIDATION:
if not clicommon.is_ipaddress(ntp_ip_address):
Expand All @@ -7067,18 +7070,23 @@ def add_ntp_server(ctx, ntp_ip_address):
click.echo("NTP server {} is already configured".format(ntp_ip_address))
return
else:
ntp_server_options = {}
if version:
ntp_server_options['version'] = version
if association_type != "server":
ntp_server_options['association_type'] = association_type
if iburst:
ntp_server_options['iburst'] = "on"
try:
db.set_entry('NTP_SERVER', ntp_ip_address,
{'resolve_as': ntp_ip_address,
'association_type': 'server'})
db.set_entry('NTP_SERVER', ntp_ip_address, ntp_server_options)
except ValueError as e:
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 @@ -7099,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
Loading