diff --git a/tests/common/helpers/platform_api/sfp.py b/tests/common/helpers/platform_api/sfp.py index a5bf42624c..66d40a948f 100644 --- a/tests/common/helpers/platform_api/sfp.py +++ b/tests/common/helpers/platform_api/sfp.py @@ -31,6 +31,10 @@ def get_presence(conn, index): return sfp_api(conn, index, 'get_presence') +def get_error_description(conn, index): + return sfp_api(conn, index, 'get_error_description') + + def get_model(conn, index): return sfp_api(conn, index, 'get_model') diff --git a/tests/platform_tests/api/test_sfp.py b/tests/platform_tests/api/test_sfp.py index f21d1f77a1..585dc0dbb8 100644 --- a/tests/platform_tests/api/test_sfp.py +++ b/tests/platform_tests/api/test_sfp.py @@ -6,6 +6,7 @@ from tests.common.helpers.assertions import pytest_assert from tests.common.helpers.platform_api import chassis, sfp +from tests.common.utilities import skip_version from platform_api_test_base import PlatformApiTestBase @@ -477,6 +478,19 @@ def test_power_override(self, duthosts, enum_rand_one_per_hwsku_hostname, localh self.expect(power_override is False, "Transceiver {} power override data is incorrect".format(i)) self.assert_expectations() + def test_get_error_description(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): + """This function tests get_error_description() API (supported on 202106 and above)""" + skip_version(duthosts[enum_rand_one_per_hwsku_hostname], ["201811", "201911", "202012"]) + + for i in self.candidate_sfp: + error_description = sfp.get_error_description(platform_api_conn, i) + if self.expect(error_description is not None, "Unable to retrieve transceiver {} error description".format(i)): + if "Not implemented" in error_description: + pytest.skip("get_error_description isn't implemented. Skip the test") + if self.expect(isinstance(error_description, str) or isinstance(error_description, unicode), "Transceiver {} error description appears incorrect".format(i)): + self.expect(error_description == "OK", "Transceiver {} is not present".format(i)) + self.assert_expectations() + def test_thermals(self, platform_api_conn): for sfp_id in self.candidate_sfp: try: diff --git a/tests/platform_tests/sfp/test_sfputil.py b/tests/platform_tests/sfp/test_sfputil.py index b8e2e68eaa..cb2a6b69f4 100644 --- a/tests/platform_tests/sfp/test_sfputil.py +++ b/tests/platform_tests/sfp/test_sfputil.py @@ -14,6 +14,7 @@ from util import parse_eeprom from util import parse_output from util import get_dev_conn +from tests.common.utilities import skip_version cmd_sfp_presence = "sudo sfputil show presence" cmd_sfp_eeprom = "sudo sfputil show eeprom" @@ -43,6 +44,29 @@ def test_check_sfputil_presence(duthosts, enum_rand_one_per_hwsku_frontend_hostn assert intf in parsed_presence, "Interface is not in output of '{}'".format(cmd_sfp_presence) assert parsed_presence[intf] == "Present", "Interface presence is not 'Present'" +@pytest.mark.parametrize("cmd_sfp_error_status", ["sudo sfputil show error-status", "sudo sfputil show error-status --fetch-from-hardware"]) +def test_check_sfputil_error_status(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, conn_graph_facts, cmd_sfp_error_status): + """ + @summary: Check SFP error status using 'sfputil show error-status' and 'sfputil show error-status --fetch-from-hardware' + This feature is supported on 202106 and above + + @param: cmd_sfp_error_status: fixture representing the command used to test + """ + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] + skip_version(duthost, ["201811", "201911", "202012"]) + portmap, dev_conn = get_dev_conn(duthost, conn_graph_facts, enum_frontend_asic_index) + + logging.info("Check output of '{}'".format(cmd_sfp_error_status)) + sfp_error_status = duthost.command(cmd_sfp_error_status) + for line in sfp_error_status["stdout_lines"][2:]: + if "Not implemented" in line: + pytest.skip("Skip test as error status isn't supported") + parsed_presence = parse_output(sfp_error_status["stdout_lines"][2:]) + for intf in dev_conn: + assert intf in parsed_presence, "Interface is not in output of '{}'".format(cmd_sfp_presence) + assert parsed_presence[intf] == "OK", "Interface error status is not 'OK'" + + def test_check_sfputil_eeprom(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, conn_graph_facts): """ @summary: Check SFP presence using 'sfputil show presence'