Skip to content

Commit ee9da5f

Browse files
authored
Refactor port_port_sfp_info_to_db() to read key:value pairs directly from port_info_dict (#590)
* Refactor port_port_sfp_info_to_db() to read key:value pairs directly from port_info_dict * Revert white space fixes * Fix white space
1 parent 29e65fe commit ee9da5f

File tree

1 file changed

+4
-54
lines changed

1 file changed

+4
-54
lines changed

sonic-xcvrd/xcvrd/xcvrd.py

+4-54
Original file line numberDiff line numberDiff line change
@@ -422,58 +422,8 @@ def post_port_sfp_info_to_db(logical_port_name, port_mapping, table, transceiver
422422
transceiver_dict[physical_port] = port_info_dict
423423
# if cmis is supported by the module
424424
if 'cmis_rev' in port_info_dict:
425-
fvs = swsscommon.FieldValuePairs(
426-
[('type', port_info_dict['type']),
427-
('vendor_rev', port_info_dict['vendor_rev']),
428-
('serial', port_info_dict['serial']),
429-
('manufacturer', port_info_dict['manufacturer']),
430-
('model', port_info_dict['model']),
431-
('vendor_oui', port_info_dict['vendor_oui']),
432-
('vendor_date', port_info_dict['vendor_date']),
433-
('connector', port_info_dict['connector']),
434-
('encoding', port_info_dict['encoding']),
435-
('ext_identifier', port_info_dict['ext_identifier']),
436-
('ext_rateselect_compliance', port_info_dict['ext_rateselect_compliance']),
437-
('cable_type', port_info_dict['cable_type']),
438-
('cable_length', str(port_info_dict['cable_length'])),
439-
('specification_compliance', port_info_dict['specification_compliance']),
440-
('nominal_bit_rate', str(port_info_dict['nominal_bit_rate'])),
441-
('application_advertisement', port_info_dict['application_advertisement']
442-
if 'application_advertisement' in port_info_dict else 'N/A'),
443-
('is_replaceable', str(is_replaceable)),
444-
('dom_capability', port_info_dict['dom_capability']
445-
if 'dom_capability' in port_info_dict else 'N/A'),
446-
('cmis_rev', port_info_dict['cmis_rev'] if 'cmis_rev' in port_info_dict else 'N/A'),
447-
('hardware_rev', port_info_dict['hardware_rev']
448-
if 'hardware_rev' in port_info_dict else 'N/A'),
449-
('media_interface_code', port_info_dict['media_interface_code']
450-
if 'media_interface_code' in port_info_dict else 'N/A'),
451-
('host_electrical_interface', port_info_dict['host_electrical_interface']
452-
if 'host_electrical_interface' in port_info_dict else 'N/A'),
453-
('host_lane_count', 'N/A'),
454-
('media_lane_count', 'N/A'),
455-
('host_lane_assignment_option', str(port_info_dict['host_lane_assignment_option'])
456-
if 'host_lane_assignment_option' in port_info_dict else 'N/A'),
457-
('media_lane_assignment_option', str(port_info_dict['media_lane_assignment_option'])
458-
if 'media_lane_assignment_option' in port_info_dict else 'N/A'),
459-
('active_apsel_hostlane1', 'N/A'),
460-
('active_apsel_hostlane2', 'N/A'),
461-
('active_apsel_hostlane3', 'N/A'),
462-
('active_apsel_hostlane4', 'N/A'),
463-
('active_apsel_hostlane5', 'N/A'),
464-
('active_apsel_hostlane6', 'N/A'),
465-
('active_apsel_hostlane7', 'N/A'),
466-
('active_apsel_hostlane8', 'N/A'),
467-
('media_interface_technology', port_info_dict['media_interface_technology']
468-
if 'media_interface_technology' in port_info_dict else 'N/A'),
469-
('supported_max_tx_power', str(port_info_dict['supported_max_tx_power'])
470-
if 'supported_max_tx_power' in port_info_dict else 'N/A'),
471-
('supported_min_tx_power', str(port_info_dict['supported_min_tx_power'])
472-
if 'supported_min_tx_power' in port_info_dict else 'N/A'),
473-
('supported_max_laser_freq', str(port_info_dict['supported_max_laser_freq'])
474-
if 'supported_max_laser_freq' in port_info_dict else 'N/A'),
475-
('supported_min_laser_freq', str(port_info_dict['supported_min_laser_freq'])
476-
if 'supported_min_laser_freq' in port_info_dict else 'N/A')
425+
fvs = swsscommon.FieldValuePairs([
426+
(field, str(value)) for field, value in port_info_dict.items()
477427
])
478428
# else cmis is not supported by the module
479429
else:
@@ -819,7 +769,7 @@ def get_cmis_media_lanes_mask(self, api, appl, lport, subport):
819769
self.log_error("Invalid input to get media lane mask - appl {} media_lane_count {} "
820770
"lport {} subport {}!".format(appl, media_lane_count, lport, subport))
821771
return media_lanes_mask
822-
772+
823773
media_lane_start_bit = (media_lane_count * (0 if subport == 0 else subport - 1))
824774
if media_lane_assignment_option & (1 << media_lane_start_bit):
825775
media_lanes_mask = ((1 << media_lane_count) - 1) << media_lane_start_bit
@@ -1294,7 +1244,7 @@ def task_worker(self):
12941244
continue
12951245
host_lanes_mask = self.port_dict[lport]['host_lanes_mask']
12961246
self.log_notice("{}: Setting host_lanemask=0x{:x}".format(lport, host_lanes_mask))
1297-
1247+
12981248
self.port_dict[lport]['media_lane_count'] = int(api.get_media_lane_count(appl))
12991249
self.port_dict[lport]['media_lane_assignment_options'] = int(api.get_media_lane_assignment_option(appl))
13001250
media_lane_count = self.port_dict[lport]['media_lane_count']

0 commit comments

Comments
 (0)