From bb33e078c4f99131e5d19db23993abbd58f46114 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 18 Oct 2022 10:15:13 +0200 Subject: [PATCH] Linting cleanup --- changelogs/fragments/1181-linting.yml | 15 +++++++ plugins/inventory/aws_ec2.py | 2 +- plugins/module_utils/cloud.py | 1 - plugins/modules/autoscaling_group.py | 4 +- plugins/modules/cloudtrail_info.py | 1 - plugins/modules/cloudwatchlogs_log_group.py | 4 +- plugins/modules/ec2_eip.py | 6 +-- plugins/modules/kms_key_info.py | 2 +- plugins/modules/lambda.py | 44 +------------------ plugins/modules/lambda_execute.py | 2 +- plugins/modules/rds_cluster_snapshot.py | 4 +- plugins/modules/rds_instance.py | 22 ++++------ plugins/modules/rds_instance_snapshot.py | 4 +- plugins/modules/route53_health_check.py | 2 - plugins/modules/s3_object_info.py | 14 +++--- .../test_minimal_versions.py | 1 - tests/unit/module_utils/policy/test_py3cmp.py | 4 +- .../policy/test_simple_hashable_policy.py | 1 - tests/unit/module_utils/test_s3.py | 2 - .../ec2_instance/test_determine_iam_role.py | 8 ++-- tests/unit/plugins/modules/test_ec2_ami.py | 6 +-- 21 files changed, 55 insertions(+), 94 deletions(-) create mode 100644 changelogs/fragments/1181-linting.yml diff --git a/changelogs/fragments/1181-linting.yml b/changelogs/fragments/1181-linting.yml new file mode 100644 index 00000000000..714f36d592d --- /dev/null +++ b/changelogs/fragments/1181-linting.yml @@ -0,0 +1,15 @@ +minor_changes: +- aws_ec2 inventory - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- cloud module_utils - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- autoscaling_group - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- cloudtrail_info - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- cloudwatchlogs_log_group - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- ec2_eip - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- kms_key_info - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- lambda - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- lambda_execute - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- rds_cluster_snapshot - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- rds_instance - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- rds_instance_snapshot - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- route53_health_check - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). +- s3_object_info - minor linting fixes (https://github.com/ansible-collections/amazon.aws/pull/1181). diff --git a/plugins/inventory/aws_ec2.py b/plugins/inventory/aws_ec2.py index c7adcb873da..6452f003f98 100644 --- a/plugins/inventory/aws_ec2.py +++ b/plugins/inventory/aws_ec2.py @@ -737,7 +737,7 @@ def prepare_host_vars(cls, original_host_vars, hostvars_prefix=None, hostvars_su if hostvars_prefix or hostvars_suffix: for hostvar, hostval in host_vars.copy().items(): - del(host_vars[hostvar]) + del host_vars[hostvar] if hostvars_prefix: hostvar = hostvars_prefix + hostvar if hostvars_suffix: diff --git a/plugins/module_utils/cloud.py b/plugins/module_utils/cloud.py index e622c484675..38b98c848f3 100644 --- a/plugins/module_utils/cloud.py +++ b/plugins/module_utils/cloud.py @@ -32,7 +32,6 @@ import time import functools import random -import ansible.module_utils.common.warnings as ansible_warnings class BackoffIterator: diff --git a/plugins/modules/autoscaling_group.py b/plugins/modules/autoscaling_group.py index fcc523d57ae..2ec191698fc 100644 --- a/plugins/modules/autoscaling_group.py +++ b/plugins/modules/autoscaling_group.py @@ -1108,9 +1108,7 @@ def create_autoscaling_group(connection): load_balancers = module.params['load_balancers'] target_group_arns = module.params['target_group_arns'] availability_zones = module.params['availability_zones'] - launch_config_name = module.params.get('launch_config_name') launch_template = module.params.get('launch_template') - mixed_instances_policy = module.params.get('mixed_instances_policy') min_size = module.params['min_size'] max_size = module.params['max_size'] max_instance_lifetime = module.params.get('max_instance_lifetime') @@ -1360,7 +1358,7 @@ def create_autoscaling_group(connection): else: try: ag['LaunchConfigurationName'] = as_group['LaunchConfigurationName'] - except Exception: + except KeyError: launch_template = as_group['LaunchTemplate'] # Prefer LaunchTemplateId over Name as it's more specific. Only one can be used for update_asg. ag['LaunchTemplate'] = {"LaunchTemplateId": launch_template['LaunchTemplateId'], "Version": launch_template['Version']} diff --git a/plugins/modules/cloudtrail_info.py b/plugins/modules/cloudtrail_info.py index a696ba71119..d47d4f075e6 100644 --- a/plugins/modules/cloudtrail_info.py +++ b/plugins/modules/cloudtrail_info.py @@ -162,7 +162,6 @@ from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict diff --git a/plugins/modules/cloudwatchlogs_log_group.py b/plugins/modules/cloudwatchlogs_log_group.py index ee6df826e70..ec1fdd4e14f 100644 --- a/plugins/modules/cloudwatchlogs_log_group.py +++ b/plugins/modules/cloudwatchlogs_log_group.py @@ -176,8 +176,8 @@ def input_retention_policy(client, log_group_name, retention, module): permited_values = [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653] if retention in permited_values: - response = client.put_retention_policy(logGroupName=log_group_name, - retentionInDays=retention) + client.put_retention_policy(logGroupName=log_group_name, + retentionInDays=retention) else: delete_log_group(client=client, log_group_name=log_group_name, module=module) module.fail_json(msg="Invalid retention value. Valid values are: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]") diff --git a/plugins/modules/ec2_eip.py b/plugins/modules/ec2_eip.py index 4c3094b98a9..41b33f7d30f 100644 --- a/plugins/modules/ec2_eip.py +++ b/plugins/modules/ec2_eip.py @@ -282,11 +282,11 @@ def disassociate_ip_and_device(ec2, module, address, device_id, check_mode, is_i if not check_mode: try: if address['Domain'] == 'vpc': - res = ec2.disassociate_address( + ec2.disassociate_address( AssociationId=address['AssociationId'], aws_retry=True ) else: - res = ec2.disassociate_address( + ec2.disassociate_address( PublicIp=address['PublicIp'], aws_retry=True ) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: @@ -390,7 +390,7 @@ def release_address(ec2, module, address, check_mode): # If we're in check mode, nothing else to do if not check_mode: try: - result = ec2.release_address(AllocationId=address['AllocationId'], aws_retry=True) + ec2.release_address(AllocationId=address['AllocationId'], aws_retry=True) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: module.fail_json_aws(e, msg="Couldn't release Elastic IP address") diff --git a/plugins/modules/kms_key_info.py b/plugins/modules/kms_key_info.py index ba8f30a2f60..bc888d34f49 100644 --- a/plugins/modules/kms_key_info.py +++ b/plugins/modules/kms_key_info.py @@ -363,7 +363,7 @@ def get_key_policy_with_backoff(connection, key_id, policy_name): def get_enable_key_rotation_with_backoff(connection, key_id): try: current_rotation_status = connection.get_key_rotation_status(KeyId=key_id) - except is_boto3_error_code(['AccessDeniedException', 'UnsupportedOperationException']) as e: + except is_boto3_error_code(['AccessDeniedException', 'UnsupportedOperationException']): return None return current_rotation_status.get('KeyRotationEnabled') diff --git a/plugins/modules/lambda.py b/plugins/modules/lambda.py index 7f8536cf3d1..1c6667f280b 100644 --- a/plugins/modules/lambda.py +++ b/plugins/modules/lambda.py @@ -401,48 +401,13 @@ except ImportError: pass # protected by AnsibleAWSModule -from ansible.module_utils._text import to_native from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags - - -def get_account_info(module): - """return the account information (account id and partition) we are currently working on - - get_account_info tries too find out the account that we are working - on. It's not guaranteed that this will be easy so we try in - several different ways. Giving either IAM or STS privileges to - the account should be enough to permit this. - """ - account_id = None - partition = None - try: - sts_client = module.client('sts', retry_decorator=AWSRetry.jittered_backoff()) - caller_id = sts_client.get_caller_identity(aws_retry=True) - account_id = caller_id.get('Account') - partition = caller_id.get('Arn').split(':')[1] - except (BotoCoreError, ClientError): - try: - iam_client = module.client('iam', retry_decorator=AWSRetry.jittered_backoff()) - arn, partition, service, reg, account_id, resource = iam_client.get_user(aws_retry=True)['User']['Arn'].split(':') - except is_boto3_error_code('AccessDenied') as e: - try: - except_msg = to_native(e.message) - except AttributeError: - except_msg = to_native(e) - m = re.search(r"arn:(aws(-([a-z\-]+))?):iam::([0-9]{12,32}):\w+/", except_msg) - if m is None: - module.fail_json_aws(e, msg="getting account information") - account_id = m.group(4) - partition = m.group(1) - except (BotoCoreError, ClientError) as e: # pylint: disable=duplicate-except - module.fail_json_aws(e, msg="getting account information") - - return account_id, partition +from ansible_collections.amazon.aws.plugins.module_utils.iam import get_aws_account_info def get_current_function(connection, function_name, qualifier=None): @@ -577,7 +542,6 @@ def _code_args(module, current_config): s3_object_version = module.params.get('s3_object_version') zip_file = module.params.get('zip_file') architectures = module.params.get('architecture') - checksum_match = False code_kwargs = {} @@ -665,10 +629,6 @@ def main(): runtime = module.params.get('runtime') role = module.params.get('role') handler = module.params.get('handler') - s3_bucket = module.params.get('s3_bucket') - s3_key = module.params.get('s3_key') - s3_object_version = module.params.get('s3_object_version') - zip_file = module.params.get('zip_file') description = module.params.get('description') timeout = module.params.get('timeout') memory_size = module.params.get('memory_size') @@ -700,7 +660,7 @@ def main(): role_arn = role else: # get account ID and assemble ARN - account_id, partition = get_account_info(module) + account_id, partition = get_aws_account_info(module) role_arn = 'arn:{0}:iam::{1}:role/{2}'.format(partition, account_id, role) # create list of layer version arn diff --git a/plugins/modules/lambda_execute.py b/plugins/modules/lambda_execute.py index 68fff52b77d..76faae42ddc 100644 --- a/plugins/modules/lambda_execute.py +++ b/plugins/modules/lambda_execute.py @@ -226,7 +226,7 @@ def main(): module.fail_json_aws(ce, msg="Client-side error when invoking Lambda, check inputs and specific error") except botocore.exceptions.ParamValidationError as ve: # pylint: disable=duplicate-except module.fail_json_aws(ve, msg="Parameters to `invoke` failed to validate") - except Exception as e: + except botocore.exceptions.BotoCoreError as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Unexpected failure while invoking Lambda function") results = { diff --git a/plugins/modules/rds_cluster_snapshot.py b/plugins/modules/rds_cluster_snapshot.py index ff712c4380a..f258066fbae 100644 --- a/plugins/modules/rds_cluster_snapshot.py +++ b/plugins/modules/rds_cluster_snapshot.py @@ -284,7 +284,7 @@ def copy_snapshot(params): method_params = get_parameters(params, 'copy_db_cluster_snapshot') if method_params.get('Tags'): method_params['Tags'] = ansible_dict_to_boto3_tag_list(method_params['Tags']) - result, changed = call_method(client, module, 'copy_db_cluster_snapshot', method_params) + _result, changed = call_method(client, module, 'copy_db_cluster_snapshot', method_params) return changed @@ -316,7 +316,7 @@ def create_snapshot(params): method_params = get_parameters(params, 'create_db_cluster_snapshot') if method_params.get('Tags'): method_params['Tags'] = ansible_dict_to_boto3_tag_list(method_params['Tags']) - snapshot, changed = call_method(client, module, 'create_db_cluster_snapshot', method_params) + _snapshot, changed = call_method(client, module, 'create_db_cluster_snapshot', method_params) return changed diff --git a/plugins/modules/rds_instance.py b/plugins/modules/rds_instance.py index 12fabc93aac..4ec1c125a03 100644 --- a/plugins/modules/rds_instance.py +++ b/plugins/modules/rds_instance.py @@ -909,7 +909,7 @@ def get_rds_method_attribute_name(instance, state, creation_source, read_replica def get_instance(client, module, db_instance_id): try: - for i in range(3): + for _i in range(3): try: instance = client.describe_db_instances(DBInstanceIdentifier=db_instance_id)['DBInstances'][0] instance['Tags'] = get_tags(client, module, instance['DBInstanceArn']) @@ -936,7 +936,7 @@ def get_final_snapshot(client, module, snapshot_identifier): if len(snapshots.get('DBSnapshots', [])) == 1: return snapshots['DBSnapshots'][0] return {} - except is_boto3_error_code('DBSnapshotNotFound') as e: # May not be using wait: True + except is_boto3_error_code('DBSnapshotNotFound'): # May not be using wait: True return {} except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg='Failed to retrieve information about the final snapshot') @@ -1128,10 +1128,6 @@ def validate_options(client, module, instance): read_replica = module.params['read_replica'] creation_source = module.params['creation_source'] source_instance = module.params['source_db_instance_identifier'] - if module.params['source_region'] is not None: - same_region = bool(module.params['source_region'] == module.params['region']) - else: - same_region = True if modified_id: modified_instance = get_instance(client, module, modified_id) @@ -1176,8 +1172,8 @@ def promote_replication_instance(client, module, instance, read_replica): # See https://awscli.amazonaws.com/v2/documentation/api/latest/reference/rds/describe-db-instances.html if bool(instance.get('StatusInfos')): try: - result, changed = call_method(client, module, method_name='promote_read_replica', - parameters={'DBInstanceIdentifier': instance['DBInstanceIdentifier']}) + _result, changed = call_method(client, module, method_name='promote_read_replica', + parameters={'DBInstanceIdentifier': instance['DBInstanceIdentifier']}) except is_boto3_error_message('DB Instance is not a read replica'): pass return changed @@ -1232,7 +1228,7 @@ def reboot_running_db_instance(client, module, instance): call_method(client, module, 'start_db_instance', parameters) if module.params.get('force_failover') is not None: parameters['ForceFailover'] = module.params['force_failover'] - results, changed = call_method(client, module, 'reboot_db_instance', parameters) + _results, changed = call_method(client, module, 'reboot_db_instance', parameters) return changed @@ -1242,9 +1238,9 @@ def start_or_stop_instance(client, module, instance, state): if state == 'stopped' and instance['DBInstanceStatus'] not in ['stopping', 'stopped']: if module.params['db_snapshot_identifier']: parameters['DBSnapshotIdentifier'] = module.params['db_snapshot_identifier'] - result, changed = call_method(client, module, 'stop_db_instance', parameters) + _result, changed = call_method(client, module, 'stop_db_instance', parameters) elif state == 'started' and instance['DBInstanceStatus'] not in ['available', 'starting', 'restarting']: - result, changed = call_method(client, module, 'start_db_instance', parameters) + _result, changed = call_method(client, module, 'start_db_instance', parameters) return changed @@ -1393,7 +1389,7 @@ def main(): # Exit on check_mode when parameters to modify if module.check_mode: module.exit_json(changed=True, **camel_dict_to_snake_dict(instance, ignore_list=['Tags', 'ProcessorFeatures'])) - result, changed = call_method(client, module, method_name, parameters_to_modify) + _result, changed = call_method(client, module, method_name, parameters_to_modify) instance_id = get_final_identifier(method_name, module) @@ -1409,7 +1405,7 @@ def main(): if changed: instance = get_instance(client, module, instance_id) if state != 'absent' and (instance or not module.check_mode): - for attempt_to_wait in range(0, 10): + for _wait_attempt in range(0, 10): instance = get_instance(client, module, instance_id) if instance: break diff --git a/plugins/modules/rds_instance_snapshot.py b/plugins/modules/rds_instance_snapshot.py index 0f779d8db13..fc63cea0aae 100644 --- a/plugins/modules/rds_instance_snapshot.py +++ b/plugins/modules/rds_instance_snapshot.py @@ -314,7 +314,7 @@ def create_snapshot(params): method_params = get_parameters(params, 'create_db_snapshot') if method_params.get('Tags'): method_params['Tags'] = ansible_dict_to_boto3_tag_list(method_params['Tags']) - snapshot, changed = call_method(client, module, 'create_db_snapshot', method_params) + _snapshot, changed = call_method(client, module, 'create_db_snapshot', method_params) return changed @@ -328,7 +328,7 @@ def copy_snapshot(params): method_params = get_parameters(params, 'copy_db_snapshot') if method_params.get('Tags'): method_params['Tags'] = ansible_dict_to_boto3_tag_list(method_params['Tags']) - result, changed = call_method(client, module, 'copy_db_snapshot', method_params) + _result, changed = call_method(client, module, 'copy_db_snapshot', method_params) return changed diff --git a/plugins/modules/route53_health_check.py b/plugins/modules/route53_health_check.py index 35287a79b40..532bc82c3ba 100644 --- a/plugins/modules/route53_health_check.py +++ b/plugins/modules/route53_health_check.py @@ -550,11 +550,9 @@ def main(): ip_addr_in = module.params.get('ip_address') port_in = module.params.get('port') type_in = module.params.get('type') - resource_path_in = module.params.get('resource_path') fqdn_in = module.params.get('fqdn') string_match_in = module.params.get('string_match') request_interval_in = module.params.get('request_interval') - failure_threshold_in = module.params.get('failure_threshold') health_check_name = module.params.get('health_check_name') tags = module.params.get('tags') diff --git a/plugins/modules/s3_object_info.py b/plugins/modules/s3_object_info.py index 0ac5c8f0b46..88e66dc4f05 100644 --- a/plugins/modules/s3_object_info.py +++ b/plugins/modules/s3_object_info.py @@ -466,7 +466,7 @@ def describe_s3_object_acl(connection, bucket_name, object_name): if len(object_acl_info) != 0: # Remove ResponseMetadata from object_acl_info, convert to snake_case - del(object_acl_info['ResponseMetadata']) + del object_acl_info['ResponseMetadata'] object_acl_info = camel_dict_to_snake_dict(object_acl_info) return object_acl_info @@ -487,7 +487,7 @@ def describe_s3_object_attributes(connection, module, bucket_name, object_name): if len(object_attributes_info) != 0 and 'msg' not in object_attributes_info.keys(): # Remove ResponseMetadata from object_attributes_info, convert to snake_case - del(object_attributes_info['ResponseMetadata']) + del object_attributes_info['ResponseMetadata'] object_attributes_info = camel_dict_to_snake_dict(object_attributes_info) return object_attributes_info @@ -507,7 +507,7 @@ def describe_s3_object_legal_hold(connection, bucket_name, object_name): if len(object_legal_hold_info) != 0: # Remove ResponseMetadata from object_legal_hold_info, convert to snake_case - del(object_legal_hold_info['ResponseMetadata']) + del object_legal_hold_info['ResponseMetadata'] object_legal_hold_info = camel_dict_to_snake_dict(object_legal_hold_info) return object_legal_hold_info @@ -526,7 +526,7 @@ def describe_s3_object_lock_configuration(connection, bucket_name): if len(object_legal_lock_configuration_info) != 0: # Remove ResponseMetadata from object_legal_lock_configuration_info, convert to snake_case - del(object_legal_lock_configuration_info['ResponseMetadata']) + del object_legal_lock_configuration_info['ResponseMetadata'] object_legal_lock_configuration_info = camel_dict_to_snake_dict(object_legal_lock_configuration_info) return object_legal_lock_configuration_info @@ -546,7 +546,7 @@ def describe_s3_object_retention(connection, bucket_name, object_name): if len(object_retention_info) != 0: # Remove ResponseMetadata from object_retention_info, convert to snake_case - del(object_retention_info['ResponseMetadata']) + del object_retention_info['ResponseMetadata'] object_retention_info = camel_dict_to_snake_dict(object_retention_info) return object_retention_info @@ -566,7 +566,7 @@ def describe_s3_object_tagging(connection, bucket_name, object_name): if len(object_tagging_info) != 0: # Remove ResponseMetadata from object_tagging_info, convert to snake_case - del(object_tagging_info['ResponseMetadata']) + del object_tagging_info['ResponseMetadata'] object_tagging_info = boto3_tag_list_to_ansible_dict(object_tagging_info['TagSet']) return object_tagging_info @@ -622,7 +622,7 @@ def get_object(connection, bucket_name, object_name): if len(object_info) != 0: # Remove ResponseMetadata from object_info, convert to snake_case - del(object_info['ResponseMetadata']) + del object_info['ResponseMetadata'] object_info = camel_dict_to_snake_dict(object_info) result['object_data'] = object_info diff --git a/tests/unit/module_utils/modules/ansible_aws_module/test_minimal_versions.py b/tests/unit/module_utils/modules/ansible_aws_module/test_minimal_versions.py index 17e69ecb529..f0bf3c4c853 100644 --- a/tests/unit/module_utils/modules/ansible_aws_module/test_minimal_versions.py +++ b/tests/unit/module_utils/modules/ansible_aws_module/test_minimal_versions.py @@ -9,7 +9,6 @@ from pprint import pprint import pytest import json -import warnings try: import botocore diff --git a/tests/unit/module_utils/policy/test_py3cmp.py b/tests/unit/module_utils/policy/test_py3cmp.py index af13f96e022..819befcc7fc 100644 --- a/tests/unit/module_utils/policy/test_py3cmp.py +++ b/tests/unit/module_utils/policy/test_py3cmp.py @@ -37,7 +37,7 @@ def test_py3cmp_mixed(): assert _py3cmp("a", ("b",)) == -1 # intended for use by _hashable_policy, so expects either a string or a tuple - with pytest.raises(TypeError) as context: + with pytest.raises(TypeError): _py3cmp((1,), 1) - with pytest.raises(TypeError) as context: + with pytest.raises(TypeError): _py3cmp(1, (1,)) diff --git a/tests/unit/module_utils/policy/test_simple_hashable_policy.py b/tests/unit/module_utils/policy/test_simple_hashable_policy.py index 408d02a07c6..16a10139756 100644 --- a/tests/unit/module_utils/policy/test_simple_hashable_policy.py +++ b/tests/unit/module_utils/policy/test_simple_hashable_policy.py @@ -7,7 +7,6 @@ __metaclass__ = type from ansible_collections.amazon.aws.plugins.module_utils.policy import _hashable_policy -from ansible_collections.amazon.aws.tests.unit.compat.mock import sentinel def test_hashable_policy_none(): diff --git a/tests/unit/module_utils/test_s3.py b/tests/unit/module_utils/test_s3.py index 42c8ecfd024..cd73a6c2e43 100644 --- a/tests/unit/module_utils/test_s3.py +++ b/tests/unit/module_utils/test_s3.py @@ -12,8 +12,6 @@ from ansible_collections.amazon.aws.plugins.module_utils import s3 from ansible.module_utils.basic import AnsibleModule -import pytest - class FakeAnsibleModule(AnsibleModule): def __init__(self): diff --git a/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py b/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py index cdde74c97e2..bdddc9f49ee 100644 --- a/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py +++ b/tests/unit/plugins/modules/ec2_instance/test_determine_iam_role.py @@ -79,8 +79,8 @@ def test_determine_iam_role_missing(params_object, ec2_instance): iam_client = MagicMock(**{"get_instance_profile.side_effect": missing_exception}) ec2_instance_module.module.client.return_value = iam_client - with pytest.raises(FailJsonException) as exception: - arn = ec2_instance.determine_iam_role(sentinel.IAM_PROFILE_NAME) + with pytest.raises(FailJsonException): + ec2_instance.determine_iam_role(sentinel.IAM_PROFILE_NAME) assert ec2_instance_module.module.fail_json_aws.call_count == 1 assert ec2_instance_module.module.fail_json_aws.call_args.args[0] is missing_exception @@ -93,8 +93,8 @@ def test_determine_iam_role_missing(params_object, ec2_instance): iam_client = MagicMock(**{"get_instance_profile.side_effect": missing_exception}) ec2_instance_module.module.client.return_value = iam_client - with pytest.raises(FailJsonException) as exception: - arn = ec2_instance.determine_iam_role(sentinel.IAM_PROFILE_NAME) + with pytest.raises(FailJsonException): + ec2_instance.determine_iam_role(sentinel.IAM_PROFILE_NAME) assert ec2_instance_module.module.fail_json_aws.call_count == 1 assert ec2_instance_module.module.fail_json_aws.call_args.args[0] is missing_exception diff --git a/tests/unit/plugins/modules/test_ec2_ami.py b/tests/unit/plugins/modules/test_ec2_ami.py index 5e8140d4a46..8e5fc5c4bf4 100644 --- a/tests/unit/plugins/modules/test_ec2_ami.py +++ b/tests/unit/plugins/modules/test_ec2_ami.py @@ -1,9 +1,9 @@ # This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from unittest.mock import MagicMock, Mock, patch, call - -import pytest +from unittest.mock import MagicMock +from unittest.mock import patch +from unittest.mock import call from ansible_collections.amazon.aws.plugins.modules import ec2_ami