Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] Provide dummy implementation for get_rx_los and get_tx_fault #151

Closed
wants to merge 3 commits into from
Closed
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
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 @@ -757,6 +757,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