From 0bda419f66fa761408533228c36a9d2fbccc5e8f Mon Sep 17 00:00:00 2001 From: "Ryan S. Brown" Date: Wed, 14 Sep 2016 11:33:29 -0400 Subject: [PATCH] Allow AWSRetry class to be created without boto3/botocore installed --- lib/ansible/module_utils/ec2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index 4e654c8f22..f9f18c1227 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -58,8 +58,18 @@ class AnsibleAWSError(Exception): pass +def _botocore_exception_maybe(): + """ + Allow for boto3 not being installed when using these utils by wrapping + botocore.exceptions instead of assigning from it directly. + """ + if HAS_BOTO3: + return botocore.exceptions.ClientError + return type(None) + + class AWSRetry(CloudRetry): - base_class = botocore.exceptions.ClientError + base_class = _botocore_exception_maybe() @staticmethod def status_code_from_exception(error):