Skip to content

Commit 04f0eb0

Browse files
authored
Add check for max root dispersion on the PTF's NTP daemon (sonic-net#17629)
* Add check for max root dispersion on the PTF's NTP daemon 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. Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com> * Fix math and fix whitespace Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com> --------- Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
1 parent 8759b08 commit 04f0eb0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/common/helpers/ntp_helper.py

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def setup_ntp_context(ptfhost, duthost, ptf_use_ipv6):
2424
"NTP server was not started in PTF container {}; NTP service start result {}"
2525
.format(ptfhost.hostname, ntp_en_res))
2626

27+
# When using Chrony as the NTP daemon on the DUT, Chrony will not use NTP sources that have a
28+
# root dispersion of more than 3 seconds (configurable via /etc/chrony/chrony.conf, but we currently
29+
# don't touch that setting). Therefore, block here until the root dispersion is less than 3 seconds
30+
# so that we don't incorrectly fail the test.
31+
pytest_assert(wait_until(180, 10, 0, check_max_root_dispersion, ptfhost, 3, NtpDaemon.NTP),
32+
"NTP timing hasn't converged enough in PTF container {}".format(ptfhost.hostname))
33+
2734
# check to see if iburst option is present
2835
ntp_add_help = duthost.command("config ntp add --help")
2936
ntp_add_iburst_present = False
@@ -89,6 +96,19 @@ def check_ntp_status(host, ntp_daemon_in_use):
8996
return False
9097

9198

99+
def check_max_root_dispersion(host, max_dispersion, ntp_daemon_in_use):
100+
if ntp_daemon_in_use == NtpDaemon.CHRONY:
101+
res = host.command("sudo chronyc -n -c ntpdata")
102+
root_dispersion = float(res["stdout"].split(",")[14]) / 100
103+
return root_dispersion < max_dispersion
104+
elif ntp_daemon_in_use == NtpDaemon.NTP or ntp_daemon_in_use == NtpDaemon.NTPSEC:
105+
res = host.shell("ntpq -c sysinfo | grep 'root dispersion' | awk '{ print $3; }'")
106+
root_dispersion = float(res["stdout"]) / 1000
107+
return root_dispersion < max_dispersion
108+
else:
109+
return False
110+
111+
92112
def run_ntp(duthost, ntp_daemon_in_use):
93113
""" Verify that DUT is synchronized with configured NTP server """
94114

0 commit comments

Comments
 (0)