From 1e45fd81c6feaaff32c08cda43b9f705f9c28dd4 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 4 Sep 2021 18:51:57 +0200 Subject: [PATCH] Update some tests to account for 'present' now only waiting for the instance to exist rather than start --- tests/integration/targets/ec2_instance/inventory | 5 ++--- tests/integration/targets/ec2_instance/main.yml | 2 +- .../roles/ec2_instance/tasks/block_devices.yml | 4 ++-- .../roles/ec2_instance/tasks/checkmode_tests.yml | 9 +++++---- .../roles/ec2_instance/tasks/cpu_options.yml | 6 ++++-- .../roles/ec2_instance/tasks/env_cleanup.yml | 1 + .../roles/ec2_instance/tasks/state_config_updates.yml | 7 ++++--- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/integration/targets/ec2_instance/inventory b/tests/integration/targets/ec2_instance/inventory index c7567049b18..192cabfe924 100644 --- a/tests/integration/targets/ec2_instance/inventory +++ b/tests/integration/targets/ec2_instance/inventory @@ -1,5 +1,6 @@ [tests] -# Sorted fastest to slowest +checkmode_tests +termination_protection ebs_optimized block_devices cpu_options @@ -8,9 +9,7 @@ default_vpc_tests external_resource_attach instance_no_wait iam_instance_role -termination_protection tags_and_vpc_settings -checkmode_tests security_group state_config_updates diff --git a/tests/integration/targets/ec2_instance/main.yml b/tests/integration/targets/ec2_instance/main.yml index 6972621f0cc..ff76dac1311 100644 --- a/tests/integration/targets/ec2_instance/main.yml +++ b/tests/integration/targets/ec2_instance/main.yml @@ -35,6 +35,6 @@ - hosts: all gather_facts: no strategy: free - #serial: 10 + serial: 3 roles: - ec2_instance diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml index acf513986bf..a2a46e76d27 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml @@ -1,7 +1,7 @@ - block: - name: "New instance with an extra block device" ec2_instance: - state: present + state: running name: "{{ resource_prefix }}-test-ebs-vols" image_id: "{{ ec2_ami_id }}" vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" @@ -77,7 +77,7 @@ - name: "New instance with an extra block device - gp3 volume_type and throughput" ec2_instance: - state: present + state: running name: "{{ resource_prefix }}-test-ebs-vols-gp3" image_id: "{{ ec2_ami_id }}" vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml index 417569808bb..f9092882a0a 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml @@ -63,7 +63,7 @@ - name: "Verify that it was not stopped." assert: that: - - '"{{ confirm_checkmode_stopinstance_fact.instances[0].state.name }}" != "stopped"' + - confirm_checkmode_stopinstance_fact.instances[0].state.name not in ["stopped", "stopping"] - name: "Stop instance." ec2_instance: @@ -73,9 +73,8 @@ tags: TestId: "{{ ec2_instance_tag_TestId }}" TestTag: "Some Value" + wait: true register: instance_stop - until: not instance_stop.failed - retries: 10 - name: "fact stopped ec2 instance" ec2_instance_info: @@ -86,7 +85,7 @@ - name: "Verify that it was stopped." assert: that: - - '"{{ confirm_stopinstance_fact.instances[0].state.name }}" in ["stopped", "stopping"]' + - confirm_stopinstance_fact.instances[0].state.name in ["stopped", "stopping"] - name: "Running instance in check mode." ec2_instance: @@ -158,6 +157,7 @@ tags: TestId: "{{ ec2_instance_tag_TestId }}" TestTag: "Some Value" + wait: True check_mode: yes - name: "fact ec2 instance" @@ -179,6 +179,7 @@ tags: TestId: "{{ ec2_instance_tag_TestId }}" TestTag: "Some Value" + wait: True - name: "fact ec2 instance" ec2_instance_info: diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml index 4628cd80a6a..7eb2b6aeb38 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml @@ -11,7 +11,7 @@ cpu_options: core_count: 1 threads_per_core: 1 - wait: false + wait: true register: instance_creation - name: "instance with cpu_options created with the right options" @@ -32,7 +32,7 @@ cpu_options: core_count: 1 threads_per_core: 2 - wait: false + wait: true register: cpu_options_update ignore_errors: yes @@ -54,6 +54,7 @@ - name: "create t3.nano instance with cpu_options(check mode)" ec2_instance: + state: running name: "{{ resource_prefix }}-test-t3nano-1-threads-per-core-checkmode" image_id: "{{ ec2_ami_id }}" tags: @@ -63,6 +64,7 @@ cpu_options: core_count: 1 threads_per_core: 1 + wait: true check_mode: yes - name: "fact checkmode ec2 instance" diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml index 53a245fc5de..bdd69fecc44 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml @@ -17,6 +17,7 @@ ec2_eni: state: absent eni_id: "{{ item.id }}" + register: removed until: removed is not failed with_items: "{{ enis.network_interfaces }}" ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml index b9f7cdcdece..9592b55a654 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml @@ -5,7 +5,7 @@ - block: - name: "Make instance with sg and termination protection enabled" ec2_instance: - state: present + state: running name: "{{ resource_prefix }}-test-state-param-changes" image_id: "{{ ec2_ami_id }}" tags: @@ -111,6 +111,7 @@ vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" termination_protection: False instance_type: "{{ ec2_instance_type }}" + wait: True register: change_params_start_result - assert: @@ -120,8 +121,8 @@ - '"instances" in change_params_start_result' - '"instance_ids" in change_params_start_result' - '"changes" in change_params_start_result' - - '"reboot_success" in change_params_start_result' - - '"reboot_failed" in change_params_start_result' + - '"start_success" in change_params_start_result' + - '"start_failed" in change_params_start_result' - change_params_start_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" - change_params_start_result.changes[0].DisableApiTermination.Value == False