Skip to content

Commit

Permalink
Skip CDB and VDM for flat memory modules (sonic-net#281)
Browse files Browse the repository at this point in the history
* Skip CDB and VDM for flat memory modules

* Improve code coverage

* Fix test failure

* Fix test failure

* Fix test failure
  • Loading branch information
prgeor authored Jun 13, 2022
1 parent be04b80 commit 0d45adb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
20 changes: 17 additions & 3 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions tests/sonic_xcvr/test_cmisCDB.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 0d45adb

Please sign in to comment.