Skip to content

Commit

Permalink
ec2_vpc_igw: increase integration tests coverage and code cleaning (a…
Browse files Browse the repository at this point in the history
…nsible-collections#386)

* Internet gateway: add missing integration tests and code check
 * Add CamelCase tags integration test
 * Removed check_input_tags() because useless as ansible_dict_to_boto3_tag_list() already performs a to_native() conversion to strings
 * Add additional integration tests for ec2_vpc_igw_info module

Signed-off-by: Alina Buzachis <[email protected]>

* Internet Gateway - integration tests
 * Fix Internet Gatways search by tags

* * Apply reviewer suggestions
        * Better error handling for the waiter
  • Loading branch information
alinabuzachis authored Mar 16, 2021
1 parent a95f0b2 commit 3fa8dd9
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions ec2_vpc_igw.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
except ImportError:
pass # caught by AnsibleAWSModule

from ansible.module_utils.six import string_types

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 AWSRetry
Expand Down Expand Up @@ -141,13 +139,6 @@ def get_matching_igw(self, vpc_id):

return igw

def check_input_tags(self, tags):
if tags is None:
return
nonstring_tags = [k for k, v in tags.items() if not isinstance(v, string_types)]
if nonstring_tags:
self._module.fail_json(msg='One or more tags contain non-string values: {0}'.format(nonstring_tags))

def ensure_tags(self, igw_id, tags, purge_tags):
final_tags = []

Expand All @@ -167,7 +158,6 @@ def ensure_tags(self, igw_id, tags, purge_tags):
if to_update:
try:
if self._check_mode:
# update tags
final_tags.update(to_update)
else:
self._connection.create_tags(
Expand All @@ -183,7 +173,6 @@ def ensure_tags(self, igw_id, tags, purge_tags):
if to_delete:
try:
if self._check_mode:
# update tags
for key in to_delete:
del final_tags[key]
else:
Expand Down Expand Up @@ -233,8 +222,6 @@ def ensure_igw_absent(self, vpc_id):
return self._results

def ensure_igw_present(self, vpc_id, tags, purge_tags):
self.check_input_tags(tags)

igw = self.get_matching_igw(vpc_id)

if igw is None:
Expand All @@ -253,6 +240,8 @@ def ensure_igw_present(self, vpc_id, tags, purge_tags):
igw = camel_dict_to_snake_dict(response['InternetGateway'])
self._connection.attach_internet_gateway(aws_retry=True, InternetGatewayId=igw['internet_gateway_id'], VpcId=vpc_id)
self._results['changed'] = True
except botocore.exceptions.WaiterError as e:
self._module.fail_json_aws(e, msg="No Internet Gateway exists.")
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self._module.fail_json_aws(e, msg='Unable to create Internet Gateway')

Expand Down

0 comments on commit 3fa8dd9

Please sign in to comment.