Skip to content

Commit 3d3c89b

Browse files
authored
fix for non-coherent cmis modules (sonic-net#2163)
* fix for non-coherent cmis modules * addressing comments * add back application_advertisement * fixing test failure Co-authored-by: Chuan Qin (QINCHUAN) <[email protected]>
1 parent 2054680 commit 3d3c89b

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

sfputil/main.py

+15-34
Original file line numberDiff line numberDiff line change
@@ -325,27 +325,13 @@ def convert_sfp_info_to_output_string(sfp_info_dict):
325325
elif key == 'cable_length':
326326
pass
327327
elif key == 'specification_compliance':
328-
if sfp_info_dict['type'] == "QSFP-DD Double Density 8X Pluggable Transceiver" or \
329-
sfp_info_dict['type'] == "OSFP 8X Pluggable Transceiver" or \
330-
sfp_info_dict['type'] == "QSFP+ or later with CMIS":
331-
output += '{}{}: {}\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
332-
else:
333-
output += '{}{}:\n'.format(indent, QSFP_DD_DATA_MAP['specification_compliance'])
334-
335-
spec_compliance_dict = {}
336-
try:
337-
spec_compliance_dict = ast.literal_eval(sfp_info_dict['specification_compliance'])
338-
sorted_compliance_key_table = natsorted(spec_compliance_dict)
339-
for compliance_key in sorted_compliance_key_table:
340-
output += '{}{}: {}\n'.format((indent * 2), compliance_key, spec_compliance_dict[compliance_key])
341-
except ValueError as e:
342-
output += '{}N/A\n'.format((indent * 2))
343-
elif key == 'application_advertisement':
344-
pass
328+
output += '{}{}: {}\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
345329
elif key == 'supported_max_tx_power' or key == 'supported_min_tx_power':
346-
output += '{}{}: {}dBm\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
330+
if key in sfp_info_dict: # C-CMIS compliant / coherent modules
331+
output += '{}{}: {}dBm\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
347332
elif key == 'supported_max_laser_freq' or key == 'supported_min_laser_freq':
348-
output += '{}{}: {}GHz\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
333+
if key in sfp_info_dict: # C-CMIS compliant / coherent modules
334+
output += '{}{}: {}GHz\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
349335
else:
350336
try:
351337
output += '{}{}: {}\n'.format(indent, QSFP_DD_DATA_MAP[key], sfp_info_dict[key])
@@ -360,21 +346,16 @@ def convert_sfp_info_to_output_string(sfp_info_dict):
360346
elif key == 'cable_length':
361347
pass
362348
elif key == 'specification_compliance':
363-
if sfp_info_dict['type'] == "QSFP-DD Double Density 8X Pluggable Transceiver" or \
364-
sfp_info_dict['type'] == "OSFP 8X Pluggable Transceiver" or \
365-
sfp_info_dict['type'] == "QSFP+ or later with CMIS":
366-
output += '{}{}: {}\n'.format(indent, QSFP_DATA_MAP[key], sfp_info_dict[key])
367-
else:
368-
output += '{}{}:\n'.format(indent, QSFP_DATA_MAP['specification_compliance'])
369-
370-
spec_compliance_dict = {}
371-
try:
372-
spec_compliance_dict = ast.literal_eval(sfp_info_dict['specification_compliance'])
373-
sorted_compliance_key_table = natsorted(spec_compliance_dict)
374-
for compliance_key in sorted_compliance_key_table:
375-
output += '{}{}: {}\n'.format((indent * 2), compliance_key, spec_compliance_dict[compliance_key])
376-
except ValueError as e:
377-
output += '{}N/A\n'.format((indent * 2))
349+
output += '{}{}:\n'.format(indent, QSFP_DATA_MAP['specification_compliance'])
350+
351+
spec_compliance_dict = {}
352+
try:
353+
spec_compliance_dict = ast.literal_eval(sfp_info_dict['specification_compliance'])
354+
sorted_compliance_key_table = natsorted(spec_compliance_dict)
355+
for compliance_key in sorted_compliance_key_table:
356+
output += '{}{}: {}\n'.format((indent * 2), compliance_key, spec_compliance_dict[compliance_key])
357+
except ValueError as e:
358+
output += '{}N/A\n'.format((indent * 2))
378359
else:
379360
output += '{}{}: {}\n'.format(indent, QSFP_DATA_MAP[key], sfp_info_dict[key])
380361

tests/sfputil_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def test_format_dict_value_to_string(self):
175175
" Active App Selection Host Lane 7: 1\n"
176176
" Active App Selection Host Lane 8: 1\n"
177177
" Active Firmware Version: 0.1\n"
178+
" Application Advertisement: N/A\n"
178179
" CMIS Revision: 5.0\n"
179180
" Connector: LC\n"
180181
" Encoding: N/A\n"

0 commit comments

Comments
 (0)