Skip to content

Commit 5430f6f

Browse files
mihirpat1mssonicbld
authored andcommitted
Change get_transceiver_info_firmware_versions return type to dict (#440)
Signed-off-by: Mihir Patel <[email protected]>
1 parent 9bf5a17 commit 5430f6f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

sonic_platform_base/sonic_xcvr/api/public/cmis.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ def get_transceiver_info(self):
181181
xcvr_info['cmis_rev'] = self.get_cmis_rev()
182182
xcvr_info['specification_compliance'] = self.get_module_media_type()
183183

184-
xcvr_info['active_firmware'], xcvr_info['inactive_firmware'] = self.get_transceiver_info_firmware_versions()
185-
186184
# In normal case will get a valid value for each of the fields. If get a 'None' value
187185
# means there was a failure while reading the EEPROM, either because the EEPROM was
188186
# not ready yet or experincing some other issues. It shouldn't return a dict with a
@@ -194,15 +192,18 @@ def get_transceiver_info(self):
194192
return xcvr_info
195193

196194
def get_transceiver_info_firmware_versions(self):
195+
return_dict = {"active_firmware" : "N/A", "inactive_firmware" : "N/A"}
197196
result = self.get_module_fw_info()
198197
if result is None:
199-
return ["N/A", "N/A"]
198+
return return_dict
200199
try:
201200
( _, _, _, _, _, _, _, _, ActiveFirmware, InactiveFirmware) = result['result']
202201
except (ValueError, TypeError):
203-
return ["N/A", "N/A"]
204-
205-
return [ActiveFirmware, InactiveFirmware]
202+
return return_dict
203+
204+
return_dict["active_firmware"] = ActiveFirmware
205+
return_dict["inactive_firmware"] = InactiveFirmware
206+
return return_dict
206207

207208
def get_transceiver_bulk_status(self):
208209
temp = self.get_module_temperature()

tests/sonic_xcvr/test_cmis.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,7 @@ def test_module_fw_upgrade(self, input_param, mock_response, expected):
12941294
'nominal_bit_rate': 0,
12951295
'specification_compliance': 'sm_media_interface',
12961296
'application_advertisement': 'N/A',
1297-
'active_firmware': '0.3.0',
12981297
'media_lane_count': 1,
1299-
'inactive_firmware': '0.2.0',
13001298
'vendor_rev': '0.0',
13011299
'host_electrical_interface': '400GAUI-8 C2M (Annex 120E)',
13021300
'vendor_oui': 'xx-xx-xx',
@@ -2374,13 +2372,19 @@ def mock_read_raw(offset, size):
23742372
assert 0, traceback.format_exc()
23752373
run_num -= 1
23762374

2377-
def test_get_transceiver_info_firmware_versions_negative_tests(self):
2375+
def test_get_transceiver_info_firmware_versions(self):
23782376
self.api.get_module_fw_info = MagicMock()
23792377
self.api.get_module_fw_info.return_value = None
2378+
expected_result = {"active_firmware" : "N/A", "inactive_firmware" : "N/A"}
23802379
result = self.api.get_transceiver_info_firmware_versions()
2381-
assert result == ["N/A", "N/A"]
2380+
assert result == expected_result
23822381

23832382
self.api.get_module_fw_info = MagicMock()
23842383
self.api.get_module_fw_info.side_effect = {'result': TypeError}
23852384
result = self.api.get_transceiver_info_firmware_versions()
2386-
assert result == ["N/A", "N/A"]
2385+
assert result == expected_result
2386+
2387+
expected_result = {"active_firmware" : "2.0.0", "inactive_firmware" : "1.0.0"}
2388+
self.api.get_module_fw_info.side_effect = [{'result': ( '', '', '', '', '', '', '', '','2.0.0', '1.0.0')}]
2389+
result = self.api.get_transceiver_info_firmware_versions()
2390+
assert result == expected_result

0 commit comments

Comments
 (0)