Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sfputil/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def loopback(port_name, loopback_mode, enable):
lane_mask = get_subport_lane_mask(int(subport), lane_count)

try:
if not api.get_diag_page_support():
click.echo(f"{port_name}: The module does not support diagnostic pages required for loopback configuration")
click.echo(f"{port_name}: {enable} {loopback_mode} loopback failed")
sys.exit(EXIT_FAIL)
status = api.set_loopback_mode(loopback_mode, lane_mask=lane_mask, enable=(enable == 'enable'))
except AttributeError:
click.echo(f"{port_name}: Set loopback mode is not applicable for this module")
Expand Down
10 changes: 10 additions & 0 deletions tests/sfputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@ def test_debug_loopback(self, mock_sonic_v2_connector, mock_config_db_connector,
mock_state_db = MagicMock()
mock_state_db.get.return_value = 1
mock_sonic_v2_connector.return_value = mock_state_db
mock_api.get_diag_page_support.return_value = True
result = runner.invoke(sfputil.cli.commands['debug'].commands['loopback'],
["Ethernet0", "host-side-input", "enable"])
assert result.output == 'Ethernet0: enable host-side-input loopback\n'
Expand All @@ -1794,6 +1795,15 @@ def test_debug_loopback(self, mock_sonic_v2_connector, mock_config_db_connector,
assert result.output == 'Ethernet0: enable media-side-input loopback\n'
assert result.exit_code != ERROR_NOT_IMPLEMENTED

mock_api.get_diag_page_support.return_value = False
result = runner.invoke(sfputil.cli.commands['debug'].commands['loopback'],
["Ethernet0", "media-side-output", "enable"])
assert result.output == (
'Ethernet0: The module does not support diagnostic pages required for loopback configuration\n'
'Ethernet0: enable media-side-output loopback failed\n')
assert result.exit_code == EXIT_FAIL

mock_api.get_diag_page_support.return_value = True
mock_api.set_loopback_mode.return_value = False
result = runner.invoke(sfputil.cli.commands['debug'].commands['loopback'],
["Ethernet0", "media-side-output", "enable"])
Expand Down
Loading