From c8617b8045053826d30b10d138202cb56e9c6d64 Mon Sep 17 00:00:00 2001 From: mihirpat1 <112018033+mihirpat1@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:45:07 -0800 Subject: [PATCH] APIs to help in finding NPU SI settings (#410) * APIs to help in finding NPU SI settings Signed-off-by: Mihir Patel * Renamed get_cable_type to get_cable_length_type --------- 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..a9c4c5b34 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_length_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_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 5b072deb8..95cf1a994 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_length_type(self): + assert self.api.get_cable_length_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")