Skip to content

Commit

Permalink
new file: ansible/platform_skip_inventory.json
Browse files Browse the repository at this point in the history
 -adding new json file to support fixture in platform tests to skip checks for modules not present in DUT
new file:   tests/platform_tests/cli/test_show_chassis_module.py
  -adding new two new test cases for verifying show chassis-module status and show chassis-module midplane status introduced as part of
   PRs sonic-net/sonic-utilities#1145 and sonic-net/sonic-utilities#1267
tests/platform_tests/conftest.py
   -adding a fixture that skips checking for modules for DUT
  • Loading branch information
rawal01 committed Feb 3, 2021
1 parent 5d9664c commit c9f1bf3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ansible/platform_skip_inventory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dut2": {
"modules": {
"skip": ["FABRIC-CARD0", "LINE-CARD4"]
}
}

}

93 changes: 93 additions & 0 deletions tests/platform_tests/cli/test_show_chassis_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import logging
import re

import pytest
from tests.common.helpers.assertions import pytest_assert

pytestmark = [
pytest.mark.topology('t2')
]

CMD_SHOW_CHASSIS_MODULE = "show chassis-module"


def parse_chassis_module(output, expected_headers):

for ln_id, temp_line in enumerate(output):
if re.findall('----',temp_line):
h_line_id = ln_id - 1
h_line = output[h_line_id]
break

headers = h_line.split()

for header_v in expected_headers:
pytest_assert(header_v in headers, "Missing header {}".format(header_v))

result = {}
num_h = len(headers)
for a_line in output[h_line_id+2:]:
tmp = a_line.split()
mod_idx = tmp[0]
result[mod_idx] = {}
for i in range(1, num_h):
result[mod_idx][headers[i]] = tmp[i]

return result


def test_show_chassis_module_status(duthosts, enum_dut_hostname, skip_module_list):
"""
@summary: Verify output of `show chassis-module status`
"""
cmd = " ".join([CMD_SHOW_CHASSIS_MODULE, "status"])
logging.info("verifying output of cli command {}".format(cmd))
duthost = duthosts[enum_dut_hostname]
exp_headers = ["Name", "Description", "Physical-Slot", "Oper-Status", "Admin-Status"]

output = duthost.command(cmd)
res = parse_chassis_module(output['stdout_lines'], exp_headers)

# by default will assume all modules should be shown online except in skip_module_list
for mod_idx in res.keys():
if mod_idx in skip_module_list:
pytest_assert(res[mod_idx]['Oper-Status'] == 'Empty',
"Oper-status for slot {} should be Empty but it is {}".format(
mod_idx, res[mod_idx]['Oper-Status']))
else:
pytest_assert(res[mod_idx]['Oper-Status'] == 'Online',
"Oper-status for slot {} should be Online but it is {}".format(
mod_idx, res[mod_idx]['Oper-Status']))


def test_show_chassis_module_midplane_status(duthosts, enum_dut_hostname, skip_module_list):
"""
@summary: Verify output of `show chassis-module midplane-status`
"""
cmd = " ".join([CMD_SHOW_CHASSIS_MODULE, "midplane-status"])
logging.info("verifying output of cli command {}".format(cmd))
expected_headers = ["Name", "IP-Address", "Reachability"]

duthost = duthosts[enum_dut_hostname]
output = duthost.command(cmd)
res_mid_status = parse_chassis_module(output['stdout_lines'], expected_headers)

if duthost.is_supervisor_node():
logging.info("supervisor node is {}".format(duthost.hostname))
# on supervisor check all applicable line cards are reachable except any modules from skip_module_list
for mod_idx in res_mid_status:
mod_mid_status = res_mid_status[mod_idx]['Reachability']
if mod_idx in skip_module_list:
pytest_assert(res_mid_status[mod_idx]['Reachability'] == "False",
"reachability of line card {} expected false but is {}".format(mod_idx, mod_mid_status))
else:
pytest_assert(mod_mid_status == "True",
"midplane reachability of line card {} expected true but is {}".format(mod_idx,
mod_mid_status))
# for line card only supervisor is shown so do not need to check skip
elif duthost.is_frontend_node():
for mod_idx in res_mid_status:
mod_mid_status = res_mid_status[mod_idx]['Reachability']
pytest_assert(mod_mid_status == "True", "reachability should be true for {}".format(mod_idx))
else:
pytest.skip("test is valid on supervisor or fronend node of chassis")
17 changes: 17 additions & 0 deletions tests/platform_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
import json
import os

from tests.common.fixtures.advanced_reboot import get_advanced_reboot
from .args.advanced_reboot_args import add_advanced_reboot_args
Expand All @@ -15,6 +17,21 @@ def skip_on_simx(duthosts, rand_one_dut_hostname):
pytest.skip('skipped on this platform: {}'.format(platform))


@pytest.fixture(scope="module")
def skip_module_list(enum_dut_hostname):
"""
Return a list of modules which are not present to skip in test based on dut
"""
skip_list = []
f_path = os.path.join(os.path.dirname(__file__), "../../ansible/platform_skip_inventory.json")
platform_inv = open(f_path, "r")
json_val = json.load(platform_inv)

if enum_dut_hostname in json_val.keys():
skip_list = json_val[enum_dut_hostname]['modules']['skip']
return skip_list


@pytest.fixture()
def bring_up_dut_interfaces(request, duthosts, rand_one_dut_hostname, tbinfo):
"""
Expand Down

0 comments on commit c9f1bf3

Please sign in to comment.