Skip to content

Commit

Permalink
Fix sudo sfputil show error-status on a multiasic platform issue (son…
Browse files Browse the repository at this point in the history
…ic-net#2373)

Fixed "sudo sfputil show error-status" on a multiasic platform issue. Fixes sonic-net/sonic-buildimage#8504
  • Loading branch information
mlok-nokia authored Nov 2, 2022
1 parent e8b1dcd commit 6621120
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,15 +1009,15 @@ def error_status(port, fetch_from_hardware):
if fetch_from_hardware:
output_table = fetch_error_status_from_platform_api(port)
else:
# Connect to STATE_DB
state_db = SonicV2Connector(host='127.0.0.1')
if state_db is not None:
state_db.connect(state_db.STATE_DB)
else:
click.echo("Failed to connect to STATE_DB")
return

output_table = fetch_error_status_from_state_db(port, state_db)
namespaces = multi_asic.get_front_end_namespaces()
for namespace in namespaces:
state_db = SonicV2Connector(use_unix_socket_path=False, namespace=namespace)
if state_db is not None:
state_db.connect(state_db.STATE_DB)
output_table.extend(fetch_error_status_from_state_db(port, state_db))
else:
click.echo("Failed to connect to STATE_DB")
return

click.echo(tabulate(output_table, table_header, tablefmt='simple'))

Expand Down
27 changes: 27 additions & 0 deletions tests/sfputil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,33 @@ def test_show_presence(self, mock_chassis):
"""
assert result.output == expected_output

@patch('sfputil.main.is_port_type_rj45', MagicMock(return_value=False))
@patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1)))
def test_show_error_status(self):
runner = CliRunner()
result = runner.invoke(sfputil.cli.commands['show'].commands['error-status'], [])
assert result.exit_code == 0
expected_output = """Port Error Status
---------- -------------------------------
Ethernet0 Blocking Error|High temperature
Ethernet4 OK
Ethernet8 Unplugged
Ethernet12 Unknown state: 255
Ethernet16 Unplugged
Ethernet28 Unplugged
Ethernet36 Unknown
"""
assert result.output == expected_output

@patch('sfputil.main.SonicV2Connector', MagicMock(return_value=None))
def test_show_error_status_error_case(self):
runner = CliRunner()
result = runner.invoke(sfputil.cli.commands['show'].commands['error-status'], [])
assert result.exit_code == 0
expected_output = """Failed to connect to STATE_DB\n"""
assert result.output == expected_output


@patch('sfputil.main.platform_chassis')
@patch('sfputil.main.logical_port_name_to_physical_port_list', MagicMock(return_value=[1]))
@patch('sfputil.main.platform_sfputil', MagicMock(is_logical_port=MagicMock(return_value=1)))
Expand Down

0 comments on commit 6621120

Please sign in to comment.