Skip to content

Commit cdf78e3

Browse files
authored
Converting legacy platform tests for a T2 chassis, adding validation of values to tests, and refactor test_sfp into smaller tests (#2965)
Summary: The following modifications are made to some of the legacy platform tests: - conftest.py: - Some of the platform tests run only on a supervisor card for a chassis. So, needed to change rand_one_dut_hostname to enum_dut_supervisor_hostname. However, in a multi-dut testbed that has no supervisor card (like DualTor), we would raise an exception that no supervisor card is present. Instead, we will now just return the first dut in the testbed. - Modified generate_params_supervisor_hostname function for this behavior. - test_xcvr_info_in_db.py: - Use enum_rand_one_per_hwsku_frontend_hostname to run test against frontend node instead of rand_one_dut_hostname that could give us a supervisor card. - test_sfp: - Use enum_rand_one_per_hwsku_frontend_hostname to run test against frontend node instead of rand_one_dut_hostname - Some of the new platforms don't support sfputils. So, added a check based on the presence of file /usr/share/sonic/device/<platform>/plugins/spfutil.py" If the file is not present, then we assume that sfputils is not supported. In this case, we don't do sfputils related steps in test_check_sfp_status_and_configure_sfp test. and skip test_check_sfp_low_power_mode test. - test_show_platform.py: - Use enum_rand_one_per_hwsku_frontend_hostname to run tests against frontend node instead of rand_one_dut_hostname - test_show_platform_summary: - Added validation of fields in 'show platform summary' based on values in the inventory if defined. - hwsku - based on 'hwsku' variable in the inventory - platform - based on 'sonic_hw_platform' variable in the inventory - asic - based on 'asic_type' variable in the inventory - asic count - based on 'num_asics' variable in the inventory - test_show_syseeprom: - Validate values against 'syseeprom_info' dictionary if defined in the inventory - test_show_platform_psustatus: - Validate that atleast one of the PSU's shows status as OK. - test_show_platform_fan: - Validate that atleast one of the fans shows status as OK. Approach What is the motivation for this PR? Need to run the legacy platform tests against a T2 chassis. However, some of the tests would run only on supervisor card, while others would run only on frontend nodes (linecards). So, need to convert these tests to use the enum_* fixtures for dut selection, rather than rand_one_dut_hostname. Also, we need to add some validation of the commands based on some variables that are defined in the inventory file - similar to the new PMON API validation. How did you do it? The following modifications are made to some of the legacy platform tests: conftest.py: Some of the platform tests run only on a supervisor card for a chassis. So, needed to change rand_one_dut_hostname to enum_dut_supervisor_hostname. However, in a multi-dut testbed that has no supervisor card (like DualTor), we would raise an exception that no supervisor card is present. Instead, we will now just return the first dut in the testbed. Modified generate_params_supervisor_hostname function for this behavior. test_xcvr_info_in_db.py: Use enum_rand_one_per_hwsku_frontend_hostname to run test against frontend node instead of rand_one_dut_hostname that could give us a supervisor card. test_sfp: Broke into 3 smaller test for the 3 modules being tested sfpshow sfputil show interface transceiver These tests were added as a directory 'sfp' under platform_tests In these tests: Use enum_rand_one_per_hwsku_frontend_hostname to run test against frontend node instead of rand_one_dut_hostname Added validation of 'sfpshow presence' and 'sfpshow eeprom'. test_show_platform.py: Use enum_rand_one_per_hwsku_frontend_hostname to run tests against frontend node instead of rand_one_dut_hostname test_show_platform_summary: Added validation of fields in 'show platform summary' based on values in the inventory if defined. hwsku - based on 'hwsku' variable in the inventory platform - based on 'sonic_hw_platform' variable in the inventory asic - based on 'asic_type' variable in the inventory asic count - based on 'num_asics' variable in the inventory test_show_syseeprom: Validate values against 'syseeprom_info' dictionary if defined in the inventory test_show_platform_psustatus: Validate that atleast one of the PSU's shows status as OK. test_show_platform_fan: Validate that atleast one of the fans shows status as OK. How did you verify/test it? Validated the modified tests against a chassis and also a pizza box.
1 parent 6b43806 commit cdf78e3

9 files changed

Lines changed: 388 additions & 203 deletions

File tree

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ def generate_params_supervisor_hostname(request):
658658
# Expecting only a single supervisor node
659659
if is_supervisor_node(inv_files, dut):
660660
return [dut]
661-
pytest.fail("Test selected require a supervisor node, " +
662-
"none of the DUTs '{}' in testbed '{}' are a supervisor node".format(duts, tbname))
661+
# If there are no supervisor cards in a multi-dut tesbed, we are dealing with all pizza box in the testbed, pick the first DUT
662+
return [duts[0]]
663663

664664
def generate_param_asic_index(request, dut_indices, param_type):
665665
_, tbinfo = get_tbinfo(request)

tests/platform_tests/cli/test_show_platform.py

Lines changed: 149 additions & 60 deletions
Large diffs are not rendered by default.

tests/platform_tests/sfp/__init__.py

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
import logging
3+
import os
4+
from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer
5+
6+
ans_host = None
7+
8+
9+
def teardown_module():
10+
logging.info("remove script to retrieve port mapping")
11+
file_path = os.path.join('/usr/share/sonic/device', ans_host.facts['platform'], 'plugins/getportmap.py')
12+
ans_host.file(path=file_path, state='absent')
13+
14+
15+
@pytest.fixture(autouse=True)
16+
def disable_analyzer_for_mellanox(duthost):
17+
if duthost.facts["asic_type"] in ["mellanox"]:
18+
loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='sfp_cfg')
19+
loganalyzer.load_common_config()
20+
21+
loganalyzer.ignore_regex.append("kernel.*Eeprom query failed*")
22+
marker = loganalyzer.init()
23+
yield
24+
25+
if duthost.facts["asic_type"] in ["mellanox"]:
26+
loganalyzer.analyze(marker)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
Check SFP status using sfpshow.
3+
4+
This script covers test case 'Check SFP status and configure SFP' in the SONiC platform test plan:
5+
https://github.com/Azure/SONiC/blob/master/doc/pmon/sonic_platform_test_plan.md
6+
"""
7+
8+
import logging
9+
import pytest
10+
11+
from util import parse_eeprom
12+
from util import parse_output
13+
from util import get_dev_conn
14+
15+
cmd_sfp_presence = "sudo sfpshow presence"
16+
cmd_sfp_eeprom = "sudo sfpshow eeprom"
17+
18+
19+
pytestmark = [
20+
pytest.mark.disable_loganalyzer, # disable automatic loganalyzer
21+
pytest.mark.topology('any')
22+
]
23+
24+
25+
def test_check_sfp_presence(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, conn_graph_facts):
26+
"""
27+
@summary: Check SFP presence using 'sfputil show presence'
28+
"""
29+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
30+
global ans_host
31+
ans_host = duthost
32+
portmap, dev_conn = get_dev_conn(duthost, conn_graph_facts, enum_frontend_asic_index)
33+
34+
logging.info("Check output of '{}'".format(cmd_sfp_presence))
35+
sfp_presence = duthost.command(cmd_sfp_presence)
36+
parsed_presence = parse_output(sfp_presence["stdout_lines"][2:])
37+
for intf in dev_conn:
38+
assert intf in parsed_presence, "Interface is not in output of '{}'".format(cmd_sfp_presence)
39+
assert parsed_presence[intf] == "Present", "Interface presence is not 'Present'"
40+
41+
42+
def test_check_sfpshow_eeprom(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, conn_graph_facts):
43+
"""
44+
@summary: Check SFP presence using 'sfputil show presence'
45+
"""
46+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
47+
global ans_host
48+
ans_host = duthost
49+
portmap, dev_conn = get_dev_conn(duthost, conn_graph_facts, enum_frontend_asic_index)
50+
51+
logging.info("Check output of '{}'".format(cmd_sfp_eeprom))
52+
sfp_eeprom = duthost.command(cmd_sfp_eeprom)
53+
parsed_eeprom = parse_eeprom(sfp_eeprom["stdout_lines"])
54+
for intf in dev_conn:
55+
assert intf in parsed_eeprom, "Interface is not in output of 'sfputil show eeprom'"
56+
assert parsed_eeprom[intf] == "SFP EEPROM detected"

0 commit comments

Comments
 (0)