Skip to content

Commit

Permalink
ec2_instance integration test fixups (ansible-collections#1259)
Browse files Browse the repository at this point in the history
ec2_instance integration test fixups

SUMMARY
Attempt to fix ec2_instance test instability
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Gonéri Le Bouder <[email protected]>
  • Loading branch information
tremble authored Nov 9, 2022
1 parent 4ea965b commit 3d071cb
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 29 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1258-ec2_instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- ec2_instance - changes to integration tests to fix failures
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_block_devices
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-block-devices'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_checkmode_tests
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-checkmode'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_cpu_options
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-cpu-options'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_default_vpc
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-default-vpc'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_ebs_optimized
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-ebs-optimized'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_external_resource_attach
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-external-attach'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_hibernation_options
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-hibernation-options'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_iam_instance_profile
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-profile'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_minimal
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-minimal'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_multiple
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-multiple'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_no_wait
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-no-wait'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_metadata_options
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-metadata'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_security_group
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-sg'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_state_config_updates
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-state-config-updates'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_tags_and_vpc_settings
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-tags-vpc'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_termination_protection
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-temination'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance
# defaults file for ec2_instance_uptime
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-uptime'
4 changes: 2 additions & 2 deletions tests/integration/targets/ec2_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@
# Anything under 15 will trigger SnapshotCreationPerVolumeRateExceeded,
# this should now be automatically handled, but pause a little anyway to
# avoid being aggressive
pause: 10
pause: 15
label: "Generate extra snapshots - {{ item }}"

- name: Pause to allow creation to finish
pause:
minutes: 2
minutes: 3

# check that snapshot_ids and max_results are mutually exclusive
- name: Check that max_results and snapshot_ids are mutually exclusive
Expand Down
15 changes: 10 additions & 5 deletions tests/integration/targets/setup_ec2_instance_env/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
# defaults file for ec2_instance
ec2_instance_owner: 'integration-run-{{ resource_prefix }}'
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-{{ inventory_hostname }}'

# defaults file for ec2_instance tests
ec2_instance_test_name: 'ec2_instance'

ec2_instance_owner: 'integration-run-{{ ec2_instance_test_name }}'
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-{{ ec2_instance_test_name }}'

vpc_name: '{{ resource_prefix }}-{{ ec2_instance_test_name }}'
vpc_seed: '{{ resource_prefix }}-{{ ec2_instance_test_name }}'

Expand All @@ -14,6 +14,11 @@ vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.0.0/16'
subnet_a_az: '{{ ec2_availability_zone_names[0] }}'
subnet_a_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.32.0/24'
subnet_a_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.32.'
subnet_a_name: '{{ resource_prefix }}-{{ ec2_instance_test_name }}-a'
subnet_b_az: '{{ ec2_availability_zone_names[1] }}'
subnet_b_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.33.0/24'
subnet_b_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.33.'
subnet_b_name: '{{ resource_prefix }}-{{ ec2_instance_test_name }}-b'

security_group_name_1: '{{ resource_prefix }}-{{ ec2_instance_test_name }}-1'
security_group_name_2: '{{ resource_prefix }}-{{ ec2_instance_test_name }}-2'
26 changes: 21 additions & 5 deletions tests/integration/targets/setup_ec2_instance_env/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name: "{{ vpc_name }}"
cidr_block: "{{ vpc_cidr }}"
tags:
Name: Ansible ec2_instance Testing VPC
Name: "{{ vpc_name }}"
tenancy: default
register: testing_vpc
notify:
Expand All @@ -25,7 +25,7 @@
cidr: "{{ subnet_a_cidr }}"
az: "{{ subnet_a_az }}"
resource_tags:
Name: "{{ resource_prefix }}-subnet-a"
Name: "{{ subnet_a_name }}"
register: testing_subnet_a

- name: "Create secondary subnet in zone B"
Expand All @@ -35,13 +35,13 @@
cidr: "{{ subnet_b_cidr }}"
az: "{{ subnet_b_az }}"
resource_tags:
Name: "{{ resource_prefix }}-subnet-b"
Name: "{{ subnet_b_name }}"
register: testing_subnet_b

- name: "create a security group with the vpc"
ec2_security_group:
state: present
name: "{{ resource_prefix }}-sg"
name: "{{ security_group_name_1 }}"
description: a security group for ansible tests
vpc_id: "{{ testing_vpc.vpc.id }}"
rules:
Expand All @@ -57,7 +57,7 @@

- name: "create secondary security group with the vpc"
ec2_security_group:
name: "{{ resource_prefix }}-sg-2"
name: "{{ security_group_name_2 }}"
description: a secondary security group for ansible tests
vpc_id: "{{ testing_vpc.vpc.id }}"
rules:
Expand All @@ -70,3 +70,19 @@
to_port: 80
cidr_ip: 0.0.0.0/0
register: sg2

- name: Preserve defaults for other roles
set_fact:
# Ensure variables are available outside of this role
vpc_cidr: '{{ vpc_cidr }}'
vpc_name: '{{ vpc_name }}'
subnet_a_az: '{{ subnet_a_az }}'
subnet_a_cidr: '{{ subnet_a_cidr }}'
subnet_a_startswith: '{{ subnet_a_startswith }}'
subnet_a_name: '{{ subnet_a_name }}'
subnet_b_az: '{{ subnet_b_az }}'
subnet_b_cidr: '{{ subnet_b_cidr }}'
subnet_b_startswith: '{{ subnet_b_startswith }}'
subnet_b_name: '{{ subnet_b_name }}'
security_group_name_1: '{{ security_group_name_1 }}'
security_group_name_2: '{{ security_group_name_2 }}'

0 comments on commit 3d071cb

Please sign in to comment.