Skip to content

Commit 942a548

Browse files
committed
Restore IPv6 support for GNMI tests except test_gnmi_auth
This partially reverts the revert commit 16c3a2f, restoring IPv6 support for most GNMI tests while keeping test_gnmi_auth without IPv6 support to avoid authentication issues. Changes: - Make duthost_mgmt_ip parameter optional in gnmi_capabilities() for backward compatibility - Restore IPv6 support in test_gnmi.py and test_mimic_hwproxy_cert_rotation.py - Keep test_gnmi_auth.py without IPv6 support to avoid breaking authentication
1 parent 16c3a2f commit 942a548

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

tests/common/helpers/gnmi_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,17 @@ def verify_tcp_port(localhost, ip, port):
319319
logger.info("TCP: " + res['stdout'] + res['stderr'])
320320

321321

322-
def gnmi_capabilities(duthost, localhost):
322+
def gnmi_capabilities(duthost, localhost, duthost_mgmt_ip=None):
323323
env = GNMIEnvironment(duthost, GNMIEnvironment.GNMI_MODE)
324-
ip = duthost.mgmt_ip
324+
if duthost_mgmt_ip:
325+
ip = duthost_mgmt_ip['mgmt_ip']
326+
addr = f"[{ip}]" if duthost_mgmt_ip['version'] == 'v6' else f"{ip}"
327+
else:
328+
ip = duthost.mgmt_ip
329+
addr = ip
325330
port = env.gnmi_port
326331
# Run gnmi_cli in gnmi container as workaround
327-
cmd = "docker exec %s gnmi_cli -client_types=gnmi -a %s:%s " % (env.gnmi_container, ip, port)
332+
cmd = "docker exec %s gnmi_cli -client_types=gnmi -a %s:%s " % (env.gnmi_container, addr, port)
328333
cmd += "-client_crt /etc/sonic/telemetry/gnmiclient.crt "
329334
cmd += "-client_key /etc/sonic/telemetry/gnmiclient.key "
330335
cmd += "-ca_crt /etc/sonic/telemetry/gnmiCA.pem "

tests/gnmi/test_gnmi.py

100644100755
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from .helper import gnmi_set, dump_gnmi_log
77
from tests.common.utilities import wait_until
88
from tests.common.plugins.allure_wrapper import allure_step_wrapper as allure
9+
from tests.common.fixtures.duthost_utils import duthost_mgmt_ip # noqa: F401
10+
911

1012
logger = logging.getLogger(__name__)
1113
allure.logger = logger
@@ -16,12 +18,12 @@
1618
]
1719

1820

19-
def test_gnmi_capabilities(duthosts, rand_one_dut_hostname, localhost):
21+
def test_gnmi_capabilities(duthosts, rand_one_dut_hostname, localhost, duthost_mgmt_ip): # noqa: F811
2022
'''
2123
Verify GNMI capabilities
2224
'''
2325
duthost = duthosts[rand_one_dut_hostname]
24-
ret, msg = gnmi_capabilities(duthost, localhost)
26+
ret, msg = gnmi_capabilities(duthost, localhost, duthost_mgmt_ip)
2527
assert ret == 0, (
2628
"GNMI capabilities command failed (non-zero return code).\n"
2729
"- Error message: {}"
@@ -38,7 +40,7 @@ def test_gnmi_capabilities(duthosts, rand_one_dut_hostname, localhost):
3840
).format(msg)
3941

4042

