Skip to content

Commit

Permalink
[Mellanox] get_error_description should return Not supported for modu…
Browse files Browse the repository at this point in the history
…les that does not support this API (sonic-net#21196)

- Why I did it
Not all xcvr API support get_error_description, for example sff8636. For those API types, get_error_description should return "Not supported".

- How I did it
get_error_description should return "Not supported".

- How to verify it
Manual test
unit test
  • Loading branch information
Junchao-Mellanox authored Jan 23, 2025
1 parent d3d65e6 commit 9b9da85
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_error_info_from_sdk_error_type(self):
Returns:
tuple: (error state, error description)
"""
error_type = utils.read_int_from_file(f'/sys/module/sx_core/asic0/module{self.sdk_index}/temperature/statuserror', default=-1)
error_type = utils.read_int_from_file(f'/sys/module/sx_core/asic0/module{self.sdk_index}/statuserror', default=-1)
sfp_state_bits = NvidiaSFPCommon.SDK_ERRORS_TO_ERROR_BITS.get(error_type)
if sfp_state_bits is None:
logger.log_error(f"Unrecognized error {error_type} detected on SFP {self.sdk_index}")
Expand Down Expand Up @@ -678,7 +678,9 @@ def get_error_description(self):
if self.is_sw_control():
api = self.get_xcvr_api()
return api.get_error_description() if api else None
except:
except NotImplementedError:
return 'Not supported'
except Exception:
return self.SFP_STATUS_INITIALIZING

oper_status, error_code = self._get_module_info(self.sdk_index)
Expand Down
4 changes: 4 additions & 0 deletions platform/mellanox/mlnx-platform-api/tests/test_sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def test_sfp_get_error_status(self, mock_get_error_code, mock_control):
mock_control.side_effect = RuntimeError('')
description = sfp.get_error_description()
assert description == 'Initializing'

mock_control.side_effect = NotImplementedError('')
description = sfp.get_error_description()
assert description == 'Not supported'

@mock.patch('sonic_platform.sfp.SFP._get_page_and_page_offset')
@mock.patch('sonic_platform.sfp.SFP._is_write_protected')
Expand Down

0 comments on commit 9b9da85

Please sign in to comment.