From 32823686aa281b9e51180d77097be370039532ed Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Mon, 7 Jun 2021 09:25:41 +0000 Subject: [PATCH 1/4] 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 --- tests/common/helpers/platform_api/sfp.py | 4 ++++ tests/platform_tests/api/test_sfp.py | 8 ++++++++ tests/platform_tests/sfp/test_sfputil.py | 25 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+) 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..11da5ffa96 100644 --- a/tests/platform_tests/api/test_sfp.py +++ b/tests/platform_tests/api/test_sfp.py @@ -181,6 +181,14 @@ def test_get_presence(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos self.expect(presence is True, "Transceiver {} is not present".format(i)) self.assert_expectations() + def test_get_error_description(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): + 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 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_get_model(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for i in self.candidate_sfp: model = sfp.get_model(platform_api_conn, i) diff --git a/tests/platform_tests/sfp/test_sfputil.py b/tests/platform_tests/sfp/test_sfputil.py index b8e2e68eaa..b5e33c1c68 100644 --- a/tests/platform_tests/sfp/test_sfputil.py +++ b/tests/platform_tests/sfp/test_sfputil.py @@ -43,6 +43,31 @@ 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.fixture(params=["sudo sfputil show error-status", "sudo sfputil show error-status --fetch-from-hardware"]) +def cmd_sfp_error_status(request): + """ + @summary: Return the command for fetching sfp error status + """ + return request.param + + +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' + """ + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] + global ans_host + ans_host = duthost + 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) + 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' From 79d19851981389bdf959b2db70c9930e4e30a5f3 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Wed, 9 Jun 2021 10:13:17 +0000 Subject: [PATCH 2/4] Address comments - Remove unused variable - Simplify the fixture of the command Signed-off-by: Stephen Sun --- tests/platform_tests/sfp/test_sfputil.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/platform_tests/sfp/test_sfputil.py b/tests/platform_tests/sfp/test_sfputil.py index b5e33c1c68..77a32a1b85 100644 --- a/tests/platform_tests/sfp/test_sfputil.py +++ b/tests/platform_tests/sfp/test_sfputil.py @@ -43,21 +43,12 @@ 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.fixture(params=["sudo sfputil show error-status", "sudo sfputil show error-status --fetch-from-hardware"]) -def cmd_sfp_error_status(request): - """ - @summary: Return the command for fetching sfp error status - """ - return request.param - - +@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' """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - global ans_host - ans_host = duthost portmap, dev_conn = get_dev_conn(duthost, conn_graph_facts, enum_frontend_asic_index) logging.info("Check output of '{}'".format(cmd_sfp_error_status)) From 94bff70751f7d899553948418fba62d55e620273 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Tue, 29 Jun 2021 01:52:33 +0000 Subject: [PATCH 3/4] Address the comment: move test_sfp_error_status to the SFP section Signed-off-by: Stephen Sun --- tests/platform_tests/api/test_sfp.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/platform_tests/api/test_sfp.py b/tests/platform_tests/api/test_sfp.py index 11da5ffa96..3d41cc8cca 100644 --- a/tests/platform_tests/api/test_sfp.py +++ b/tests/platform_tests/api/test_sfp.py @@ -181,14 +181,6 @@ def test_get_presence(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos self.expect(presence is True, "Transceiver {} is not present".format(i)) self.assert_expectations() - def test_get_error_description(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): - 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 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_get_model(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): for i in self.candidate_sfp: model = sfp.get_model(platform_api_conn, i) @@ -485,6 +477,14 @@ 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): + 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 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: From 0a3e7812d914c0ac2f7cfd988f62da5f5f7f97a4 Mon Sep 17 00:00:00 2001 From: Stephen Sun Date: Wed, 30 Jun 2021 06:41:38 +0000 Subject: [PATCH 4/4] Fix review comments - Skip the test if error status isn't supported - Skip the test on versions 202012, 201911, 201811 - Add comments Signed-off-by: Stephen Sun --- tests/platform_tests/api/test_sfp.py | 6 ++++++ tests/platform_tests/sfp/test_sfputil.py | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/platform_tests/api/test_sfp.py b/tests/platform_tests/api/test_sfp.py index 3d41cc8cca..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 @@ -478,9 +479,14 @@ def test_power_override(self, duthosts, enum_rand_one_per_hwsku_hostname, localh 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() diff --git a/tests/platform_tests/sfp/test_sfputil.py b/tests/platform_tests/sfp/test_sfputil.py index 77a32a1b85..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" @@ -46,13 +47,20 @@ def test_check_sfputil_presence(duthosts, enum_rand_one_per_hwsku_frontend_hostn @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' + @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)