Skip to content

Commit

Permalink
[platform/sfp] Add test cases for SFP error status (#3648)
Browse files Browse the repository at this point in the history
Add test cases for SFP error status
- Add test cases for sfputil show error-status
- Add platform test for SFP.get_error_description()

Signed-off-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
stephenxs authored Jun 30, 2021
1 parent c394e96 commit 8305c26
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/common/helpers/platform_api/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
14 changes: 14 additions & 0 deletions tests/platform_tests/api/test_sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions tests/platform_tests/sfp/test_sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 8305c26

Please sign in to comment.