Skip to content
Merged
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
20 changes: 20 additions & 0 deletions tests/common/helpers/ntp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def setup_ntp_context(ptfhost, duthost, ptf_use_ipv6):
"NTP server was not started in PTF container {}; NTP service start result {}"
.format(ptfhost.hostname, ntp_en_res))

# When using Chrony as the NTP daemon on the DUT, Chrony will not use NTP sources that have a
# root dispersion of more than 3 seconds (configurable via /etc/chrony/chrony.conf, but we currently
# don't touch that setting). Therefore, block here until the root dispersion is less than 3 seconds
# so that we don't incorrectly fail the test.
pytest_assert(wait_until(180, 10, 0, check_max_root_dispersion, ptfhost, 3, NtpDaemon.NTP),
"NTP timing hasn't converged enough in PTF container {}".format(ptfhost.hostname))

# check to see if iburst option is present
ntp_add_help = duthost.command("config ntp add --help")
ntp_add_iburst_present = False
Expand Down Expand Up @@ -89,6 +96,19 @@ def check_ntp_status(host, ntp_daemon_in_use):
return False


def check_max_root_dispersion(host, max_dispersion, ntp_daemon_in_use):
if ntp_daemon_in_use == NtpDaemon.CHRONY:
res = host.command("sudo chronyc -n -c ntpdata")
root_dispersion = float(res["stdout"].split(",")[14]) / 100
return root_dispersion < max_dispersion
elif ntp_daemon_in_use == NtpDaemon.NTP or ntp_daemon_in_use == NtpDaemon.NTPSEC:
res = host.shell("ntpq -c sysinfo | grep 'root dispersion' | awk '{ print $3; }'")
root_dispersion = float(res["stdout"]) / 1000
return root_dispersion < max_dispersion
else:
return False


def run_ntp(duthost, ntp_daemon_in_use):
""" Verify that DUT is synchronized with configured NTP server """

Expand Down
Loading