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
15 changes: 12 additions & 3 deletions tests/common/helpers/ntp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,29 @@ 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))

# 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),
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
Expand Down
Loading