From 6492675b96a13755090fc62aaa405fe2fc593984 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox Date: Thu, 4 Jul 2024 10:24:50 +0300 Subject: [PATCH] Add speed media key for non CMIS cable --- sonic-xcvrd/tests/test_xcvrd.py | 13 +++++++++++-- .../xcvrd/xcvrd_utilities/media_settings_parser.py | 12 ++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 11b7f4e89..16a9446a2 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -660,12 +660,21 @@ def test_get_media_settings_key(self, mock_is_cmis_api, mock_chassis): # Test a good 'specification_compliance' value result = media_settings_parser.get_media_settings_key(0, xcvr_info_dict, 100000, 2) - assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-10GBase-SR-255M', 'lane_speed_key': None } + assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-10GBase-SR-255M', 'lane_speed_key': 'speed:50G:2' } + + # Test a special 'specification_compliance' value + specification_compliance_dict = { + '10/40G Ethernet Compliance Code': 'Extended', + 'Extended Specification Compliance': '100GBASE-SR10' + } + xcvr_info_dict[0]['specification_compliance'] = str(specification_compliance_dict) + result = media_settings_parser.get_media_settings_key(0, xcvr_info_dict, 100000, 2) + assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-100GBASE-SR10-255M', 'lane_speed_key': 'speed:50G:2' } # Test a bad 'specification_compliance' value xcvr_info_dict[0]['specification_compliance'] = 'N/A' result = media_settings_parser.get_media_settings_key(0, xcvr_info_dict, 100000, 2) - assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-*', 'lane_speed_key': None } + assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-*', 'lane_speed_key': 'speed:50G:2' } # TODO: Ensure that error message was logged mock_is_cmis_api.return_value = True diff --git a/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py b/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py index 9e79e6c7b..7e4ce4e5e 100644 --- a/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py +++ b/sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py @@ -58,6 +58,12 @@ def get_lane_speed_key(physical_port, port_speed, lane_count): host_electrical_interface_id = appl_adv_dict[app_id].get('host_electrical_interface_id') if host_electrical_interface_id: lane_speed_key = LANE_SPEED_KEY_PREFIX + host_electrical_interface_id.split()[0] + else: + speed_per_lane = port_speed / 1000 / lane_count + speed_per_lane_int = int(speed_per_lane) + if speed_per_lane - speed_per_lane_int == 0: + speed_per_lane = speed_per_lane_int + lane_speed_key = LANE_SPEED_KEY_PREFIX + str(speed_per_lane) + 'G:' + str(lane_count) return lane_speed_key @@ -88,14 +94,16 @@ def get_media_settings_key(physical_port, transceiver_dict, port_speed, lane_cou media_compliance_dict = ast.literal_eval(media_compliance_dict_str) if sup_compliance_str in media_compliance_dict: media_compliance_code = media_compliance_dict[sup_compliance_str] + if media_compliance_code == 'Extended' or media_compliance_code == 'Unknown': + media_compliance_code = media_compliance_dict['Extended Specification Compliance'] except ValueError as e: helper_logger.log_error("Invalid value for port {} 'specification_compliance': {}".format(physical_port, media_compliance_dict_str)) media_type = transceiver_dict[physical_port]['type_abbrv_name'] - if len(media_type) != 0: + if media_type: media_key += media_type - if len(media_compliance_code) != 0: + if media_compliance_code: media_key += '-' + media_compliance_code sfp = xcvrd.platform_chassis.get_sfp(physical_port) api = sfp.get_xcvr_api()