Skip to content

Commit 9133802

Browse files
authored
Add IPV6 only telemetry test case (#12440)
## Description of PR Summary: Fixes # (issue) 26660292 ### Type of change - [ ] Bug fix - [ ] Testbed and Framework(new/improvement) - [x] Test case(new/improvement) #### What is the motivation for this PR? Backport #12268 #12420 #### How did you do it? backport to 202305 #### How did you verify/test it? Manual test
1 parent 9bc592a commit 9133802

File tree

5 files changed

+59
-25
lines changed

5 files changed

+59
-25
lines changed

tests/common/utilities.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from tests.common.cache import FactsCache
3434
from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, DOWNSTREAM_NEIGHBOR_MAP
3535
from tests.common.helpers.assertions import pytest_assert
36+
from netaddr import valid_ipv6
3637

3738
logger = logging.getLogger(__name__)
3839
cache = FactsCache()
@@ -476,6 +477,19 @@ def is_ipv4_address(ip_address):
476477
return False
477478

478479

480+
def get_mgmt_ipv6(duthost):
481+
config_facts = duthost.get_running_config_facts()
482+
mgmt_interfaces = config_facts.get("MGMT_INTERFACE", {})
483+
mgmt_ipv6 = None
484+
485+
for mgmt_interface, ip_configs in mgmt_interfaces.items():
486+
for ip_addr_with_prefix in ip_configs.keys():
487+
ip_addr = ip_addr_with_prefix.split("/")[0]
488+
if valid_ipv6(ip_addr):
489+
mgmt_ipv6 = ip_addr
490+
return mgmt_ipv6
491+
492+
479493
def compare_crm_facts(left, right):
480494
"""Compare CRM facts
481495

tests/ip/test_mgmt_ipv6_only.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
2+
import re
23

3-
from netaddr import valid_ipv6
4+
from tests.common.utilities import get_mgmt_ipv6
5+
from tests.common.helpers.assertions import pytest_assert
46
from tests.tacacs.utils import check_output
57
from tests.bgp.test_bgp_fact import run_bgp_facts
68
from tests.test_features import run_show_features
@@ -9,6 +11,8 @@
911
from tests.tacacs.conftest import tacacs_creds, check_tacacs_v6 # noqa F401
1012
from tests.syslog.test_syslog import run_syslog, check_default_route # noqa F401
1113
from tests.common.fixtures.duthost_utils import convert_and_restore_config_db_to_ipv6_only # noqa F401
14+
from tests.common.helpers.gnmi_utils import GNMIEnvironment
15+
from tests.telemetry.conftest import gnxi_path, setup_streaming_telemetry # noqa F401
1216

1317
pytestmark = [
1418
pytest.mark.disable_loganalyzer,
@@ -44,19 +48,6 @@ def ignore_expected_loganalyzer_exception(loganalyzer):
4448
loganalyzer[hostname].ignore_regex.extend(ignore_regex)
4549

4650

47-
def get_mgmt_ipv6(duthost):
48-
config_facts = duthost.get_running_config_facts()
49-
mgmt_interfaces = config_facts.get("MGMT_INTERFACE", {})
50-
mgmt_ipv6 = None
51-
52-
for mgmt_interface, ip_configs in mgmt_interfaces.items():
53-
for ip_addr_with_prefix in ip_configs.keys():
54-
ip_addr = ip_addr_with_prefix.split("/")[0]
55-
if valid_ipv6(ip_addr):
56-
mgmt_ipv6 = ip_addr
57-
return mgmt_ipv6
58-
59-
6051
def test_bgp_facts_ipv6_only(duthosts, enum_frontend_dut_hostname, enum_asic_index,
6152
convert_and_restore_config_db_to_ipv6_only): # noqa F811
6253
run_bgp_facts(duthosts, enum_frontend_dut_hostname, enum_asic_index)
@@ -129,3 +120,22 @@ def test_rw_user_ipv6_only(localhost, duthosts, enum_rand_one_per_hwsku_hostname
129120
res = ssh_remote_run(localhost, dutipv6, tacacs_creds['tacacs_rw_user'],
130121
tacacs_creds['tacacs_rw_user_passwd'], "cat /etc/passwd")
131122
check_output(res, 'testadmin', 'remote_user_su')
123+
124+
125+
@pytest.mark.parametrize('setup_streaming_telemetry', [True], indirect=True)
126+
def test_telemetry_output_ipv6_only(convert_and_restore_config_db_to_ipv6_only, # noqa F811
127+
duthosts, enum_rand_one_per_hwsku_hostname,
128+
setup_streaming_telemetry): # noqa F811
129+
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
130+
env = GNMIEnvironment(duthost, GNMIEnvironment.TELEMETRY_MODE)
131+
if duthost.is_supervisor_node():
132+
pytest.skip(
133+
"Skipping test as no Ethernet0 frontpanel port on supervisor")
134+
dut_ip = get_mgmt_ipv6(duthost)
135+
cmd = "~/gnmi_get -xpath_target COUNTERS_DB -xpath COUNTERS/Ethernet0 -target_addr \
136+
[%s]:%s -logtostderr -insecure" % (dut_ip, env.gnmi_port)
137+
show_gnmi_out = duthost.shell(cmd)['stdout']
138+
result = str(show_gnmi_out)
139+
inerrors_match = re.search("SAI_PORT_STAT_IF_IN_ERRORS", result)
140+
pytest_assert(inerrors_match is not None,
141+
"SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi output")

tests/telemetry/conftest.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
from tests.common.helpers.assertions import pytest_assert as py_assert
55
from tests.common.errors import RunAnsibleModuleFail
6-
from tests.common.utilities import wait_until, wait_tcp_connection
6+
from tests.common.utilities import wait_until, wait_tcp_connection, get_mgmt_ipv6
77
from tests.common.helpers.gnmi_utils import GNMIEnvironment
8-
from telemetry_utils import get_list_stdout, setup_telemetry_forpyclient, restore_telemetry_forpyclient
8+
from tests.telemetry.telemetry_utils import get_list_stdout, setup_telemetry_forpyclient, restore_telemetry_forpyclient
99

1010

1111
logger = logging.getLogger(__name__)
@@ -79,10 +79,11 @@ def delete_gnmi_config(duthost):
7979

8080

8181
@pytest.fixture(scope="module")
82-
def setup_streaming_telemetry(duthosts, enum_rand_one_per_hwsku_hostname, localhost, ptfhost, gnxi_path):
82+
def setup_streaming_telemetry(request, duthosts, enum_rand_one_per_hwsku_hostname, localhost, ptfhost, gnxi_path):
8383
"""
8484
@summary: Post setting up the streaming telemetry before running the test.
8585
"""
86+
is_ipv6 = request.param
8687
try:
8788
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
8889
has_gnmi_config = check_gnmi_config(duthost)
@@ -106,11 +107,18 @@ def setup_streaming_telemetry(duthosts, enum_rand_one_per_hwsku_hostname, localh
106107

107108
# Wait until the TCP port was opened
108109
dut_ip = duthost.mgmt_ip
110+
if is_ipv6:
111+
dut_ip = get_mgmt_ipv6(duthost)
109112
wait_tcp_connection(localhost, dut_ip, env.gnmi_port, timeout_s=60)
110113

111114
# pyclient should be available on ptfhost. If it was not available, then fail pytest.
112-
file_exists = ptfhost.stat(path=gnxi_path + "gnmi_cli_py/py_gnmicli.py")
113-
py_assert(file_exists["stat"]["exists"] is True)
115+
if is_ipv6:
116+
cmd = "docker cp %s:/usr/sbin/gnmi_get ~/" % (env.gnmi_container)
117+
ret = duthost.shell(cmd)['rc']
118+
py_assert(ret == 0)
119+
else:
120+
file_exists = ptfhost.stat(path=gnxi_path + "gnmi_cli_py/py_gnmicli.py")
121+
py_assert(file_exists["stat"]["exists"] is True)
114122
except RunAnsibleModuleFail as e:
115123
logger.info("Error happens in the setup period of setup_streaming_telemetry, recover the telemetry.")
116124
restore_telemetry_forpyclient(duthost, default_client_auth)

tests/telemetry/test_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def do_init(duthost):
3737
duthost.copy(src="telemetry/validate_yang_events.py", dest="~/")
3838

3939

40+
@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True)
4041
@pytest.mark.disable_loganalyzer
41-
def test_events(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_streaming_telemetry, localhost, gnxi_path):
42+
def test_events(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, setup_streaming_telemetry, gnxi_path):
4243
""" Run series of events inside duthost and validate that output is correct
4344
and conforms to YANG schema
4445
"""

tests/telemetry/test_telemetry.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def test_telemetry_enabledbydefault(duthosts, enum_rand_one_per_hwsku_hostname):
8080
"Telemetry feature is not enabled")
8181

8282

83+
@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True)
8384
def test_telemetry_ouput(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost,
84-
setup_streaming_telemetry, localhost, gnxi_path):
85+
setup_streaming_telemetry, gnxi_path):
8586
"""Run pyclient from ptfdocker and show gnmi server outputself.
8687
"""
8788
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
@@ -102,7 +103,7 @@ def test_telemetry_ouput(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost,
102103
"SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi_output")
103104

104105

105-
def test_osbuild_version(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
106+
def test_osbuild_version(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
106107
""" Test osbuild/version query.
107108
"""
108109
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
@@ -118,7 +119,7 @@ def test_osbuild_version(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, lo
118119
0, "invalid build_version value at {0}".format(result))
119120

120121

121-
def test_sysuptime(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
122+
def test_sysuptime(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
122123
"""
123124
@summary: Run pyclient from ptfdocker and test the dataset 'system uptime' to check
124125
whether the value of 'system uptime' was float number and whether the value was
@@ -167,7 +168,7 @@ def test_sysuptime(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhos
167168
pytest.fail("The value of system uptime was not updated correctly.")
168169

169170

170-
def test_virtualdb_table_streaming(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
171+
def test_virtualdb_table_streaming(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
171172
"""Run pyclient from ptfdocker to stream a virtual-db query multiple times.
172173
"""
173174
logger.info('start virtual db sample streaming testing')
@@ -196,7 +197,7 @@ def invoke_py_cli_from_ptf(ptfhost, cmd, callback):
196197
callback(ret["stdout"])
197198

198199

199-
def test_on_change_updates(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, localhost, gnxi_path):
200+
def test_on_change_updates(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, gnxi_path):
200201
logger.info("Testing on change update notifications")
201202

202203
duthost = duthosts[enum_rand_one_per_hwsku_hostname]

0 commit comments

Comments
 (0)