[Mellanox] Provide dummy implementation for get_rx_los and get_tx_fault (#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
This commit is contained in:
parent
5510d9c03b
commit
1d69f0916e
@ -755,6 +755,38 @@ class SFP(NvidiaSFPCommon):
|
||||
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"""
|
||||
|
@ -119,3 +119,17 @@ class TestSfp:
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user