Skip to content

Commit 1d69f09

Browse files
[Mellanox] Provide dummy implementation for get_rx_los and get_tx_fault (sonic-net#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
1 parent 5510d9c commit 1d69f09

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,38 @@ def get_error_description(self):
755755
error_description = "Unknow SFP module status ({})".format(oper_status)
756756
return error_description
757757

758+
def get_rx_los(self):
759+
"""Accessing rx los is not supproted, return all False
760+
761+
Returns:
762+
list: [False] * channels
763+
"""
764+
api = self.get_xcvr_api()
765+
return [False] * api.NUM_CHANNELS if api else None
766+
767+
def get_tx_fault(self):
768+
"""Accessing tx fault is not supproted, return all False
769+
770+
Returns:
771+
list: [False] * channels
772+
"""
773+
api = self.get_xcvr_api()
774+
return [False] * api.NUM_CHANNELS if api else None
775+
776+
def get_xcvr_api(self):
777+
"""
778+
Retrieves the XcvrApi associated with this SFP
779+
780+
Returns:
781+
An object derived from XcvrApi that corresponds to the SFP
782+
"""
783+
if self._xcvr_api is None:
784+
self.refresh_xcvr_api()
785+
if self._xcvr_api is not None:
786+
self._xcvr_api.get_rx_los = self.get_rx_los
787+
self._xcvr_api.get_tx_fault = self.get_tx_fault
788+
return self._xcvr_api
789+
758790

759791
class RJ45Port(NvidiaSFPCommon):
760792
"""class derived from SFP, representing RJ45 ports"""

platform/mellanox/mlnx-platform-api/tests/test_sfp.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,17 @@ def test_is_port_admin_status_up(self, mock_port_status):
119119

120120
mock_port_status.return_value = (0, False)
121121
assert not SFP.is_port_admin_status_up(None, None)
122+
123+
@mock.patch('sonic_platform.sfp.SFP.get_xcvr_api')
124+
def test_dummy_apis(self, mock_get_xcvr_api):
125+
mock_api = mock.MagicMock()
126+
mock_api.NUM_CHANNELS = 4
127+
mock_get_xcvr_api.return_value = mock_api
128+
129+
sfp = SFP(0)
130+
assert sfp.get_rx_los() == [False] * 4
131+
assert sfp.get_tx_fault() == [False] * 4
132+
133+
mock_get_xcvr_api.return_value = None
134+
assert sfp.get_rx_los() is None
135+
assert sfp.get_tx_fault() is None

0 commit comments

Comments
 (0)