From 0d45adb62f48637a575e09da7c61c58a7020e40e Mon Sep 17 00:00:00 2001 From: Prince George <45705344+prgeor@users.noreply.github.com> Date: Mon, 13 Jun 2022 15:23:59 -0700 Subject: [PATCH] Skip CDB and VDM for flat memory modules (#281) * Skip CDB and VDM for flat memory modules * Improve code coverage * Fix test failure * Fix test failure * Fix test failure --- .../sonic_xcvr/api/public/cmis.py | 20 ++++++++++++++++--- tests/sonic_xcvr/test_cmisCDB.py | 17 ++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index 6b666987dcb7..4d0a9fea443a 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -27,8 +27,8 @@ class CmisApi(XcvrApi): def __init__(self, xcvr_eeprom): super(CmisApi, self).__init__(xcvr_eeprom) - self.vdm = CmisVdmApi(xcvr_eeprom) - self.cdb = CmisCdbApi(xcvr_eeprom) + self.vdm = CmisVdmApi(xcvr_eeprom) if not self.is_flat_memory() else None + self.cdb = CmisCdbApi(xcvr_eeprom) if not self.is_flat_memory() else None def get_model(self): ''' @@ -1015,7 +1015,7 @@ def get_vdm(self): ''' This function returns all the VDM items, including real time monitor value, threholds and flags ''' - vdm = self.vdm.get_vdm_allpage() if not self.is_flat_memory() else {} + vdm = self.vdm.get_vdm_allpage() if self.vdm is not None else {} return vdm def get_module_firmware_fault_state_changed(self): @@ -1116,6 +1116,9 @@ def get_module_fw_mgmt_feature(self, verbose = False): the following upgrade with depend on these parameters. """ txt = '' + if self.cdb is None: + return {'status': False, 'info': "CDB Not supported", 'result': None} + # get fw upgrade features (CMD 0041h) starttime = time.time() autopaging = self.xcvr_eeprom.read(consts.AUTO_PAGING_SUPPORT) @@ -1166,6 +1169,10 @@ def get_module_fw_info(self): Validity Status: 1 = invalid, 0 = valid """ txt = '' + + if self.cdb is None: + return {'status': False, 'info': "CDB Not supported", 'result': None} + # get fw info (CMD 0100h) rpllen, rpl_chkcode, rpl = self.cdb.get_fw_info() # password issue @@ -1250,6 +1257,8 @@ def module_fw_run(self, mode = 0x01): """ # run module FW (CMD 0109h) txt = '' + if self.cdb is None: + return False, "CDB NOT supported on this module" starttime = time.time() fw_run_status = self.cdb.run_fw_image(mode) if fw_run_status == 1: @@ -1280,6 +1289,8 @@ def module_fw_commit(self): Otherwise it will return False. """ txt = '' + if self.cdb is None: + return False, "CDB NOT supported on this module" # commit module FW (CMD 010Ah) starttime = time.time() fw_commit_status= self.cdb.commit_fw_image() @@ -1337,6 +1348,9 @@ def module_fw_download(self, startLPLsize, maxblocksize, lplonly_flag, autopagin This function returns True if download successfully completes. Otherwise it will return False where it fails. """ txt = '' + if self.cdb is None: + return False, "CDB NOT supported on this module" + # start fw download (CMD 0101h) starttime = time.time() try: diff --git a/tests/sonic_xcvr/test_cmisCDB.py b/tests/sonic_xcvr/test_cmisCDB.py index b0a7396acf68..6973e02452c8 100644 --- a/tests/sonic_xcvr/test_cmisCDB.py +++ b/tests/sonic_xcvr/test_cmisCDB.py @@ -1,5 +1,6 @@ from mock import MagicMock import pytest +from sonic_platform_base.sonic_xcvr.api.public.cmis import CmisApi from sonic_platform_base.sonic_xcvr.api.public.cmisCDB import CmisCdbApi from sonic_platform_base.sonic_xcvr.mem_maps.public.cmis import CmisMemMap from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom @@ -13,6 +14,18 @@ class TestCDB(object): eeprom = XcvrEeprom(reader, writer, mem_map) api = CmisCdbApi(eeprom) + def test_cdb_is_none(self): + api = CmisApi(self.eeprom) + api.cdb = None + print(api) + print(api.get_module_fw_mgmt_feature()) + assert False == api.get_module_fw_mgmt_feature()['status'] + assert False == api.get_module_fw_info()['status'] + assert False == api.module_fw_run()[0] + assert False == api.module_fw_commit()[0] + assert False == api.module_fw_download(None, None, None, None, None, None)[0] + + @pytest.mark.parametrize("mock_response, expected", [ (64, False), (0, True) @@ -101,7 +114,7 @@ def test_get_fw_management_features(self, mock_response, expected): self.api.cdb1_chkstatus = MagicMock() self.api.cdb1_chkstatus.return_value = mock_response[0] self.api.read_cdb = MagicMock() - self.api.read_cdb.return_value = mock_response[1] + self.api.read_cdb.return_value = mock_response[1] result = self.api.get_fw_management_features() assert result == expected @@ -185,7 +198,7 @@ def test_run_fw_image(self, mock_response, expected): self.api.cdb1_chkstatus.return_value = mock_response result = self.api.run_fw_image() assert result == expected - + @pytest.mark.parametrize("mock_response, expected", [ (1, 1), (64, 64),