Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action] [PR:440] Change get_transceiver_info_firmware_versions return type to dict (#440) #443

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -169,8 +169,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 @@ -182,15 +180,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 @@ -1281,9 +1281,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 @@ -2361,13 +2359,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
Loading