Skip to content

Commit

Permalink
CmisApi::get_application_advertisement catch AttributeError as well (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
stephenxs authored Oct 30, 2022
1 parent 86bab38 commit cf4c6af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ def get_application_advertisement(self):
# Read the application advertisement in page01
try:
dic.update(self.xcvr_eeprom.read(consts.APPLS_ADVT_FIELD_PAGE01))
except TypeError as e:
except (TypeError, AttributeError) as e:
logger.error('Failed to read APPLS_ADVT_FIELD_PAGE01: ' + str(e))
return ret

Expand Down
6 changes: 6 additions & 0 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,12 @@ def test_get_application_advertisement(self):
assert result[1]['media_lane_count'] == 4
assert result[1]['host_lane_assignment_options'] == 0x01

def test_get_application_advertisement_non_support(self):
self.api.xcvr_eeprom.read = MagicMock(return_value = None)
self.api.is_flat_memory = MagicMock(return_value = False)
result = self.api.get_application_advertisement()
assert result == {}

def test_get_application(self):
self.api.xcvr_eeprom.read = MagicMock()
self.api.xcvr_eeprom.read.return_value = 0x20
Expand Down

0 comments on commit cf4c6af

Please sign in to comment.