41-
def test_gnmi_capabilities_authenticate(duthosts, rand_one_dut_hostname, localhost):
43+
def test_gnmi_capabilities_authenticate(duthosts, rand_one_dut_hostname, localhost, duthost_mgmt_ip): # noqa: F811
4244
'''
4345
Verify GNMI capabilities with different roles
4446
'''
@@ -47,7 +49,7 @@ def test_gnmi_capabilities_authenticate(duthosts, rand_one_dut_hostname, localho
4749
with allure.step("Verify GNMI capabilities with noaccess role"):
4850
role = "gnmi_noaccess"
4951
add_gnmi_client_common_name(duthost, "test.client.gnmi.sonic", role)
50-
ret, msg = gnmi_capabilities(duthost, localhost)
52+
ret, msg = gnmi_capabilities(duthost, localhost, duthost_mgmt_ip)
5153
assert ret != 0, (
5254
"GNMI capabilities authenticate with noaccess role command unexpectedly succeeded "
5355
"(zero return code) for a client with noaccess role.\n"
@@ -61,7 +63,7 @@ def test_gnmi_capabilities_authenticate(duthosts, rand_one_dut_hostname, localho
6163
with allure.step("Verify GNMI capabilities with readonly role"):
6264
role = "gnmi_readonly"
6365
add_gnmi_client_common_name(duthost, "test.client.gnmi.sonic", role)
64-
ret, msg = gnmi_capabilities(duthost, localhost)
66+
ret, msg = gnmi_capabilities(duthost, localhost, duthost_mgmt_ip)
6567
assert ret == 0, (
6668
"GNMI capabilities authenticate readonly command failed (non-zero return code).\n"
6769
"- Error message: {}"
@@ -78,7 +80,7 @@ def test_gnmi_capabilities_authenticate(duthosts, rand_one_dut_hostname, localho
7880
with allure.step("Verify GNMI capabilities with readwrite role"):
7981
role = "gnmi_readwrite"
8082
add_gnmi_client_common_name(duthost, "test.client.gnmi.sonic", role)
81-
ret, msg = gnmi_capabilities(duthost, localhost)
83+
ret, msg = gnmi_capabilities(duthost, localhost, duthost_mgmt_ip)
8284
assert ret == 0, (
8385
"GNMI capabilities authenticate readwrite role command failed (non-zero return code).\n"
8486
"- Error message: {}"
@@ -95,7 +97,7 @@ def test_gnmi_capabilities_authenticate(duthosts, rand_one_dut_hostname, localho
9597
with allure.step("Verify GNMI capabilities with empty role"):
9698
role = ""
9799
add_gnmi_client_common_name(duthost, "test.client.gnmi.sonic", role)
98-
ret, msg = gnmi_capabilities(duthost, localhost)
100+
ret, msg = gnmi_capabilities(duthost, localhost, duthost_mgmt_ip)
99101
assert ret == 0, (
100102
"GNMI capabilities authenticate with empty role command failed (non-zero return code).\n"
101103
"- Error message: {}"

tests/gnmi/test_mimic_hwproxy_cert_rotation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from tests.common.utilities import wait_until
77
from tests.common.helpers.gnmi_utils import GNMIEnvironment, gnmi_capabilities
88
from tests.common.utilities import get_image_type
9+
from tests.common.fixtures.duthost_utils import duthost_mgmt_ip # noqa: F401
910

1011

1112
logger = logging.getLogger(__name__)
@@ -29,7 +30,8 @@ def check_telemetry_status(duthost):
2930
return "RUNNING" in output['stdout']
3031

3132

32-
def test_mimic_hwproxy_cert_rotation(duthosts, rand_one_dut_hostname, localhost, ptfhost):
33+
def test_mimic_hwproxy_cert_rotation(duthosts, rand_one_dut_hostname, localhost, ptfhost,
34+
duthost_mgmt_ip): # noqa: F811
3335
duthost = duthosts[rand_one_dut_hostname]
3436

3537
# Use bash -c to run the pipeline properly
@@ -87,7 +89,7 @@ def test_mimic_hwproxy_cert_rotation(duthosts, rand_one_dut_hostname, localhost,
8789
enable_feature = 'sudo config feature state gnmi enabled'
8890
duthost.command(enable_feature, module_ignore_errors=True)
8991
assert wait_until(60, 3, 0, check_gnmi_status, duthost), "GNMI service failed to start"
90-
ret, msg = gnmi_capabilities(duthost, localhost)
92+
ret, msg = gnmi_capabilities(duthost, localhost, duthost_mgmt_ip)
9193
assert ret == 0, msg
9294
assert "sonic-db" in msg, msg
9395
assert "JSON_IETF" in msg, msg

0 commit comments

Comments
 (0)