Skip to content

Commit

Permalink
[Mellanox] Provide dummy implementation for get_rx_los and get_tx_fau…
Browse files Browse the repository at this point in the history
…lt (#12231)

- Why I did it
get_rx_los and get_tx_fault is not supported via the exisitng interface used, need provide dummy implementation for them.
NOTE: in later releases we will get them back via different interface.

- How I did it
Return False * lane_num for get_rx_los and get_tx_fault

- How to verify it
Added unit test
  • Loading branch information
Junchao-Mellanox authored and yxieca committed Oct 3, 2022
1 parent c6bcf24 commit bca54e1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
32 changes: 32 additions & 0 deletions platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,38 @@ def get_error_description(self):
error_description = "Unknow SFP module status ({})".format(oper_status)
return error_description

def get_rx_los(self):
"""Accessing rx los is not supproted, return all False
Returns:
list: [False] * channels
"""
api = self.get_xcvr_api()
return [False] * api.NUM_CHANNELS if api else None

def get_tx_fault(self):
"""Accessing tx fault is not supproted, return all False
Returns:
list: [False] * channels
"""
api = self.get_xcvr_api()
return [False] * api.NUM_CHANNELS if api else None

def get_xcvr_api(self):
"""
Retrieves the XcvrApi associated with this SFP
Returns:
An object derived from XcvrApi that corresponds to the SFP
"""
if self._xcvr_api is None:
self.refresh_xcvr_api()
if self._xcvr_api is not None:
self._xcvr_api.get_rx_los = self.get_rx_los
self._xcvr_api.get_tx_fault = self.get_tx_fault
return self._xcvr_api


class RJ45Port(NvidiaSFPCommon):
"""class derived from SFP, representing RJ45 ports"""
Expand Down
14 changes: 14 additions & 0 deletions platform/mellanox/mlnx-platform-api/tests/test_sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,17 @@ def test_is_port_admin_status_up(self, mock_port_status):

mock_port_status.return_value = (0, False)
assert not SFP.is_port_admin_status_up(None, None)

@mock.patch('sonic_platform.sfp.SFP.get_xcvr_api')
def test_dummy_apis(self, mock_get_xcvr_api):
mock_api = mock.MagicMock()
mock_api.NUM_CHANNELS = 4
mock_get_xcvr_api.return_value = mock_api

sfp = SFP(0)
assert sfp.get_rx_los() == [False] * 4
assert sfp.get_tx_fault() == [False] * 4

mock_get_xcvr_api.return_value = None
assert sfp.get_rx_los() is None
assert sfp.get_tx_fault() is None

0 comments on commit bca54e1

Please sign in to comment.