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

Create is_transceiver_vdm_supported API for CMIS transceivers #527

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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 @@ -1505,6 +1505,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 @@ -1242,6 +1242,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
Loading