From f72d4d233901136f0d262b6742cb85df3d8efa08 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 9 Oct 2019 11:30:43 +0200 Subject: [PATCH] Do not use fully qualified module_utils imports (#63101) --- lib/ansible/modules/cloud/amazon/cloudformation.py | 12 +++++------- lib/ansible/modules/cloud/amazon/dynamodb_ttl.py | 7 +++---- .../modules/database/influxdb/influxdb_user.py | 10 +++++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/cloudformation.py b/lib/ansible/modules/cloud/amazon/cloudformation.py index 0ce9e0484b..365114203f 100644 --- a/lib/ansible/modules/cloud/amazon/cloudformation.py +++ b/lib/ansible/modules/cloud/amazon/cloudformation.py @@ -325,9 +325,7 @@ try: except ImportError: HAS_BOTO3 = False -import ansible.module_utils.ec2 -# import a class, otherwise we'll use a fully qualified path -from ansible.module_utils.ec2 import AWSRetry, boto_exception +from ansible.module_utils.ec2 import ansible_dict_to_boto3_tag_list, AWSRetry, boto3_conn, boto_exception, ec2_argument_spec, get_aws_connection_info from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_bytes, to_native @@ -621,7 +619,7 @@ def get_stack_facts(cfn, stack_name): def main(): - argument_spec = ansible.module_utils.ec2.ec2_argument_spec() + argument_spec = ec2_argument_spec() argument_spec.update(dict( stack_name=dict(required=True), template_parameters=dict(required=False, type='dict', default={}), @@ -713,7 +711,7 @@ def main(): stack_params['Parameters'].append({'ParameterKey': k, 'ParameterValue': str(v)}) if isinstance(module.params.get('tags'), dict): - stack_params['Tags'] = ansible.module_utils.ec2.ansible_dict_to_boto3_tag_list(module.params['tags']) + stack_params['Tags'] = ansible_dict_to_boto3_tag_list(module.params['tags']) if module.params.get('role_arn'): stack_params['RoleARN'] = module.params['role_arn'] @@ -721,8 +719,8 @@ def main(): result = {} try: - region, ec2_url, aws_connect_kwargs = ansible.module_utils.ec2.get_aws_connection_info(module, boto3=True) - cfn = ansible.module_utils.ec2.boto3_conn(module, conn_type='client', resource='cloudformation', region=region, endpoint=ec2_url, **aws_connect_kwargs) + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) + cfn = boto3_conn(module, conn_type='client', resource='cloudformation', region=region, endpoint=ec2_url, **aws_connect_kwargs) except botocore.exceptions.NoCredentialsError as e: module.fail_json(msg=boto_exception(e)) diff --git a/lib/ansible/modules/cloud/amazon/dynamodb_ttl.py b/lib/ansible/modules/cloud/amazon/dynamodb_ttl.py index 18eb49e4c9..66e6dca0f8 100644 --- a/lib/ansible/modules/cloud/amazon/dynamodb_ttl.py +++ b/lib/ansible/modules/cloud/amazon/dynamodb_ttl.py @@ -74,9 +74,8 @@ try: except ImportError: pass -import ansible.module_utils.ec2 from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.ec2 import ec2_argument_spec, camel_dict_to_snake_dict, HAS_BOTO3 +from ansible.module_utils.ec2 import HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict, ec2_argument_spec, get_aws_connection_info def get_current_ttl_state(c, table_name): @@ -137,8 +136,8 @@ def main(): module.fail_json(msg='Found botocore in version {0}, but >= {1} is required for TTL support'.format(botocore.__version__, '1.5.24')) try: - region, ec2_url, aws_connect_kwargs = ansible.module_utils.ec2.get_aws_connection_info(module, boto3=True) - dbclient = ansible.module_utils.ec2.boto3_conn(module, conn_type='client', resource='dynamodb', region=region, endpoint=ec2_url, **aws_connect_kwargs) + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) + dbclient = boto3_conn(module, conn_type='client', resource='dynamodb', region=region, endpoint=ec2_url, **aws_connect_kwargs) except botocore.exceptions.NoCredentialsError as e: module.fail_json(msg=str(e)) diff --git a/lib/ansible/modules/database/influxdb/influxdb_user.py b/lib/ansible/modules/database/influxdb/influxdb_user.py index ed0728cbfa..3a22fac0e6 100644 --- a/lib/ansible/modules/database/influxdb/influxdb_user.py +++ b/lib/ansible/modules/database/influxdb/influxdb_user.py @@ -99,7 +99,7 @@ RETURN = ''' #only defaults ''' -import ansible.module_utils.urls +from ansible.module_utils.urls import ConnectionError from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_native import ansible.module_utils.influxdb as influx @@ -114,7 +114,7 @@ def find_user(module, client, user_name): if user['user'] == user_name: user_result = user break - except (ansible.module_utils.urls.ConnectionError, influx.exceptions.InfluxDBClientError) as e: + except (ConnectionError, influx.exceptions.InfluxDBClientError) as e: module.fail_json(msg=to_native(e)) return user_result @@ -126,7 +126,7 @@ def check_user_password(module, client, user_name, user_password): except influx.exceptions.InfluxDBClientError as e: if e.code == 401: return False - except ansible.module_utils.urls.ConnectionError as e: + except ConnectionError as e: module.fail_json(msg=to_native(e)) finally: # restore previous user @@ -138,7 +138,7 @@ def set_user_password(module, client, user_name, user_password): if not module.check_mode: try: client.set_user_password(user_name, user_password) - except ansible.module_utils.urls.ConnectionError as e: + except ConnectionError as e: module.fail_json(msg=to_native(e)) @@ -146,7 +146,7 @@ def create_user(module, client, user_name, user_password, admin): if not module.check_mode: try: client.create_user(user_name, user_password, admin) - except ansible.module_utils.urls.ConnectionError as e: + except ConnectionError as e: module.fail_json(msg=to_native(e))