Skip to content

Commit c6fa955

Browse files
committed
More changes
1 parent d2b2509 commit c6fa955

File tree

4 files changed

+103
-31
lines changed

4 files changed

+103
-31
lines changed

sonic_platform_base/sonic_xcvr/api/public/c_cmis.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66
from sonic_py_common import logger
77
from ...fields import consts
8-
from .cmis import CmisApi, CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP
8+
from .cmis import CmisApi, CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP, CMIS_XCVR_INFO_DEFAULT_DICT
99
import time
1010
import copy
1111
BYTELENGTH = 8
@@ -46,16 +46,15 @@
4646

4747
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)
4848

49-
class CCmisApi(CmisApi):
50-
C_CMIS_XCVR_INFO_DEFAULT_DICT = copy.deepcopy(CmisApi.cmis_xcvr_info_dict)
51-
C_CMIS_XCVR_INFO_DEFAULT_DICT.update({
52-
"supported_max_tx_power": "N/A",
53-
"supported_min_tx_power": "N/A",
54-
"supported_max_laser_freq": "N/A",
55-
"supported_min_laser_freq": "N/A"
56-
})
57-
49+
C_CMIS_XCVR_INFO_DEFAULT_DICT = copy.deepcopy(CMIS_XCVR_INFO_DEFAULT_DICT)
50+
C_CMIS_XCVR_INFO_DEFAULT_DICT.update({
51+
"supported_max_tx_power": "N/A",
52+
"supported_min_tx_power": "N/A",
53+
"supported_max_laser_freq": "N/A",
54+
"supported_min_laser_freq": "N/A"
55+
})
5856

57+
class CCmisApi(CmisApi):
5958
def __init__(self, xcvr_eeprom):
6059
super(CCmisApi, self).__init__(xcvr_eeprom)
6160

@@ -322,6 +321,9 @@ def get_pm_all(self):
322321
PM_dict['rx_mer_max'] = self.xcvr_eeprom.read(consts.RX_MAX_MER_PM)
323322
return PM_dict
324323

