Skip to content

Commit 6323792

Browse files
saiarcot895mssonicbld
authored andcommitted
Clean up mgmtvrf test for ntp by reusing existing code (#19140)
What is the motivation for this PR? Update the mgmtvrf test case for ntp by having it use Chrony How did you do it? Reuse existing code that is in the common ntp_helper module instead of copy-pasting code here. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent 9738852 commit 6323792

1 file changed

Lines changed: 5 additions & 31 deletions

File tree

tests/mvrf/test_mgmtvrf.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tests.common.utilities import wait_until
88
from tests.common.config_reload import config_reload
99
from tests.common.helpers.assertions import pytest_assert
10-
from tests.common.helpers.ntp_helper import NtpDaemon, ntp_daemon_in_use # noqa: F401
10+
from tests.common.helpers.ntp_helper import NtpDaemon, ntp_daemon_in_use, setup_ntp_context # noqa: F401
1111
from tests.common.helpers.snmp_helpers import get_snmp_facts
1212
from tests.common.devices.ptf import PTFHost
1313

@@ -156,20 +156,6 @@ def execute_dut_command(duthost, command, mvrf=True, ignore_errors=False):
156156
return result
157157

158158

159-
def setup_ntp(ptfhost, duthost, ntp_servers):
160-
"""setup ntp client and server"""
161-
ptfhost.lineinfile(path="/etc/ntp.conf", line="server 127.127.1.0 prefer")
162-
# restart ntp server
163-
ntp_en_res = ptfhost.service(name="ntp", state="restarted")
164-
pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost, NtpDaemon.NTP),
165-
"NTP server was not started in PTF container {}; NTP service start result {}"
166-
.format(ptfhost.hostname, ntp_en_res))
167-
# setup ntp on dut to sync with ntp server
168-
for ntp_server in ntp_servers:
169-
duthost.command("config ntp del %s" % ntp_server)
170-
duthost.command("config ntp add %s" % ptfhost.mgmt_ip)
171-
172-
173159
class TestMvrfInbound():
174160
def test_ping(self, duthost):
175161
duthost.ping()
@@ -227,22 +213,10 @@ def test_ntp(self, duthosts, rand_one_dut_hostname, ptfhost, check_ntp_sync,
227213
duthost = duthosts[rand_one_dut_hostname]
228214
# Check if ntp was not in sync with ntp server before enabling mvrf, if yes then setup ntp server on ptf
229215
if check_ntp_sync:
230-
setup_ntp(ptfhost, duthost, ntp_servers)
231-
232-
# There is no entry ntp in `/etc/passwd` on kvm testbed.
233-
cmd = "getent passwd ntp"
234-
ntp_uid_output = duthost.command(cmd, module_ignore_errors=True)
235-
if duthost.facts["asic_type"] == "vs" and ntp_uid_output['rc'] == 2:
236-
return
237-
assert ntp_uid_output['rc'] == 0, "Run command '{}' failed".format(cmd)
238-
ntp_uid = ":".join(ntp_uid_output['stdout'].split(':')[2:4])
239-
240-
force_ntp = "timeout 20 ntpd -gq -u {}".format(ntp_uid)
241-
duthost.service(name="ntp", state="stopped")
242-
logger.info("Ntp restart in mgmt vrf")
243-
execute_dut_command(duthost, force_ntp)
244-
duthost.service(name="ntp", state="restarted")
245-
pytest_assert(wait_until(400, 10, 0, check_ntp_status, duthost, ntp_daemon_in_use), "Ntp not started")
216+
with setup_ntp_context(ptfhost, duthost, False):
217+
pytest_assert(wait_until(400, 10, 0, check_ntp_status, duthost, ntp_daemon_in_use), "Ntp not started")
218+
else:
219+
pytest_assert(wait_until(400, 10, 0, check_ntp_status, duthost, ntp_daemon_in_use), "Ntp not started")
246220

247221
def test_service_acl(self, duthosts, rand_one_dut_hostname, localhost):
248222
duthost = duthosts[rand_one_dut_hostname]

0 commit comments

Comments
 (0)