From 67f5f0ad7b6320910393e83a2f1b470d63f666fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Fri, 17 Dec 2021 16:33:22 -0500 Subject: [PATCH] DNM - TEST SF --- plugins/module_utils/route53.py | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/plugins/module_utils/route53.py b/plugins/module_utils/route53.py index 3e2940a5311..138729617d5 100644 --- a/plugins/module_utils/route53.py +++ b/plugins/module_utils/route53.py @@ -2,6 +2,7 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function + __metaclass__ = type try: @@ -10,8 +11,12 @@ pass # caught by AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.tagging import ansible_dict_to_boto3_tag_list -from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.tagging import ( + ansible_dict_to_boto3_tag_list, +) +from ansible_collections.amazon.aws.plugins.module_utils.tagging import ( + boto3_tag_list_to_ansible_dict, +) from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags @@ -20,13 +25,15 @@ def manage_tags(module, client, resource_type, resource_id, new_tags, purge_tags return False old_tags = get_tags(module, client, resource_type, resource_id) - tags_to_set, tags_to_delete = compare_aws_tags(old_tags, new_tags, purge_tags=purge_tags) + tags_to_set, tags_to_delete = compare_aws_tags( + old_tags, new_tags, purge_tags=purge_tags + ) change_params = dict() if tags_to_set: - change_params['AddTags'] = ansible_dict_to_boto3_tag_list(tags_to_set) + change_params["AddTags"] = ansible_dict_to_boto3_tag_list(tags_to_set) if tags_to_delete: - change_params['RemoveTagKeys'] = tags_to_delete + change_params["RemoveTagKeys"] = tags_to_delete if not change_params: return False @@ -36,13 +43,15 @@ def manage_tags(module, client, resource_type, resource_id, new_tags, purge_tags try: client.change_tags_for_resource( - ResourceType=resource_type, - ResourceId=resource_id, - **change_params + ResourceType=resource_type, ResourceId=resource_id, **change_params ) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, msg='Failed to update tags on {0}'.format(resource_type), - resource_id=resource_id, change_params=change_params) + module.fail_json_aws( + e, + msg="Failed to update tags on {0}".format(resource_type), + resource_id=resource_id, + change_params=change_params, + ) return True @@ -52,13 +61,19 @@ def get_tags(module, client, resource_type, resource_id): ResourceType=resource_type, ResourceId=resource_id, ) - except is_boto3_error_code('NoSuchHealthCheck'): + except is_boto3_error_code("NoSuchHealthCheck"): return {} - except is_boto3_error_code('NoSuchHostedZone'): # pylint: disable=duplicate-except + except is_boto3_error_code("NoSuchHostedZone"): # pylint: disable=duplicate-except return {} - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except - module.fail_json_aws(e, msg='Failed to fetch tags on {0}'.format(resource_type), - resource_id=resource_id) + except ( + botocore.exceptions.BotoCoreError, + botocore.exceptions.ClientError, + ) as e: # pylint: disable=duplicate-except + module.fail_json_aws( + e, + msg="Failed to fetch tags on {0}".format(resource_type), + resource_id=resource_id, + ) - tags = boto3_tag_list_to_ansible_dict(tagset['ResourceTagSet']['Tags']) + tags = boto3_tag_list_to_ansible_dict(tagset["ResourceTagSet"]["Tags"]) return tags