From bc74af3d0ff3d61d3eb8c90e18428e7994b8984b Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Tue, 2 Apr 2024 18:10:29 -0700 Subject: [PATCH] Add IPv6-only test case for NTP (#12258) ## Type of change - [x] Test case(new/improvement) ## Approach #### What is the motivation for this PR? Add support for testing NTP over IPv6. Additionally, test NTP when running with an IPv6-only network. Also, this fixes the IPv6 address assignment for vlab-02 and makes sure it's given an address on the same subnet as the PTF container. ### How did you verify/test it? Tested on KVM and physical DUT with IPv6-only mgmt address. --- ansible/lab | 1 + ansible/veos_vtb | 2 +- tests/common/devices/base.py | 4 ++++ tests/ip/test_mgmt_ipv6_only.py | 11 +++++++++++ tests/ntp/test_ntp.py | 17 +++++++++++++---- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ansible/lab b/ansible/lab index 40774802f07..b226b283862 100644 --- a/ansible/lab +++ b/ansible/lab @@ -121,6 +121,7 @@ sonic_s6100: ansible_host: 10.251.0.190 vlab-02: ansible_host: 10.250.0.114 + ansible_hostv6: fec0::ffff:afa:e sonic_a7260: vars: diff --git a/ansible/veos_vtb b/ansible/veos_vtb index 7f2f613b3cf..99727bcf33a 100644 --- a/ansible/veos_vtb +++ b/ansible/veos_vtb @@ -111,7 +111,7 @@ all: ansible_user: admin vlab-02: ansible_host: 10.250.0.114 - ansible_hostv6: fec0::ffff:afa:2 + ansible_hostv6: fec0::ffff:afa:e type: kvm hwsku: Force10-S6100 serial_port: 9095 diff --git a/tests/common/devices/base.py b/tests/common/devices/base.py index 381a1aa9a06..3179ca88a06 100644 --- a/tests/common/devices/base.py +++ b/tests/common/devices/base.py @@ -44,6 +44,10 @@ def __init__(self, ansible_adhoc, hostname, *args, **kwargs): else: self.host = ansible_adhoc(become=True, *args, **kwargs)[hostname] self.mgmt_ip = self.host.options["inventory_manager"].get_host(hostname).vars["ansible_host"] + if "ansible_hostv6" in self.host.options["inventory_manager"].get_host(hostname).vars: + self.mgmt_ipv6 = self.host.options["inventory_manager"].get_host(hostname).vars["ansible_hostv6"] + else: + self.mgmt_ipv6 = None self.hostname = hostname def __getattr__(self, module_name): diff --git a/tests/ip/test_mgmt_ipv6_only.py b/tests/ip/test_mgmt_ipv6_only.py index fa736c58a9d..f867b9daa71 100644 --- a/tests/ip/test_mgmt_ipv6_only.py +++ b/tests/ip/test_mgmt_ipv6_only.py @@ -5,6 +5,7 @@ from tests.bgp.test_bgp_fact import run_bgp_facts from tests.test_features import run_show_features from tests.tacacs.test_ro_user import ssh_remote_run +from tests.ntp.test_ntp import run_ntp from tests.common.helpers.assertions import pytest_require from tests.tacacs.conftest import tacacs_creds, check_tacacs_v6 # noqa F401 from tests.syslog.test_syslog import run_syslog, check_default_route # noqa F401 @@ -17,6 +18,11 @@ ] +def pytest_generate_tests(metafunc): + if "ptf_use_ipv6" in metafunc.fixturenames: + metafunc.parametrize("ptf_use_ipv6", [True], scope="module") + + @pytest.fixture(autouse=True) def ignore_expected_loganalyzer_exception(loganalyzer): ignore_regex = [ @@ -129,3 +135,8 @@ def test_rw_user_ipv6_only(localhost, duthosts, enum_rand_one_per_hwsku_hostname res = ssh_remote_run(localhost, dutipv6, tacacs_creds['tacacs_rw_user'], tacacs_creds['tacacs_rw_user_passwd'], "cat /etc/passwd") check_output(res, 'testadmin', 'remote_user_su') + + +def test_ntp_ipv6_only(duthosts, rand_one_dut_hostname, + convert_and_restore_config_db_to_ipv6_only, setup_ntp): # noqa F811 + run_ntp(duthosts, rand_one_dut_hostname, setup_ntp) diff --git a/tests/ntp/test_ntp.py b/tests/ntp/test_ntp.py index 6562b814ac7..c27c28f1e7b 100644 --- a/tests/ntp/test_ntp.py +++ b/tests/ntp/test_ntp.py @@ -15,6 +15,11 @@ TIME_FORWARD = 3600 +def pytest_generate_tests(metafunc): + if "ptf_use_ipv6" in metafunc.fixturenames: + metafunc.parametrize("ptf_use_ipv6", [False, True], scope="module") + + def config_long_jump(duthost, enable=False): """change ntpd option to enable or disable long jump""" ntpsec_conf_stat = duthost.stat(path="/etc/ntpsec/ntp.conf") @@ -40,7 +45,7 @@ def config_long_jump(duthost, enable=False): @pytest.fixture(scope="module") -def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname): +def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname, ptf_use_ipv6): """setup ntp client and server""" duthost = duthosts[rand_one_dut_hostname] @@ -59,14 +64,14 @@ def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname): for ntp_server in ntp_servers: duthost.command("config ntp del %s" % ntp_server) - duthost.command("config ntp add %s" % ptfhost.mgmt_ip) + duthost.command("config ntp add %s" % (ptfhost.mgmt_ipv6 if ptf_use_ipv6 else ptfhost.mgmt_ip)) yield # stop ntp server ptfhost.service(name="ntp", state="stopped") # reset ntp client configuration - duthost.command("config ntp del %s" % ptfhost.mgmt_ip) + duthost.command("config ntp del %s" % (ptfhost.mgmt_ipv6 if ptf_use_ipv6 else ptfhost.mgmt_ip)) for ntp_server in ntp_servers: duthost.command("config ntp add %s" % ntp_server) # The time jump leads to exception in lldp_syncd. The exception has been handled by lldp_syncd, @@ -132,7 +137,7 @@ def test_ntp_long_jump_disabled(duthosts, rand_one_dut_hostname, setup_ntp, setu pytest.fail("NTP long jump disable failed") -def test_ntp(duthosts, rand_one_dut_hostname, setup_ntp): +def run_ntp(duthosts, rand_one_dut_hostname, setup_ntp): """ Verify that DUT is synchronized with configured NTP server """ duthost = duthosts[rand_one_dut_hostname] @@ -148,3 +153,7 @@ def test_ntp(duthosts, rand_one_dut_hostname, setup_ntp): duthost.service(name='ntp', state='restarted') pytest_assert(wait_until(720, 10, 0, check_ntp_status, duthost), "NTP not in sync") + + +def test_ntp(duthosts, rand_one_dut_hostname, setup_ntp): + run_ntp(duthosts, rand_one_dut_hostname, setup_ntp)