From c9a81b0dd9bbafb1186a94ee9c07bbcf15ca3e88 Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Thu, 2 Nov 2023 01:07:18 +0000 Subject: [PATCH 1/2] APIs to help in finding NPU SI settings Signed-off-by: Mihir Patel --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 14 +++++++++++++- tests/sonic_xcvr/test_cmis.py | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index a677f32ff..a0c899b00 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -43,6 +43,18 @@ def get_model(self): ''' return self.xcvr_eeprom.read(consts.VENDOR_PART_NO_FIELD) + def get_cable_type(self): + ''' + This function returns the cable type of the module + ''' + return "Length Cable Assembly(m)" + + def get_cable_length(self): + ''' + This function returns the cable length of the module + ''' + return self.xcvr_eeprom.read(consts.LENGTH_ASSEMBLY_FIELD) + def get_vendor_rev(self): ''' This function returns the revision level for part number provided by vendor @@ -146,7 +158,6 @@ def get_transceiver_info(self): "encoding": "N/A", # Not supported "ext_identifier": "%s (%sW Max)" % (power_class, max_power), "ext_rateselect_compliance": "N/A", # Not supported - "cable_type": "Length Cable Assembly(m)", "cable_length": float(admin_info[consts.LENGTH_ASSEMBLY_FIELD]), "nominal_bit_rate": 0, # Not supported "vendor_date": admin_info[consts.VENDOR_DATE_FIELD], @@ -160,6 +171,7 @@ def get_transceiver_info(self): xcvr_info['media_lane_count'] = self.get_media_lane_count() xcvr_info['host_lane_assignment_option'] = self.get_host_lane_assignment_option() xcvr_info['media_lane_assignment_option'] = self.get_media_lane_assignment_option() + xcvr_info['cable_type'] = self.get_cable_type() apsel_dict = self.get_active_apsel_hostlane() for lane in range(1, self.NUM_CHANNELS+1): xcvr_info["%s%d" % ("active_apsel_hostlane", lane)] = \ diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index 5b072deb8..8f6e3b9df 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -32,6 +32,19 @@ def test_get_model(self, mock_response, expected): result = self.api.get_model() assert result == expected + def test_get_cable_type(self): + assert self.api.get_cable_type() == "Length Cable Assembly(m)" + + @pytest.mark.parametrize("mock_response, expected", [ + ("0.0", "0.0"), + ("1.2", "1.2") + ]) + def test_get_cable_length(self, mock_response, expected): + self.api.xcvr_eeprom.read = MagicMock() + self.api.xcvr_eeprom.read.return_value = mock_response + result = self.api.get_cable_length() + assert result == expected + @pytest.mark.parametrize("mock_response, expected", [ ("0.0", "0.0"), ("1.2", "1.2") From ecc3db4841cff8a227972f6fe8a2ac941492a0cb Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Wed, 29 Nov 2023 22:35:22 +0000 Subject: [PATCH 2/2] Renamed get_cable_type to get_cable_length_type --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 4 ++-- tests/sonic_xcvr/test_cmis.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index a0c899b00..a9c4c5b34 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -43,7 +43,7 @@ def get_model(self): ''' return self.xcvr_eeprom.read(consts.VENDOR_PART_NO_FIELD) - def get_cable_type(self): + def get_cable_length_type(self): ''' This function returns the cable type of the module ''' @@ -171,7 +171,7 @@ def get_transceiver_info(self): xcvr_info['media_lane_count'] = self.get_media_lane_count() xcvr_info['host_lane_assignment_option'] = self.get_host_lane_assignment_option() xcvr_info['media_lane_assignment_option'] = self.get_media_lane_assignment_option() - xcvr_info['cable_type'] = self.get_cable_type() + xcvr_info['cable_type'] = self.get_cable_length_type() apsel_dict = self.get_active_apsel_hostlane() for lane in range(1, self.NUM_CHANNELS+1): xcvr_info["%s%d" % ("active_apsel_hostlane", lane)] = \ diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index 8f6e3b9df..95cf1a994 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -32,8 +32,8 @@ def test_get_model(self, mock_response, expected): result = self.api.get_model() assert result == expected - def test_get_cable_type(self): - assert self.api.get_cable_type() == "Length Cable Assembly(m)" + def test_get_cable_length_type(self): + assert self.api.get_cable_length_type() == "Length Cable Assembly(m)" @pytest.mark.parametrize("mock_response, expected", [ ("0.0", "0.0"),