Skip to content

Commit

Permalink
Cleanup - use is_boto3_error_(message|code) (ansible-collections#268)
Browse files Browse the repository at this point in the history
* Reorder imports
* Make use of is_boto3_error_message
* Mass-migration over to is_boto3_error_code
* Remove unused imports
* unused vars in exception
* Improve consistency around catching BotoCoreError and ClientError
* Remove unused imports
* Remove unused 'PolicyError' from iam_policy_info
* Avoid catching botocore.exceptions.ClientError when we only want some error codes
* Import camel_dict_to_snake_dict/snake_dict_to_camel_dict from ansible.module_utils.common.dict_transformations

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@4cf52ef
  • Loading branch information
tremble authored and jillr committed Jul 28, 2021
1 parent 9810aee commit 7a8e791
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions plugins/modules/ec2_vpc_route_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,24 @@

import re
from time import sleep
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter
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 camel_dict_to_snake_dict, snake_dict_to_camel_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list, boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags, AWSRetry


try:
import botocore
except ImportError:
pass # caught by AnsibleAWSModule

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_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 ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter


CIDR_RE = re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$')
SUBNET_RE = re.compile(r'^subnet-[A-z0-9]+$')
Expand Down Expand Up @@ -370,11 +375,8 @@ def ensure_tags(connection=None, module=None, resource_id=None, tags=None, purge
def describe_route_tables_with_backoff(connection, **params):
try:
return connection.describe_route_tables(**params)['RouteTables']
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'InvalidRouteTableID.NotFound':
return None
else:
raise
except is_boto3_error_code('InvalidRouteTableID.NotFound'):
return None


def get_route_table_by_id(connection, module, route_table_id):
Expand Down

0 comments on commit 7a8e791

Please sign in to comment.