Skip to content

Commit

Permalink
Add IPv6-only test case for NTP (sonic-net#12258)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
saiarcot895 authored Apr 3, 2024
1 parent 9fa89d9 commit bc74af3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions ansible/lab
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ansible/veos_vtb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/common/devices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions tests/ip/test_mgmt_ipv6_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down Expand Up @@ -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)
17 changes: 13 additions & 4 deletions tests/ntp/test_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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]

Expand All @@ -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,
Expand Down Expand Up @@ -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]

Expand All @@ -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)

0 comments on commit bc74af3

Please sign in to comment.