Final round of moving modules to new import error msg (#51852)

* Final round of moving modules to new import error msg

* readd URL to jenkins install guide

* fix unit tests
This commit is contained in:
Jordan Borean 2019-02-08 10:07:01 +10:00 committed by GitHub
parent ffbc9d99de
commit a39c4ad464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 292 additions and 150 deletions

View file

@ -28,8 +28,10 @@
import os
import re
import traceback
from ansible.module_utils.ansible_release import __version__
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.cloud import CloudRetry
from ansible.module_utils.six import string_types, binary_type, text_type
@ -38,18 +40,22 @@ from ansible.module_utils.common.dict_transformations import (
_camel_to_snake, _snake_to_camel,
)
BOTO_IMP_ERR = None
try:
import boto
import boto.ec2 # boto does weird import stuff
HAS_BOTO = True
except ImportError:
BOTO_IMP_ERR = traceback.format_exc()
HAS_BOTO = False
BOTO3_IMP_ERR = None
try:
import boto3
import botocore
HAS_BOTO3 = True
except Exception:
BOTO3_IMP_ERR = traceback.format_exc()
HAS_BOTO3 = False
try:
@ -253,7 +259,7 @@ def get_aws_connection_info(module, boto3=False):
if not region:
region = boto.config.get('Boto', 'ec2_region')
else:
module.fail_json(msg="boto is required for this module. Please install boto and try again")
module.fail_json(msg=missing_required_lib('boto'), exception=BOTO_IMP_ERR)
elif HAS_BOTO3:
# here we don't need to make an additional call, will default to 'us-east-1' if the below evaluates to None.
try:
@ -261,7 +267,7 @@ def get_aws_connection_info(module, boto3=False):
except botocore.exceptions.ProfileNotFound as e:
pass
else:
module.fail_json(msg="Boto3 is required for this module. Please install boto3 and try again")
module.fail_json(msg=missing_required_lib('boto3'), exception=BOTO3_IMP_ERR)
if not security_token:
if os.environ.get('AWS_SECURITY_TOKEN'):