Skip to content

Commit

Permalink
Change get_transceiver_info_firmware_versions return type to dict (so…
Browse files Browse the repository at this point in the history
…nic-net#440)

Signed-off-by: Mihir Patel <[email protected]>
  • Loading branch information
mihirpat1 authored Feb 16, 2024
1 parent 888075d commit 796e89a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 7 additions & 6 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ def get_transceiver_info(self):
xcvr_info['cmis_rev'] = self.get_cmis_rev()
xcvr_info['specification_compliance'] = self.get_module_media_type()

xcvr_info['active_firmware'], xcvr_info['inactive_firmware'] = self.get_transceiver_info_firmware_versions()

# In normal case will get a valid value for each of the fields. If get a 'None' value
# means there was a failure while reading the EEPROM, either because the EEPROM was
# not ready yet or experincing some other issues. It shouldn't return a dict with a
Expand All @@ -194,15 +192,18 @@ def get_transceiver_info(self):
return xcvr_info

def get_transceiver_info_firmware_versions(self):
return_dict = {"active_firmware" : "N/A", "inactive_firmware" : "N/A"}
result = self.get_module_fw_info()
if result is None:
return ["N/A", "N/A"]
return return_dict
try:
( _, _, _, _, _, _, _, _, ActiveFirmware, InactiveFirmware) = result['result']
except (ValueError, TypeError):
return ["N/A", "N/A"]

return [ActiveFirmware, InactiveFirmware]
return return_dict

return_dict["active_firmware"] = ActiveFirmware
return_dict["inactive_firmware"] = InactiveFirmware
return return_dict

def get_transceiver_bulk_status(self):
temp = self.get_module_temperature()
Expand Down
14 changes: 9 additions & 5 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,9 +1294,7 @@ def test_module_fw_upgrade(self, input_param, mock_response, expected):
'nominal_bit_rate': 0,
'specification_compliance': 'sm_media_interface',
'application_advertisement': 'N/A',
'active_firmware': '0.3.0',
'media_lane_count': 1,
'inactive_firmware': '0.2.0',
'vendor_rev': '0.0',
'host_electrical_interface': '400GAUI-8 C2M (Annex 120E)',
'vendor_oui': 'xx-xx-xx',
Expand Down Expand Up @@ -2374,13 +2372,19 @@ def mock_read_raw(offset, size):
assert 0, traceback.format_exc()
run_num -= 1

def test_get_transceiver_info_firmware_versions_negative_tests(self):
def test_get_transceiver_info_firmware_versions(self):
self.api.get_module_fw_info = MagicMock()
self.api.get_module_fw_info.return_value = None
expected_result = {"active_firmware" : "N/A", "inactive_firmware" : "N/A"}
result = self.api.get_transceiver_info_firmware_versions()
assert result == ["N/A", "N/A"]
assert result == expected_result

self.api.get_module_fw_info = MagicMock()
self.api.get_module_fw_info.side_effect = {'result': TypeError}
result = self.api.get_transceiver_info_firmware_versions()
assert result == ["N/A", "N/A"]
assert result == expected_result

expected_result = {"active_firmware" : "2.0.0", "inactive_firmware" : "1.0.0"}
self.api.get_module_fw_info.side_effect = [{'result': ( '', '', '', '', '', '', '', '','2.0.0', '1.0.0')}]
result = self.api.get_transceiver_info_firmware_versions()
assert result == expected_result

0 comments on commit 796e89a

Please sign in to comment.