Skip to content

Commit

Permalink
Work on ec2_instance integration test flakes (#1845)
Browse files Browse the repository at this point in the history
Work on ec2_instance integration test flakes

SUMMARY
As seen in #1828 the integration tests for ec2_instance are still a little flaky (ignoring Zuul also being flaky).  This attempts to tweak two of the worst offenders to improve things
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
(cherry picked from commit 02b1511)
  • Loading branch information
tremble authored and patchback[bot] committed Nov 21, 2023
1 parent 989ac62 commit bfddee5
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 293 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_block_devices
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-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,6 +1,7 @@
---
# this just makes sure they're in the right place
dependencies:
- role: setup_ec2_facts
- role: setup_ec2_instance_env
vars:
ec2_instance_test_name: block_devices
- role: setup_ec2_facts
- role: setup_ec2_instance_env
vars:
ec2_instance_test_name: block_devices
201 changes: 107 additions & 94 deletions tests/integration/targets/ec2_instance_block_devices/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,123 @@
- module_defaults:
---
- name: Wrap tests in block to set module defaults
module_defaults:
group/aws:
access_key: "{{ aws_access_key }}"
secret_key: "{{ aws_secret_key }}"
session_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block:
- name: "New instance with an extra block device"
ec2_instance:
state: running
name: "{{ resource_prefix }}-test-ebs-vols"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sdb
ebs:
volume_size: 20
delete_on_termination: true
volume_type: standard
tags:
TestId: "{{ ec2_instance_tag_TestId }}"
instance_type: "{{ ec2_instance_type }}"
wait: true
register: block_device_instances
- name: New instance with an extra block device
amazon.aws.ec2_instance:
state: running
name: "{{ resource_prefix }}-test-ebs-vols"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sdb
ebs:
volume_size: 20
delete_on_termination: true
volume_type: standard
tags:
TestId: "{{ ec2_instance_tag_TestId }}"
instance_type: "{{ ec2_instance_type }}"
wait: true
register: block_device_instances

- name: "Gather instance info"
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
register: block_device_instances_info
- name: Gather instance info
amazon.aws.ec2_instance_info:
filters:
tag:Name: "{{ resource_prefix }}-test-ebs-vols"
register: block_device_instances_info

- assert:
that:
- block_device_instances is not failed
- block_device_instances is changed
- block_device_instances_info.instances[0].block_device_mappings[0]
- block_device_instances_info.instances[0].block_device_mappings[1]
- block_device_instances_info.instances[0].block_device_mappings[1].device_name == '/dev/sdb'
- name: Check device name
ansible.builtin.assert:
that:
- block_device_instances is not failed
- block_device_instances is changed
- instance_info.block_device_mappings | length == 2
- '"/dev/sdb" in instance_info.block_device_mappings | map(attribute="device_name")'
vars:
instance_info: "{{ block_device_instances_info.instances[0] }}"

- name: "New instance with an extra block device (check mode)"
ec2_instance:
state: present
name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sdb
ebs:
volume_size: 20
delete_on_termination: true
volume_type: standard
tags:
TestId: "{{ ec2_instance_tag_TestId }}"
instance_type: "{{ ec2_instance_type }}"
check_mode: yes
- name: New instance with an extra block device (check mode)
amazon.aws.ec2_instance:
state: present
name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sdb
ebs:
volume_size: 20
delete_on_termination: true
volume_type: standard
tags:
TestId: "{{ ec2_instance_tag_TestId }}"
instance_type: "{{ ec2_instance_type }}"
check_mode: true

- name: "fact presented ec2 instance"
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-test-ebs-vols"
register: presented_instance_fact
- name: Fact presented ec2 instance
amazon.aws.ec2_instance_info:
filters:
tag:Name: "{{ resource_prefix }}-test-ebs-vols"
register: presented_instance_fact

- name: "fact checkmode ec2 instance"
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-test-ebs-vols-checkmode"
register: checkmode_instance_fact
- name: Fact checkmode ec2 instance
amazon.aws.ec2_instance_info:
filters:
tag:Name: "{{ resource_prefix }}-test-ebs-vols-checkmode"
register: checkmode_instance_fact

- name: "Confirm instance was created without check mode"
assert:
that:
- "{{ presented_instance_fact.instances | length }} > 0"
- name: Confirm instance was created without check mode
ansible.builtin.assert:
that:
- "{{ presented_instance_fact.instances | length }} > 0"

- name: "Confirm instance was not created with check mode"
assert:
that:
- "{{ checkmode_instance_fact.instances | length }} == 0"
- name: Confirm instance was not created with check mode
ansible.builtin.assert:
that:
- "{{ checkmode_instance_fact.instances | length }} == 0"

- name: "Terminate instances"
ec2_instance:
state: absent
instance_ids: "{{ block_device_instances.instance_ids }}"
- name: Terminate instances
amazon.aws.ec2_instance:
state: absent
instance_ids: "{{ block_device_instances.instance_ids }}"

- name: "New instance with an extra block device - gp3 volume_type and throughput"
ec2_instance:
state: running
name: "{{ resource_prefix }}-test-ebs-vols-gp3"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sdb
ebs:
volume_size: 20
delete_on_termination: true
volume_type: gp3
throughput: 500
tags:
TestId: "{{ ec2_instance_tag_TestId }}"
instance_type: "{{ ec2_instance_type }}"
wait: true
register: block_device_instances_gp3
- name: New instance with an extra block device - gp3 volume_type and throughput
amazon.aws.ec2_instance:
state: running
name: "{{ resource_prefix }}-test-ebs-vols-gp3"
image_id: "{{ ec2_ami_id }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sdb
ebs:
volume_size: 20
delete_on_termination: true
volume_type: gp3
throughput: 500
tags:
TestId: "{{ ec2_instance_tag_TestId }}"
instance_type: "{{ ec2_instance_type }}"
wait: true
register: block_device_instances_gp3

- assert:
that:
- block_device_instances_gp3 is not failed
- block_device_instances_gp3 is changed
- block_device_instances_gp3.spec.BlockDeviceMappings[0].DeviceName == '/dev/sdb'
- block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeType == 'gp3'
- block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeSize == 20
- block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.Throughput == 500
- name: Check updated device configuration
ansible.builtin.assert:
that:
- block_device_instances_gp3 is not failed
- block_device_instances_gp3 is changed
- instance_info.block_device_mappings | length == 2
- '"/dev/sdb" in instance_info.block_device_mappings | map(attribute="device_name")'
- block_device_spec | length == 1
- '"DeviceName" in block_device_spec[0]'
- '"Ebs" in block_device_spec[0]'
- block_device_spec[0].DeviceName == "/dev/sdb"
- block_device_spec[0].Ebs.VolumeType == "gp3"
- block_device_spec[0].Ebs.VolumeSize == 20
- block_device_spec[0].Ebs.Throughput == 500
vars:
instance_info: "{{ block_device_instances_gp3.instances[0] }}"
block_device_spec: "{{ block_device_instances_gp3.spec.BlockDeviceMappings }}"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# defaults file for ec2_instance_state_config_updates
ec2_instance_type: 't3.micro'
ec2_instance_tag_TestId: '{{ resource_prefix }}-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,6 +1,7 @@
---
# this just makes sure they're in the right place
dependencies:
- role: setup_ec2_facts
- role: setup_ec2_instance_env
vars:
ec2_instance_test_name: state_config_updates
- role: setup_ec2_facts
- role: setup_ec2_instance_env
vars:
ec2_instance_test_name: state_config_updates
Loading

0 comments on commit bfddee5

Please sign in to comment.