Skip to content

Commit cf4c6af

Browse files
authored
CmisApi::get_application_advertisement catch AttributeError as well (#316)
- Description Catch both TypeError and AttributeError in CmisApi::get_application_advertisement because an AttributeError will be thrown when updating a dict with None. - Motivation and Context Fix issue found during automation tests - How Has This Been Tested? Manually test Added new unit test Signed-off-by: Stephen Sun <stephens@nvidia.com>
1 parent 86bab38 commit cf4c6af

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sonic_platform_base/sonic_xcvr/api/public/cmis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ def get_application_advertisement(self):
18891889
# Read the application advertisement in page01
18901890
try:
18911891
dic.update(self.xcvr_eeprom.read(consts.APPLS_ADVT_FIELD_PAGE01))
1892-
except TypeError as e:
1892+
except (TypeError, AttributeError) as e:
18931893
logger.error('Failed to read APPLS_ADVT_FIELD_PAGE01: ' + str(e))
18941894
return ret
18951895

tests/sonic_xcvr/test_cmis.py

+6
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,12 @@ def test_get_application_advertisement(self):
20192019
assert result[1]['media_lane_count'] == 4
20202020
assert result[1]['host_lane_assignment_options'] == 0x01
20212021

2022+
def test_get_application_advertisement_non_support(self):
2023+
self.api.xcvr_eeprom.read = MagicMock(return_value = None)
2024+
self.api.is_flat_memory = MagicMock(return_value = False)
2025+
result = self.api.get_application_advertisement()
2026+
assert result == {}
2027+
20222028
def test_get_application(self):
20232029
self.api.xcvr_eeprom.read = MagicMock()
20242030
self.api.xcvr_eeprom.read.return_value = 0x20

0 commit comments

Comments
 (0)