From c5d99356a845f798560d99cb82b0f1cebc277f22 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 17 Aug 2022 12:32:50 +0200 Subject: [PATCH] [PR #953 backport][stable-4] Minor linting fixups - 2022-08-04 (#965) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [PR #953 backport][stable-4] Minor linting fixups - 2022-08-04 SUMMARY Minor linting fixups docs unused variables ISSUE TYPE Feature Pull Request COMPONENT NAME plugins/inventory/aws_ec2.py plugins/inventory/aws_rds.py plugins/lookup/aws_account_attribute.py plugins/lookup/aws_secret.py plugins/lookup/aws_ssm.py plugins/module_utils/acm.py plugins/module_utils/botocore.py plugins/module_utils/cloud.py plugins/module_utils/iam.py plugins/module_utils/modules.py plugins/module_utils/rds.py ADDITIONAL INFORMATION Original PR Reviewed-by: Jill R Reviewed-by: Gonéri Le Bouder Reviewed-by: Alina Buzachis --- changelogs/fragments/965-linting.yml | 2 ++ plugins/module_utils/acm.py | 5 +++-- plugins/module_utils/botocore.py | 4 ++-- plugins/module_utils/cloud.py | 2 +- plugins/module_utils/cloudfront_facts.py | 4 +--- plugins/module_utils/iam.py | 2 +- plugins/module_utils/modules.py | 1 - 7 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/965-linting.yml diff --git a/changelogs/fragments/965-linting.yml b/changelogs/fragments/965-linting.yml new file mode 100644 index 00000000000..e6d56ff590a --- /dev/null +++ b/changelogs/fragments/965-linting.yml @@ -0,0 +1,2 @@ +minor_changes: +- various modules - linting fixups (https://github.com/ansible-collections/amazon.aws/pull/953). diff --git a/plugins/module_utils/acm.py b/plugins/module_utils/acm.py index e0934deade4..436f116477d 100644 --- a/plugins/module_utils/acm.py +++ b/plugins/module_utils/acm.py @@ -21,7 +21,8 @@ # on behalf of Telstra Corporation Limited # # Common functionality to be used by the modules: -# - acm +# - acm_certificate +# - acm_certificate_info from __future__ import (absolute_import, division, print_function) __metaclass__ = type @@ -213,7 +214,7 @@ def import_certificate(self, client, module, certificate, private_key, arn=None, module.debug("Attempting to delete the cert we just created, arn=%s" % arn) try: self.delete_certificate_with_backoff(client, arn) - except Exception as f: + except (BotoCoreError, ClientError): module.warn("Certificate %s exists, and is not tagged. So Ansible will not see it on the next run.") module.fail_json_aws(e, msg="Couldn't tag certificate %s, couldn't delete it either" % arn) module.fail_json_aws(e, msg="Couldn't tag certificate %s" % arn) diff --git a/plugins/module_utils/botocore.py b/plugins/module_utils/botocore.py index 33e79420848..791cac60333 100644 --- a/plugins/module_utils/botocore.py +++ b/plugins/module_utils/botocore.py @@ -72,7 +72,7 @@ def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None except (botocore.exceptions.ProfileNotFound, botocore.exceptions.PartialCredentialsError, botocore.exceptions.NoCredentialsError, botocore.exceptions.ConfigParseError) as e: module.fail_json(msg=to_native(e)) - except botocore.exceptions.NoRegionError as e: + except botocore.exceptions.NoRegionError: module.fail_json(msg="The %s module requires a region and none was found in configuration, " "environment variables or module parameters" % module._name) @@ -155,7 +155,7 @@ def get_aws_region(module, boto3=None): try: profile_name = module.params.get('profile') return botocore.session.Session(profile=profile_name).get_config_variable('region') - except botocore.exceptions.ProfileNotFound as e: + except botocore.exceptions.ProfileNotFound: return None diff --git a/plugins/module_utils/cloud.py b/plugins/module_utils/cloud.py index ba2fac74c4d..e690c0a8699 100644 --- a/plugins/module_utils/cloud.py +++ b/plugins/module_utils/cloud.py @@ -67,7 +67,7 @@ def _retry_func(func, sleep_time_generator, retries, catch_extra_error_codes, fo for sleep_time in sleep_time_generator: try: return func() - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except counter += 1 if counter == retries: raise diff --git a/plugins/module_utils/cloudfront_facts.py b/plugins/module_utils/cloudfront_facts.py index cef099db02b..c628bff14ba 100644 --- a/plugins/module_utils/cloudfront_facts.py +++ b/plugins/module_utils/cloudfront_facts.py @@ -174,9 +174,7 @@ def summary_get_distribution_list(self, streaming=False): temp_distribution['Tags'] = boto3_tag_list_to_ansible_dict(resource_tags['Tags'].get('Items', [])) distribution_list[list_name].append(temp_distribution) return distribution_list - except botocore.exceptions.ClientError as e: - self.module.fail_json_aws(e, msg="Error generating summary of distributions") - except Exception as e: + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: self.module.fail_json_aws(e, msg="Error generating summary of distributions") def get_etag_from_distribution_id(self, distribution_id, streaming): diff --git a/plugins/module_utils/iam.py b/plugins/module_utils/iam.py index 760c15f8e65..6ebed23baca 100644 --- a/plugins/module_utils/iam.py +++ b/plugins/module_utils/iam.py @@ -47,7 +47,7 @@ def get_aws_account_info(module): except (botocore.exceptions.BotoCoreError, botocore.exceptions.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(':') + _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) diff --git a/plugins/module_utils/modules.py b/plugins/module_utils/modules.py index 311b6b3976b..81aac319263 100644 --- a/plugins/module_utils/modules.py +++ b/plugins/module_utils/modules.py @@ -124,7 +124,6 @@ def __init__(self, **kwargs): if not HAS_BOTO3: self._module.fail_json( msg=missing_required_lib('botocore or boto3')) - current_versions = self._gather_versions() if not self.botocore_at_least('1.20.0'): self.warn('botocore < 1.20.0 is not supported or tested.' ' Some features may not work.')