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

is_boto3_error_code - support sets and tuples #1829

Merged
Merged
Changes from 1 commit
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
Next Next commit
is_boto3_error_code - support sets and tuples
tremble committed Nov 22, 2023
commit d042c4cfacf847de82174b451f20940825b94eb5
2 changes: 1 addition & 1 deletion plugins/module_utils/botocore.py
Original file line number Diff line number Diff line change
@@ -335,7 +335,7 @@ def is_boto3_error_code(code, e=None):
import sys

dummy, e, dummy = sys.exc_info()
if not isinstance(code, list):
if not isinstance(code, (list, tuple, set)):
code = [code]
if isinstance(e, ClientError) and e.response["Error"]["Code"] in code:
return ClientError
68 changes: 68 additions & 0 deletions tests/unit/module_utils/botocore/test_is_boto3_error_code.py
Original file line number Diff line number Diff line change
@@ -209,3 +209,71 @@ def test_is_boto3_error_code_multiple__pass__botocore(self):
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ == "NeverEverRaisedException"

def test_is_boto3_error_code_tuple__pass__client(self):
passed_exception = self._make_denied_exception()
returned_exception = is_boto3_error_code(("NotAccessDenied", "AccessDenied"), e=passed_exception)
assert isinstance(passed_exception, returned_exception)
assert issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ != "NeverEverRaisedException"

returned_exception = is_boto3_error_code(("AccessDenied", "NotAccessDenied"), e=passed_exception)
assert isinstance(passed_exception, returned_exception)
assert issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ != "NeverEverRaisedException"

def test_is_boto3_error_code_tuple__pass__unexpected(self):
passed_exception = self._make_unexpected_exception()
returned_exception = is_boto3_error_code(("NotAccessDenied", "AccessDenied"), e=passed_exception)
assert not isinstance(passed_exception, returned_exception)
assert not issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ == "NeverEverRaisedException"

def test_is_boto3_error_code_tuple__pass__botocore(self):
passed_exception = self._make_botocore_exception()
returned_exception = is_boto3_error_code(("NotAccessDenied", "AccessDenied"), e=passed_exception)
assert not isinstance(passed_exception, returned_exception)
assert not issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ == "NeverEverRaisedException"

def test_is_boto3_error_code_set__pass__client(self):
passed_exception = self._make_denied_exception()
returned_exception = is_boto3_error_code({"NotAccessDenied", "AccessDenied"}, e=passed_exception)
assert isinstance(passed_exception, returned_exception)
assert issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ != "NeverEverRaisedException"

returned_exception = is_boto3_error_code({"AccessDenied", "NotAccessDenied"}, e=passed_exception)
assert isinstance(passed_exception, returned_exception)
assert issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ != "NeverEverRaisedException"

def test_is_boto3_error_code_set__pass__unexpected(self):
passed_exception = self._make_unexpected_exception()
returned_exception = is_boto3_error_code({"NotAccessDenied", "AccessDenied"}, e=passed_exception)
assert not isinstance(passed_exception, returned_exception)
assert not issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ == "NeverEverRaisedException"

def test_is_boto3_error_code_set__pass__botocore(self):
passed_exception = self._make_botocore_exception()
returned_exception = is_boto3_error_code({"NotAccessDenied", "AccessDenied"}, e=passed_exception)
assert not isinstance(passed_exception, returned_exception)
assert not issubclass(returned_exception, botocore.exceptions.ClientError)
assert not issubclass(returned_exception, botocore.exceptions.BotoCoreError)
assert issubclass(returned_exception, Exception)
assert returned_exception.__name__ == "NeverEverRaisedException"