324+
def _get_xcvr_info_default_dict(self):
325+
return C_CMIS_XCVR_INFO_DEFAULT_DICT
326+
325327
def get_transceiver_info(self):
326328
"""
327329
Retrieves transceiver info of this SFP
@@ -364,17 +366,22 @@ def get_transceiver_info(self):
364366
supported_min_laser_freq = FLOAT ; support minimum laser frequency
365367
================================================================================
366368
"""
367-
self.xcvr_info = copy.deepcopy(self.C_CMIS_XCVR_INFO_DEFAULT_DICT)
368-
self.xcvr_info = super(CCmisApi, self).get_transceiver_info()
369+
xcvr_info = super(CCmisApi, self).get_transceiver_info()
370+
371+
# Return None if CmisApi class returns None, this indicates to XCVRD that retry is
372+
# needed.
373+
if xcvr_info is None:
374+
return None
375+
369376
min_power, max_power = self.get_supported_power_config()
370377
_, _, _, low_freq_supported, high_freq_supported = self.get_supported_freq_config()
371-
self.xcvr_info.update({
378+
xcvr_info.update({
372379
'supported_max_tx_power': max_power,
373380
'supported_min_tx_power': min_power,
374381
'supported_max_laser_freq': high_freq_supported,
375382
'supported_min_laser_freq': low_freq_supported
376383
})
377-
return self.xcvr_info
384+
return xcvr_info
378385

379386
def get_transceiver_bulk_status(self):
380387
"""

sonic_platform_base/sonic_xcvr/api/public/cmis.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,7 @@ class VdmSubtypeIndex(Enum):
7878
"Errored Frames Current Value Host Input" : "errored_frames_curr_host_input"
7979
}
8080

81-
class CmisApi(XcvrApi):
82-
NUM_CHANNELS = 8
83-
LowPwrRequestSW = 4
84-
LowPwrAllowRequestHW = 6
85-
86-
cmis_xcvr_info_dict = {
81+
CMIS_XCVR_INFO_DEFAULT_DICT = {
8782
"type": "N/A",
8883
"type_abbrv_name": "N/A",
8984
"hardware_rev": "N/A",
@@ -114,6 +109,11 @@ class CmisApi(XcvrApi):
114109
"vdm_supported": "N/A"
115110
}
116111

112+
class CmisApi(XcvrApi):
113+
NUM_CHANNELS = 8
114+
LowPwrRequestSW = 4
115+
LowPwrAllowRequestHW = 6
116+
117117
def __init__(self, xcvr_eeprom):
118118
super(CmisApi, self).__init__(xcvr_eeprom)
119119
self.vdm = CmisVdmApi(xcvr_eeprom) if not self.is_flat_memory() else None
@@ -291,6 +291,9 @@ def get_module_inactive_firmware(self):
291291
inactive_fw = [str(num) for num in [inactive_fw_major, inactive_fw_minor]]
292292
return '.'.join(inactive_fw)
293293

294+
def _get_xcvr_info_default_dict(self):
295+
return CMIS_XCVR_INFO_DEFAULT_DICT
296+
294297
def get_transceiver_info(self):
295298
admin_info = self.xcvr_eeprom.read(consts.ADMIN_INFO_FIELD)
296299
if admin_info is None:
@@ -299,8 +302,8 @@ def get_transceiver_info(self):
299302
ext_id = admin_info[consts.EXT_ID_FIELD]
300303
power_class = ext_id[consts.POWER_CLASS_FIELD]
301304
max_power = ext_id[consts.MAX_POWER_FIELD]
302-
self.xcvr_info = copy.deepcopy(CmisApi.cmis_xcvr_info_dict)
303-
self.xcvr_info.update({
305+
xcvr_info = copy.deepcopy(self._get_xcvr_info_default_dict())
306+
xcvr_info.update({
304307
"type": admin_info[consts.ID_FIELD],
305308
"type_abbrv_name": admin_info[consts.ID_ABBRV_FIELD],
306309
"hardware_rev": self.get_module_hardware_revision(),
@@ -328,18 +331,18 @@ def get_transceiver_info(self):
328331
})
329332
apsel_dict = self.get_active_apsel_hostlane()
330333
for lane in range(1, self.NUM_CHANNELS + 1):
331-
self.xcvr_info["%s%d" % ("active_apsel_hostlane", lane)] = \
334+
xcvr_info["%s%d" % ("active_apsel_hostlane", lane)] = \
332335
apsel_dict["%s%d" % (consts.ACTIVE_APSEL_HOSTLANE, lane)]
333336

334337
# In normal case will get a valid value for each of the fields. If get a 'None' value
335338
# means there was a failure while reading the EEPROM, either because the EEPROM was
336-
# not ready yet or experincing some other issues. It shouldn't return a dict with a
339+
# not ready yet or experiencing some other issues. It shouldn't return a dict with a
337340
# wrong field value, instead should return a 'None' to indicate to XCVRD that retry is
338341
# needed.
339-
if None in self.xcvr_info.values():
342+
if None in xcvr_info.values():
340343
return None
341344
else:
342-
return self.xcvr_info
345+
return xcvr_info
343346

344347
def get_transceiver_info_firmware_versions(self):
345348
return_dict = {"active_firmware" : "N/A", "inactive_firmware" : "N/A"}

tests/sonic_xcvr/test_ccmis.py

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from mock import MagicMock
22
from mock import patch
33
import pytest
4-
from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CCmisApi
4+
from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CCmisApi, C_CMIS_XCVR_INFO_DEFAULT_DICT
55
from sonic_platform_base.sonic_xcvr.mem_maps.public.c_cmis import CCmisMemMap
66
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom
77
from sonic_platform_base.sonic_xcvr.codes.public.cmis import CmisCodes
@@ -161,14 +161,68 @@ def test_get_pm_all(self, mock_response, expected):
161161
@pytest.mark.parametrize("mock_response, expected",[
162162
(
163163
(
164-
{
165-
'type': 'QSFP-DD Double Density 8X Pluggable Transceiver'
164+
{ # EEPROM DATA
165+
'type': 'QSFP-DD Double Density 8X Pluggable Transceiver',
166+
'type_abbrv_name': 'QSFP-DD',
167+
'model': 'ABCD',
168+
'encoding': 'N/A',
169+
'ext_identifier': 'Power Class 8 (20.0W Max)',
170+
'ext_rateselect_compliance': 'N/A',
171+
'cable_type': 'Length Cable Assembly(m)',
172+
'cable_length': 0.0,
173+
'nominal_bit_rate': 'N/A',
174+
'specification_compliance': 'sm_media_interface',
175+
'application_advertisement': 'N/A',
176+
'media_lane_count': 1,
177+
'vendor_rev': '0.0',
178+
'host_electrical_interface': '400GAUI-8 C2M (Annex 120E)',
179+
'vendor_oui': 'xx-xx-xx',
180+
'manufacturer': 'VENDOR_NAME',
181+
'media_interface_technology': '1550 nm DFB',
182+
'media_interface_code': '400ZR, DWDM, amplified',
183+
'serial': '00000000',
184+
'host_lane_count': 8,
185+
**{f'active_apsel_hostlane{i}': 1 for i in range(1, 9)},
186+
'hardware_rev': '0.0',
187+
'cmis_rev': '5.0',
188+
'media_lane_assignment_option': 1,
189+
'connector': 'LC',
190+
'host_lane_assignment_option': 1,
191+
'vendor_date': '21010100',
192+
'vdm_supported': True,
166193
},
167194
(-20, 0),
168195
(0xff, -72, 120, 191300, 196100)
169196
),
170-
{
197+
{ # Expected Result
171198
'type': 'QSFP-DD Double Density 8X Pluggable Transceiver',
199+
'type_abbrv_name': 'QSFP-DD',
200+
'model': 'ABCD',
201+
'encoding': 'N/A',
202+
'ext_identifier': 'Power Class 8 (20.0W Max)',
203+
'ext_rateselect_compliance': 'N/A',
204+
'cable_type': 'Length Cable Assembly(m)',
205+
'cable_length': 0.0,
206+
'nominal_bit_rate': 'N/A',
207+
'specification_compliance': 'sm_media_interface',
208+
'application_advertisement': 'N/A',
209+
'media_lane_count': 1,
210+
'vendor_rev': '0.0',
211+
'host_electrical_interface': '400GAUI-8 C2M (Annex 120E)',
212+
'vendor_oui': 'xx-xx-xx',
213+
'manufacturer': 'VENDOR_NAME',
214+
'media_interface_technology': '1550 nm DFB',
215+
'media_interface_code': '400ZR, DWDM, amplified',
216+
'serial': '00000000',
217+
'host_lane_count': 8,
218+
**{f'active_apsel_hostlane{i}': 1 for i in range(1, 9)},
219+
'hardware_rev': '0.0',
220+
'cmis_rev': '5.0',
221+
'media_lane_assignment_option': 1,
222+
'connector': 'LC',
223+
'host_lane_assignment_option': 1,
224+
'vendor_date': '21010100',
225+
'vdm_supported': True,
172226
'supported_min_laser_freq': 191300,
173227
'supported_max_laser_freq': 196100,
174228
'supported_max_tx_power': 0,
@@ -189,6 +243,9 @@ def test_get_transceiver_info(self, get_transceiver_info_func, mock_response, ex
189243
result = self.api.get_transceiver_info()
190244
assert result == expected
191245

246+
# Test result is same as default dictionary length
247+
assert len(C_CMIS_XCVR_INFO_DEFAULT_DICT) == len(result)
248+
192249

193250
@pytest.mark.parametrize("mock_response, expected",[
194251
(

tests/sonic_xcvr/test_cmis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import pytest
44
import traceback
55
import random
6-
from sonic_platform_base.sonic_xcvr.api.public.cmis import CmisApi, CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP, THRESHOLD_TYPE_STR_MAP, FLAG_TYPE_STR_MAP
6+
from sonic_platform_base.sonic_xcvr.api.public.cmis import CmisApi, CMIS_VDM_KEY_TO_DB_PREFIX_KEY_MAP, THRESHOLD_TYPE_STR_MAP
7+
from sonic_platform_base.sonic_xcvr.api.public.cmis import FLAG_TYPE_STR_MAP, CMIS_XCVR_INFO_DEFAULT_DICT
78
from sonic_platform_base.sonic_xcvr.mem_maps.public.cmis import CmisMemMap
89
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom
910
from sonic_platform_base.sonic_xcvr.codes.public.cmis import CmisCodes
@@ -1522,6 +1523,10 @@ def test_get_transceiver_info(self, mock_response, expected):
15221523
result = self.api.get_transceiver_info()
15231524
assert result == expected
15241525

1526+
if result is not None:
1527+
# Test result is same as default dictionary length
1528+
assert len(CMIS_XCVR_INFO_DEFAULT_DICT) == len(result)
1529+
15251530
# Test negative path
15261531
self.api.get_cmis_rev.return_value = None
15271532
result = self.api.get_transceiver_info()

0 commit comments

Comments
 (0)