Skip to content

Commit 52d8be7

Browse files
authored
Update setup_ntp_context to detect NTP daemon type (#18583)
Bookworm uses ntpsec as the NTP daemon on the PTF host. The PR is modified to be backward compatible with Bullseye. It detects the NTP daemon type which is NTP on Bullseye and NTPSEC on Bookworm. Fixes test failures on Bookworm that rely on the NTP daemon setup like ip/test_mgmt_ipv6_only.py::test_ntp_ipv6_only
1 parent 8992a90 commit 52d8be7

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

tests/common/helpers/ntp_helper.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@ class NtpDaemon(Enum):
1515
@contextmanager
1616
def setup_ntp_context(ptfhost, duthost, ptf_use_ipv6):
1717
"""setup ntp client and server"""
18-
ptfhost.lineinfile(path="/etc/ntp.conf", line="server 127.127.1.0 prefer")
18+
ntp_daemon_type = get_ntp_daemon_in_use(ptfhost)
19+
ntp_conf_path = None
20+
if ntp_daemon_type == NtpDaemon.NTPSEC:
21+
ntp_conf_path = '/etc/ntpsec/ntp.conf'
22+
elif ntp_daemon_type == NtpDaemon.CHRONY:
23+
ntp_conf_path = '/etc/chrony/chrony.conf'
24+
elif ntp_daemon_type == NtpDaemon.NTP:
25+
ntp_conf_path = '/etc/ntp.conf'
26+
27+
ptfhost.lineinfile(path=ntp_conf_path, line="server 127.127.1.0 prefer")
1928

2029
# restart ntp server
2130
ntp_en_res = ptfhost.service(name="ntp", state="restarted")
2231

23-
pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost, NtpDaemon.NTP),
32+
pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost, ntp_daemon_type),
2433
"NTP server was not started in PTF container {}; NTP service start result {}"
2534
.format(ptfhost.hostname, ntp_en_res))
2635

2736
# When using Chrony as the NTP daemon on the DUT, Chrony will not use NTP sources that have a
2837
# root dispersion of more than 3 seconds (configurable via /etc/chrony/chrony.conf, but we currently
2938
# don't touch that setting). Therefore, block here until the root dispersion is less than 3 seconds
3039
# 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),
40+
pytest_assert(wait_until(180, 10, 0, check_max_root_dispersion, ptfhost, 3, ntp_daemon_type),
3241
"NTP timing hasn't converged enough in PTF container {}".format(ptfhost.hostname))
3342

3443
# check to see if iburst option is present

0 commit comments

Comments
 (0)