Skip to content

Commit 0d45adb

Browse files
authored
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
1 parent be04b80 commit 0d45adb

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

sonic_platform_base/sonic_xcvr/api/public/cmis.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class CmisApi(XcvrApi):
2727

2828
def __init__(self, xcvr_eeprom):
2929
super(CmisApi, self).__init__(xcvr_eeprom)
30-
self.vdm = CmisVdmApi(xcvr_eeprom)
31-
self.cdb = CmisCdbApi(xcvr_eeprom)
30+
self.vdm = CmisVdmApi(xcvr_eeprom) if not self.is_flat_memory() else None
31+
self.cdb = CmisCdbApi(xcvr_eeprom) if not self.is_flat_memory() else None
3232

3333
def get_model(self):
3434
'''
@@ -1015,7 +1015,7 @@ def get_vdm(self):
10151015
'''
10161016
This function returns all the VDM items, including real time monitor value, threholds and flags
10171017
'''
1018-
vdm = self.vdm.get_vdm_allpage() if not self.is_flat_memory() else {}
1018+
vdm = self.vdm.get_vdm_allpage() if self.vdm is not None else {}
10191019
return vdm
10201020

10211021
def get_module_firmware_fault_state_changed(self):
@@ -1116,6 +1116,9 @@ def get_module_fw_mgmt_feature(self, verbose = False):
11161116
the following upgrade with depend on these parameters.
11171117
"""
11181118
txt = ''
1119+
if self.cdb is None:
1120+
return {'status': False, 'info': "CDB Not supported", 'result': None}
1121+
11191122
# get fw upgrade features (CMD 0041h)
11201123
starttime = time.time()
11211124
autopaging = self.xcvr_eeprom.read(consts.AUTO_PAGING_SUPPORT)
@@ -1166,6 +1169,10 @@ def get_module_fw_info(self):
11661169
Validity Status: 1 = invalid, 0 = valid
11671170
"""
11681171
txt = ''
1172+
1173+
if self.cdb is None:
1174+
return {'status': False, 'info': "CDB Not supported", 'result': None}
1175+
11691176
# get fw info (CMD 0100h)
11701177
rpllen, rpl_chkcode, rpl = self.cdb.get_fw_info()
11711178
# password issue
@@ -1250,6 +1257,8 @@ def module_fw_run(self, mode = 0x01):
12501257
"""
12511258
# run module FW (CMD 0109h)
12521259
txt = ''
1260+
if self.cdb is None:
1261+
return False, "CDB NOT supported on this module"
12531262
starttime = time.time()
12541263
fw_run_status = self.cdb.run_fw_image(mode)
12551264
if fw_run_status == 1:
@@ -1280,6 +1289,8 @@ def module_fw_commit(self):
12801289
Otherwise it will return False.
12811290
"""
12821291
txt = ''
1292+
if self.cdb is None:
1293+
return False, "CDB NOT supported on this module"
12831294
# commit module FW (CMD 010Ah)
12841295
starttime = time.time()
12851296
fw_commit_status= self.cdb.commit_fw_image()
@@ -1337,6 +1348,9 @@ def module_fw_download(self, startLPLsize, maxblocksize, lplonly_flag, autopagin
13371348
This function returns True if download successfully completes. Otherwise it will return False where it fails.
13381349
"""
13391350
txt = ''
1351+
if self.cdb is None:
1352+
return False, "CDB NOT supported on this module"
1353+
13401354
# start fw download (CMD 0101h)
13411355
starttime = time.time()
13421356
try:

tests/sonic_xcvr/test_cmisCDB.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mock import MagicMock
22
import pytest
3+
from sonic_platform_base.sonic_xcvr.api.public.cmis import CmisApi
34
from sonic_platform_base.sonic_xcvr.api.public.cmisCDB import CmisCdbApi
45
from sonic_platform_base.sonic_xcvr.mem_maps.public.cmis import CmisMemMap
56
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom
@@ -13,6 +14,18 @@ class TestCDB(object):
1314
eeprom = XcvrEeprom(reader, writer, mem_map)
1415
api = CmisCdbApi(eeprom)
1516

17+
def test_cdb_is_none(self):
18+
api = CmisApi(self.eeprom)
19+
api.cdb = None
20+
print(api)
21+
print(api.get_module_fw_mgmt_feature())
22+
assert False == api.get_module_fw_mgmt_feature()['status']
23+
assert False == api.get_module_fw_info()['status']
24+
assert False == api.module_fw_run()[0]
25+
assert False == api.module_fw_commit()[0]
26+
assert False == api.module_fw_download(None, None, None, None, None, None)[0]
27+
28+
1629
@pytest.mark.parametrize("mock_response, expected", [
1730
(64, False),
1831
(0, True)
@@ -101,7 +114,7 @@ def test_get_fw_management_features(self, mock_response, expected):
101114
self.api.cdb1_chkstatus = MagicMock()
102115
self.api.cdb1_chkstatus.return_value = mock_response[0]
103116
self.api.read_cdb = MagicMock()
104-
self.api.read_cdb.return_value = mock_response[1]
117+
self.api.read_cdb.return_value = mock_response[1]
105118
result = self.api.get_fw_management_features()
106119
assert result == expected
107120

@@ -185,7 +198,7 @@ def test_run_fw_image(self, mock_response, expected):
185198
self.api.cdb1_chkstatus.return_value = mock_response
186199
result = self.api.run_fw_image()
187200
assert result == expected
188-
201+
189202
@pytest.mark.parametrize("mock_response, expected", [
190203
(1, 1),
191204
(64, 64),

0 commit comments

Comments
 (0)