Skip to content

Commit

Permalink
Create is_transceiver_vdm_supported API for CMIS transceivers (#527)
Browse files Browse the repository at this point in the history
* Create is_transceiver_vdm_supported API for CMIS transceivers

Signed-off-by: Mihir Patel <[email protected]>

* Increased code coverage

* Enhanced unit test in test_sfp_optoe_base.py

---------

Signed-off-by: Mihir Patel <[email protected]>
  • Loading branch information
mihirpat1 authored Jan 30, 2025
1 parent bead25d commit cb5564c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,12 @@ def set_loopback_mode(self, loopback_mode, lane_mask = 0xff, enable = False):
logger.error('Invalid loopback mode:%s, lane_mask:%#x', loopback_mode, lane_mask)
return False

def is_transceiver_vdm_supported(self):
'''
This function returns whether VDM is supported
'''
return self.vdm is not None and self.xcvr_eeprom.read(consts.VDM_SUPPORTED)

def get_vdm(self, field_option=None):
'''
This function returns all the VDM items, including real time monitor value, threholds and flags
Expand Down
6 changes: 6 additions & 0 deletions sonic_platform_base/sonic_xcvr/api/xcvr_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ def get_transceiver_status_flags(self):
"""
raise NotImplementedError

def is_transceiver_vdm_supported(self):
"""
Retrieves VDM support status for this xcvr (applicable for CMIS and C-CMIS)
"""
raise NotImplementedError

def get_transceiver_vdm_real_value(self):
"""
Retrieves VDM real (sample) values for this xcvr (applicable for CMIS and C-CMIS)
Expand Down
4 changes: 4 additions & 0 deletions sonic_platform_base/sonic_xcvr/sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def is_coherent_module(self):
api = self.get_xcvr_api()
return api.is_coherent_module() if api is not None else None

def is_transceiver_vdm_supported(self):
api = self.get_xcvr_api()
return api.is_transceiver_vdm_supported() if api is not None else None

def get_transceiver_vdm_real_value(self):
"""
Retrieves VDM real (sample) values for this xcvr (applicable for CMIS and C-CMIS)
Expand Down
14 changes: 14 additions & 0 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,20 @@ def test_set_loopback_mode(self, input_param, mock_response, expected):
result = self.api.set_loopback_mode(input_param[0], input_param[1])
assert result == expected

def test_is_transceiver_vdm_supported_no_vdm(self):
self.api.vdm = None
assert self.api.is_transceiver_vdm_supported() == False

def test_is_transceiver_vdm_supported_true(self):
self.api.vdm = MagicMock()
self.api.xcvr_eeprom.read = MagicMock(return_value=1)
assert self.api.is_transceiver_vdm_supported() == True

def test_is_transceiver_vdm_supported_false(self):
self.api.vdm = MagicMock()
self.api.xcvr_eeprom.read = MagicMock(return_value=0)
assert self.api.is_transceiver_vdm_supported() == False

@pytest.mark.parametrize("mock_response, expected",[
(
[
Expand Down
10 changes: 10 additions & 0 deletions tests/sonic_xcvr/test_sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sonic_platform_base.sonic_xcvr.mem_maps.public.c_cmis import CCmisMemMap
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom
from sonic_platform_base.sonic_xcvr.codes.public.cmis import CmisCodes
from sonic_platform_base.sonic_xcvr.api.public.sff8472 import Sff8472Api

class TestSfpOptoeBase(object):

Expand All @@ -19,7 +20,16 @@ class TestSfpOptoeBase(object):
sfp_optoe_api = SfpOptoeBase()
ccmis_api = CCmisApi(eeprom)
cmis_api = CmisApi(eeprom)
sff8472_api = Sff8472Api(eeprom)

def test_is_transceiver_vdm_supported_non_cmis(self):
self.sfp_optoe_api.get_xcvr_api = MagicMock(return_value=self.sff8472_api)
try:
self.sfp_optoe_api.is_transceiver_vdm_supported()
except NotImplementedError:
exception_raised = True
assert exception_raised

@pytest.mark.parametrize("mock_response1, mock_response2, expected", [
(0, cmis_api, 0),
(1, cmis_api, 1),
Expand Down

0 comments on commit cb5564c

Please sign in to comment.