Skip to content

Commit

Permalink
APIs to help in finding NPU SI settings (#410)
Browse files Browse the repository at this point in the history
* APIs to help in finding NPU SI settings

Signed-off-by: Mihir Patel <[email protected]>

* Renamed get_cable_type to get_cable_length_type

---------

Signed-off-by: Mihir Patel <[email protected]>
  • Loading branch information
mihirpat1 authored and mssonicbld committed Feb 2, 2024
1 parent 7c2ad66 commit c8617b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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)] = \
Expand Down
13 changes: 13 additions & 0 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c8617b8

Please sign in to comment.