Skip to content

Commit d86b2b6

Browse files
g[sfputil debug] Fix issue: do not check output status when CMIS version is lower than 5.0 (#3938)
1 parent 252a643 commit d86b2b6

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

sfputil/debug.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ def set_output(port_name, enable, direction):
9393

9494
subport = get_subport(port_name)
9595

96+
if hasattr(api, 'get_cmis_rev'):
97+
cmis_rev = api.get_cmis_rev()
98+
if cmis_rev is None:
99+
click.echo(f"{port_name}: CMIS revision not available for subport {subport}")
100+
sys.exit(EXIT_FAIL)
101+
102+
# OutputStatusRx and OutputStatusTx are supported from CMIS 5.0
103+
if float(cmis_rev) < 5.0:
104+
click.echo(
105+
f"{port_name}: This functionality is not supported"
106+
f" with CMIS version {cmis_rev}, requires CMIS 5.0 and above"
107+
)
108+
sys.exit(EXIT_FAIL)
109+
96110
try:
97111
if direction == "tx":
98112
lane_count = get_media_lane_count(port_name)

tests/sfputil_test.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,23 +1822,29 @@ def test_debug_loopback(self, mock_sonic_v2_connector, mock_config_db_connector,
18221822
assert result.exit_code == EXIT_FAIL
18231823

18241824
@pytest.mark.parametrize(
1825-
"direction, lane_count, enable, disable_func_result, output_dict, expected_echo, expected_exit",
1825+
"direction, lane_count, enable, disable_func_result, cmis_version, output_dict, expected_echo, expected_exit",
18261826
[
18271827
# TX disable success
18281828
(
1829-
"tx", 2, "disable", True, {"TxOutputStatus1": False, "TxOutputStatus2": False},
1829+
"tx", 2, "disable", True, "5.3", {"TxOutputStatus1": False, "TxOutputStatus2": False},
18301830
"TX output disabled", None
18311831
),
18321832
# RX enable success
1833-
("rx", 1, "enable", True, {"RxOutputStatus1": True}, "RX output enabled", None),
1833+
("rx", 1, "enable", True, "5.0", {"RxOutputStatus1": True}, "RX output enabled", None),
18341834
# TX disable fails to disable
1835-
("tx", 1, "disable", True, {"TxOutputStatus1": True}, "TX output on lane 1 is still enabled", SystemExit),
1835+
(
1836+
"tx", 1, "disable", True, "5.0", {"TxOutputStatus1": True},
1837+
"TX output on lane 1 is still enabled", SystemExit
1838+
),
18361839
# RX enable fails to enable
1837-
("rx", 1, "enable", True, {"RxOutputStatus1": False}, "RX output on lane 1 is still disabled", SystemExit),
1838-
# TX disable_func returns False
1839-
("tx", 1, "disable", False, {}, "TX disable failed", SystemExit),
1840-
# RX output_dict is None
1841-
("rx", 1, "disable", True, None, "RX output status not available", SystemExit),
1840+
(
1841+
"rx", 1, "enable", True, "5.0", {"RxOutputStatus1": False},
1842+
"RX output on lane 1 is still disabled", SystemExit
1843+
),
1844+
# CMIS version is None
1845+
("tx", 1, "disable", False, None, {}, "CMIS revision not available", SystemExit),
1846+
# CMIS version is below 5.0
1847+
("rx", 1, "disable", True, "4.0", None, "This functionality is not supported", SystemExit),
18421848
]
18431849
)
18441850
@patch("sfputil.debug.get_sfp_object")
@@ -1857,6 +1863,7 @@ def test_set_output_cli(
18571863
lane_count,
18581864
enable,
18591865
disable_func_result,
1866+
cmis_version,
18601867
output_dict,
18611868
expected_echo,
18621869
expected_exit
@@ -1875,6 +1882,7 @@ def test_set_output_cli(
18751882
# Mock SFP and API
18761883
mock_sfp = MagicMock()
18771884
mock_api = MagicMock()
1885+
mock_api.get_cmis_rev.return_value = cmis_version
18781886
if direction == "tx":
18791887
mock_sfp.tx_disable_channel.return_value = disable_func_result
18801888
mock_api.get_tx_output_status.return_value = output_dict

0 commit comments

Comments
 (0)