Skip to content

Commit

Permalink
Minor Sanity test fixes (#1462)
Browse files Browse the repository at this point in the history
Minor Sanity test fixes

SUMMARY
Steal sanity fixes from #1393
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/backup_tag_info.py
plugins/modules/backup_vault.py
plugins/modules/route53_info.py
test-requirements.txt
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
  • Loading branch information
tremble authored Apr 20, 2023
1 parent 7afa27d commit 736754b
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 161 deletions.
6 changes: 6 additions & 0 deletions changelogs/fragments/1462-sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
minor_changes:
- route53_info - drop unused imports (https://github.com/ansible-collections/amazon.aws/pull/1462).
trivial:
# Not yet released
- backup_tag_info - sanity fixes
- backup_vault - sanity fixes
5 changes: 0 additions & 5 deletions plugins/modules/backup_tag_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
type: dict
"""

try:
from botocore.exceptions import ClientError, BotoCoreError
except ImportError:
pass # caught by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.backup import get_backup_resource_tags

Expand Down
1 change: 0 additions & 1 deletion plugins/modules/backup_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@


from ansible_collections.amazon.aws.plugins.module_utils.tagging import compare_aws_tags
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.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
Expand Down
2 changes: 0 additions & 2 deletions plugins/modules/route53_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,6 @@
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible.module_utils._text import to_native

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pytest
pytest-forked
pytest-mock
pytest-xdist
pytest-ansible-units ; python_version > '3.8'

# Needed for ansible.utils.ipaddr in tests
netaddr
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/targets/cloudtrail/main.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
search_service_names:
- 'com.amazonaws.{{ aws_region }}.s3'
- 'com.amazonaws.{{ aws_region }}.ec2'
- 'com.amazonaws.{{ aws_region }}.s3'
- 'com.amazonaws.{{ aws_region }}.ec2'
242 changes: 121 additions & 121 deletions tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,135 +1,135 @@
---
- module_defaults:
- name: Verify ec2_vpc_endpoint_service_info
module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
collections:
- amazon.aws
- community.aws
block:
- name: "List all available services (Check Mode)"
ec2_vpc_endpoint_service_info:
check_mode: true
register: services_check

- name: 'List all available services (Check Mode)'
ec2_vpc_endpoint_service_info:
check_mode: True
register: services_check
- name: "Verify services (Check Mode)"
vars:
first_service: "{{ services_check.service_details[0] }}"
ansible.builtin.assert:
that:
- services_check is successful
- services_check is not changed
- '"service_names" in services_check'
- '"service_details" in services_check'
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'

- name: 'Verify services (Check Mode)'
vars:
first_service: '{{ services_check.service_details[0] }}'
assert:
that:
- services_check is successful
- services_check is not changed
- '"service_names" in services_check'
- '"service_details" in services_check'
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'
- name: "List all available services"
ec2_vpc_endpoint_service_info:
register: services_info

- name: 'List all available services'
ec2_vpc_endpoint_service_info:
register: services_info
- name: "Verify services"
vars:
first_service: "{{ services_info.service_details[0] }}"
ansible.builtin.assert:
that:
- services_info is successful
- services_info is not changed
- '"service_names" in services_info'
- '"service_details" in services_info'
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'

- name: 'Verify services'
vars:
first_service: '{{ services_info.service_details[0] }}'
assert:
that:
- services_info is successful
- services_info is not changed
- '"service_names" in services_info'
- '"service_details" in services_info'
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'
- name: "Limit services by name"
ec2_vpc_endpoint_service_info:
service_names: "{{ search_service_names }}"
register: services_info

- name: 'Limit services by name'
ec2_vpc_endpoint_service_info:
service_names: '{{ search_service_names }}'
register: services_info
- name: "Verify services"
vars:
first_service: "{{ services_info.service_details[0] }}"
# The same service sometimes pop up twice. s3 for example has
# s3.us-east-1.amazonaws.com and s3.us-east-1.vpce.amazonaws.com which are
# part of com.amazonaws.us-east-1.s3 so we need to run the results through
# the unique filter to know if we've got what we think we have
unique_names: "{{ services_info.service_names | unique | list }}"
unique_detail_names: '{{ services_info.service_details | map(attribute="service_name") | unique | list }}'
ansible.builtin.assert:
that:
- services_info is successful
- services_info is not changed
- '"service_names" in services_info'
- (unique_names | length) == (search_service_names | length)
- (unique_detail_names | length ) == (search_service_names | length)
- (unique_names | difference(search_service_names) | length) == 0
- (unique_detail_names | difference(search_service_names) | length) == 0
- '"service_details" in services_info'
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'

- name: 'Verify services'
vars:
first_service: '{{ services_info.service_details[0] }}'
# The same service sometimes pop up twice. s3 for example has
# s3.us-east-1.amazonaws.com and s3.us-east-1.vpce.amazonaws.com which are
# part of com.amazonaws.us-east-1.s3 so we need to run the results through
# the unique filter to know if we've got what we think we have
unique_names: '{{ services_info.service_names | unique | list }}'
unique_detail_names: '{{ services_info.service_details | map(attribute="service_name") | unique | list }}'
assert:
that:
- services_info is successful
- services_info is not changed
- '"service_names" in services_info'
- (unique_names | length) == (search_service_names | length)
- (unique_detail_names | length ) == (search_service_names | length)
- (unique_names | difference(search_service_names) | length) == 0
- (unique_detail_names | difference(search_service_names) | length) == 0
- '"service_details" in services_info'
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'
- name: "Grab single service details to test filters"
ansible.builtin.set_fact:
example_service: "{{ services_info.service_details[0] }}"

- name: 'Grab single service details to test filters'
set_fact:
example_service: '{{ services_info.service_details[0] }}'
- name: "Limit services by filter"
ec2_vpc_endpoint_service_info:
filters:
service-name: "{{ example_service.service_name }}"
register: filtered_service

- name: 'Limit services by filter'
ec2_vpc_endpoint_service_info:
filters:
service-name: '{{ example_service.service_name }}'
register: filtered_service

- name: 'Verify services'
vars:
first_service: '{{ filtered_service.service_details[0] }}'
assert:
that:
- filtered_service is successful
- filtered_service is not changed
- '"service_names" in filtered_service'
- filtered_service.service_names | length == 1
- '"service_details" in filtered_service'
- filtered_service.service_details | length == 1
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'
- name: "Verify services"
vars:
first_service: "{{ filtered_service.service_details[0] }}"
ansible.builtin.assert:
that:
- filtered_service is successful
- filtered_service is not changed
- '"service_names" in filtered_service'
- filtered_service.service_names | length == 1
- '"service_details" in filtered_service'
- filtered_service.service_details | length == 1
- '"acceptance_required" in first_service'
- '"availability_zones" in first_service'
- '"base_endpoint_dns_names" in first_service'
- '"manages_vpc_endpoints" in first_service'
- '"owner" in first_service'
- '"private_dns_name" in first_service'
- '"private_dns_name_verification_state" in first_service'
- '"service_id" in first_service'
- '"service_name" in first_service'
- '"service_type" in first_service'
- '"tags" in first_service'
- '"vpc_endpoint_policy_supported" in first_service'
21 changes: 13 additions & 8 deletions tests/integration/targets/inventory_aws_ec2/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: get image ID to create an instance
ec2_ami_info:
amazon.aws.ec2_ami_info:
filters:
architecture: x86_64
# CentOS Community Platform Engineering (CPE)
Expand All @@ -9,25 +10,27 @@
name: 'Fedora-Cloud-Base-34-1.2.x86_64*'
register: fedora_images

- set_fact:
- name: Set image id, vpc cidr and subnet cidr
ansible.builtin.set_fact:
image_id: '{{ fedora_images.images.0.image_id }}'
vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16'
subnet_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/24'

- name: create a VPC to work in
ec2_vpc_net:
amazon.aws.ec2_vpc_net:
cidr_block: '{{ vpc_cidr }}'
state: present
name: '{{ resource_prefix }}_setup'
resource_tags:
Name: '{{ resource_prefix }}_setup'
register: setup_vpc

- set_fact:
- name: Set vpc id
ansible.builtin.set_fact:
vpc_id: '{{ setup_vpc.vpc.id }}'

- name: create a subnet to use for creating an ec2 instance
ec2_vpc_subnet:
amazon.aws.ec2_vpc_subnet:
az: '{{ aws_region }}a'
vpc_id: '{{ setup_vpc.vpc.id }}'
cidr: '{{ subnet_cidr }}'
Expand All @@ -36,7 +39,8 @@
Name: '{{ resource_prefix }}_setup'
register: setup_subnet

- set_fact:
- name: Set subnet id
ansible.builtin.set_fact:
subnet_id: '{{ setup_subnet.subnet.id }}'

- name: create a security group to use for creating an ec2 instance
Expand All @@ -47,7 +51,8 @@
vpc_id: '{{ setup_vpc.vpc.id }}'
register: setup_sg

- set_fact:
- name: Set sg id
ansible.builtin.set_fact:
sg_id: '{{ setup_sg.group_id }}'

- name: Create ec2 instance
Expand All @@ -57,5 +62,5 @@
instance_type: t2.micro
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
wait: false
register: setup_instance
Loading

0 comments on commit 736754b

Please sign in to comment.