diff --git a/tests/common/helpers/ntp_helper.py b/tests/common/helpers/ntp_helper.py index d6ecb702589..9033bb5d920 100644 --- a/tests/common/helpers/ntp_helper.py +++ b/tests/common/helpers/ntp_helper.py @@ -15,12 +15,21 @@ class NtpDaemon(Enum): @contextmanager def setup_ntp_context(ptfhost, duthost, ptf_use_ipv6): """setup ntp client and server""" - ptfhost.lineinfile(path="/etc/ntp.conf", line="server 127.127.1.0 prefer") + ntp_daemon_type = get_ntp_daemon_in_use(ptfhost) + ntp_conf_path = None + if ntp_daemon_type == NtpDaemon.NTPSEC: + ntp_conf_path = '/etc/ntpsec/ntp.conf' + elif ntp_daemon_type == NtpDaemon.CHRONY: + ntp_conf_path = '/etc/chrony/chrony.conf' + elif ntp_daemon_type == NtpDaemon.NTP: + ntp_conf_path = '/etc/ntp.conf' + + ptfhost.lineinfile(path=ntp_conf_path, line="server 127.127.1.0 prefer") # restart ntp server ntp_en_res = ptfhost.service(name="ntp", state="restarted") - pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost, NtpDaemon.NTP), + pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost, ntp_daemon_type), "NTP server was not started in PTF container {}; NTP service start result {}" .format(ptfhost.hostname, ntp_en_res)) @@ -28,7 +37,7 @@ def setup_ntp_context(ptfhost, duthost, ptf_use_ipv6): # 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), + pytest_assert(wait_until(180, 10, 0, check_max_root_dispersion, ptfhost, 3, ntp_daemon_type), "NTP timing hasn't converged enough in PTF container {}".format(ptfhost.hostname)) # check to see if iburst option is present