diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index a677f32ff..925e3c098 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -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 @@ -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() diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index 5b072deb8..f243f2808 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -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', @@ -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