Do not use fully qualified module_utils imports (#63101)

This commit is contained in:
Martin Krizek 2019-10-09 11:30:43 +02:00 committed by GitHub
parent 9f9afcb203
commit f72d4d2339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 16 deletions

View file

@ -325,9 +325,7 @@ try:
except ImportError: except ImportError:
HAS_BOTO3 = False HAS_BOTO3 = False
import ansible.module_utils.ec2 from ansible.module_utils.ec2 import ansible_dict_to_boto3_tag_list, AWSRetry, boto3_conn, boto_exception, ec2_argument_spec, get_aws_connection_info
# import a class, otherwise we'll use a fully qualified path
from ansible.module_utils.ec2 import AWSRetry, boto_exception
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native from ansible.module_utils._text import to_bytes, to_native
@ -621,7 +619,7 @@ def get_stack_facts(cfn, stack_name):
def main(): def main():
argument_spec = ansible.module_utils.ec2.ec2_argument_spec() argument_spec = ec2_argument_spec()
argument_spec.update(dict( argument_spec.update(dict(
stack_name=dict(required=True), stack_name=dict(required=True),
template_parameters=dict(required=False, type='dict', default={}), template_parameters=dict(required=False, type='dict', default={}),
@ -713,7 +711,7 @@ def main():
stack_params['Parameters'].append({'ParameterKey': k, 'ParameterValue': str(v)}) stack_params['Parameters'].append({'ParameterKey': k, 'ParameterValue': str(v)})
if isinstance(module.params.get('tags'), dict): 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'): if module.params.get('role_arn'):
stack_params['RoleARN'] = module.params['role_arn'] stack_params['RoleARN'] = module.params['role_arn']
@ -721,8 +719,8 @@ def main():
result = {} result = {}
try: try:
region, ec2_url, aws_connect_kwargs = ansible.module_utils.ec2.get_aws_connection_info(module, boto3=True) region, ec2_url, aws_connect_kwargs = 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) cfn = boto3_conn(module, conn_type='client', resource='cloudformation', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except botocore.exceptions.NoCredentialsError as e: except botocore.exceptions.NoCredentialsError as e:
module.fail_json(msg=boto_exception(e)) module.fail_json(msg=boto_exception(e))

View file

@ -74,9 +74,8 @@ try:
except ImportError: except ImportError:
pass pass
import ansible.module_utils.ec2
from ansible.module_utils.basic import AnsibleModule 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): 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')) module.fail_json(msg='Found botocore in version {0}, but >= {1} is required for TTL support'.format(botocore.__version__, '1.5.24'))
try: try:
region, ec2_url, aws_connect_kwargs = ansible.module_utils.ec2.get_aws_connection_info(module, boto3=True) region, ec2_url, aws_connect_kwargs = 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) dbclient = boto3_conn(module, conn_type='client', resource='dynamodb', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except botocore.exceptions.NoCredentialsError as e: except botocore.exceptions.NoCredentialsError as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))

View file

@ -99,7 +99,7 @@ RETURN = '''
#only defaults #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.basic import AnsibleModule
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
import ansible.module_utils.influxdb as influx import ansible.module_utils.influxdb as influx
@ -114,7 +114,7 @@ def find_user(module, client, user_name):
if user['user'] == user_name: if user['user'] == user_name:
user_result = user user_result = user
break 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)) module.fail_json(msg=to_native(e))
return user_result return user_result
@ -126,7 +126,7 @@ def check_user_password(module, client, user_name, user_password):
except influx.exceptions.InfluxDBClientError as e: except influx.exceptions.InfluxDBClientError as e:
if e.code == 401: if e.code == 401:
return False return False
except ansible.module_utils.urls.ConnectionError as e: except ConnectionError as e:
module.fail_json(msg=to_native(e)) module.fail_json(msg=to_native(e))
finally: finally:
# restore previous user # restore previous user
@ -138,7 +138,7 @@ def set_user_password(module, client, user_name, user_password):
if not module.check_mode: if not module.check_mode:
try: try:
client.set_user_password(user_name, user_password) 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)) 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: if not module.check_mode:
try: try:
client.create_user(user_name, user_password, admin) 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)) module.fail_json(msg=to_native(e))