diff --git a/config/main.py b/config/main.py index dbd574ff01..e6891568cc 100644 --- a/config/main.py +++ b/config/main.py @@ -8018,8 +8018,11 @@ def ntp(ctx): @ntp.command('add') @click.argument('ntp_ip_address', metavar='', 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): @@ -8030,18 +8033,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='', required=True) @@ -8062,10 +8070,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 ...') diff --git a/show/main.py b/show/main.py index 971a3bc1cc..1e73cac0ab 100755 --- a/show/main.py +++ b/show/main.py @@ -2045,22 +2045,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") diff --git a/tests/conftest.py b/tests/conftest.py index 3874668a67..41c9901e86 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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',