Skip to content

Commit 478de97

Browse files
authored
Enhance test_show_chassis_modules_status to check expected physical s… (sonic-net#17193)
* Enhance test_show_chassis_modules_status to check expected physical slot numbers based on Inventory Truth
1 parent ffc0a41 commit 478de97

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/platform_tests/cli/test_show_chassis_module.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import pytest
33
from tests.common.helpers.assertions import pytest_assert
4+
from tests.common.utilities import get_inventory_files, get_host_visible_vars
45
from .util import get_field_range, get_fields, get_skip_mod_list, get_skip_logical_module_list
56

67
logger = logging.getLogger('__name__')
@@ -12,6 +13,13 @@
1213
CMD_SHOW_CHASSIS_MODULE = "show chassis modules"
1314

1415

16+
@pytest.fixture(scope='module')
17+
def dut_vars(duthosts, enum_rand_one_per_hwsku_hostname, request):
18+
inv_files = get_inventory_files(request)
19+
dut_vars = get_host_visible_vars(inv_files, enum_rand_one_per_hwsku_hostname)
20+
yield dut_vars
21+
22+
1523
def parse_chassis_module(output, expected_headers):
1624
assert len(output) > 2
1725
f_ranges = get_field_range(output[1])
@@ -33,13 +41,32 @@ def parse_chassis_module(output, expected_headers):
3341
return result
3442

3543

36-
def test_show_chassis_module_status(duthosts, enum_rand_one_per_hwsku_hostname):
44+
def test_show_chassis_module_status(duthosts, enum_rand_one_per_hwsku_hostname, dut_vars):
3745
cmd = " ".join([CMD_SHOW_CHASSIS_MODULE, "status"])
3846
logger.info("verifying output of cli command {}".format(cmd))
3947
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
4048
exp_headers = ["Name", "Description", "Physical-Slot", "Oper-Status", "Admin-Status"]
4149
skip_mod_list = get_skip_mod_list(duthost)
4250
skip_logical_lc_list = get_skip_logical_module_list(duthost)
51+
"""
52+
Gather expected module slot data from a inventory file if 'module_slot_info' is defined in the inventory
53+
# Sample inventory with module_slot_info:
54+
str-sonic-chassis-01-sup:
55+
ansible_host: 10.251.0.188
56+
model: SOME-VENDOR-MODEL
57+
serial: BADC0FFEE123
58+
base_mac: 38:8a:29:13:45:67
59+
module_slot_info:
60+
"FABRIC-CARD0": "1"
61+
"FABRIC-CARD3": "3"
62+
"FABRIC-CARD4": "4"
63+
"LINE-CARD1": "2"
64+
"LINE-CARD3": "4"
65+
"SUPERVISOR0": "Y"
66+
"""
67+
exp_module_slot_info = {}
68+
if 'module_slot_info' in dut_vars:
69+
exp_module_slot_info = dut_vars['module_slot_info']
4370

4471
output = duthost.command(cmd)
4572
res = parse_chassis_module(output['stdout_lines'], exp_headers)
@@ -62,6 +89,17 @@ def test_show_chassis_module_status(duthosts, enum_rand_one_per_hwsku_hostname):
6289
pytest_assert(res[mod_idx]['Oper-Status'] == 'Online',
6390
"Oper-status for slot {} should be Online but it is {}".format(
6491
mod_idx, res[mod_idx]['Oper-Status']))
92+
# If inventory contains physical slot info, perform expected slot number check
93+
if exp_module_slot_info:
94+
pytest_assert(mod_idx in exp_module_slot_info,
95+
"Module {} is expected to be present but it is missing".format(
96+
mod_idx))
97+
pytest_assert(res[mod_idx]['Physical-Slot'] == exp_module_slot_info[mod_idx],
98+
"Module {} expected slot {} not matching show output {}".format(
99+
mod_idx, exp_module_slot_info[mod_idx], res[mod_idx]['Physical-Slot']))
100+
else:
101+
# In case Inventory file does not have the slot info, just log it but no need to fail the test
102+
logger.info("Inventory file has no record of module_slot_info")
65103

66104

67105
def test_show_chassis_module_midplane_status(duthosts, enum_rand_one_per_hwsku_hostname):

0 commit comments

Comments
 (0)