1
1
import logging
2
2
import pytest
3
3
from tests .common .helpers .assertions import pytest_assert
4
+ from tests .common .utilities import get_inventory_files , get_host_visible_vars
4
5
from .util import get_field_range , get_fields , get_skip_mod_list , get_skip_logical_module_list
5
6
6
7
logger = logging .getLogger ('__name__' )
12
13
CMD_SHOW_CHASSIS_MODULE = "show chassis modules"
13
14
14
15
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
+
15
23
def parse_chassis_module (output , expected_headers ):
16
24
assert len (output ) > 2
17
25
f_ranges = get_field_range (output [1 ])
@@ -33,13 +41,32 @@ def parse_chassis_module(output, expected_headers):
33
41
return result
34
42
35
43
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 ):
37
45
cmd = " " .join ([CMD_SHOW_CHASSIS_MODULE , "status" ])
38
46
logger .info ("verifying output of cli command {}" .format (cmd ))
39
47
duthost = duthosts [enum_rand_one_per_hwsku_hostname ]
40
48
exp_headers = ["Name" , "Description" , "Physical-Slot" , "Oper-Status" , "Admin-Status" ]
41
49
skip_mod_list = get_skip_mod_list (duthost )
42
50
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' ]
43
70
44
71
output = duthost .command (cmd )
45
72
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):
62
89
pytest_assert (res [mod_idx ]['Oper-Status' ] == 'Online' ,
63
90
"Oper-status for slot {} should be Online but it is {}" .format (
64
91
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" )
65
103
66
104
67
105
def test_show_chassis_module_midplane_status (duthosts , enum_rand_one_per_hwsku_hostname ):
0 commit comments