From 87f400793b7fb4a0a743228d0b55c93889354eb6 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 30 Aug 2024 12:50:55 +0200 Subject: [PATCH] Add integration test --- .../tasks/main.yml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml b/tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml index 082c3dbb7b..b293ce2038 100644 --- a/tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml +++ b/tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml @@ -277,6 +277,57 @@ - '"terminated_ids" not in terminate_multiple_instances' - '"ec2:TerminateInstances" not in terminate_multiple_instances.resource_actions' + - name: Trigger restart of instances with exact_count (check_mode) + amazon.aws.ec2_instance: + state: restarted + instance_type: "{{ ec2_instance_type }}" + exact_count: 3 + region: "{{ aws_region }}" + image_id: "{{ ec2_ami_id }}" + name: "{{ resource_prefix }}-test-enf_cnt" + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + register: restart_multiple_instances + check_mode: true + + - ansible.builtin.assert: + that: + - restart_multiple_instances is not failed + - restart_multiple_instances.changed + - '"instances" in restart_multiple_instances' + - restart_multiple_instances.instances | length == 3 + - '"reboot_success" in restart_multiple_instances' + - '"reboot_failed" in restart_multiple_instances' + - '"ec2:StopInstances" not in restart_multiple_instances.resource_actions' + - '"ec2:StartInstances" not in restart_multiple_instances.resource_actions' + + + - name: Trigger restart of instances with exact_count + amazon.aws.ec2_instance: + state: restarted + instance_type: "{{ ec2_instance_type }}" + exact_count: 3 + region: "{{ aws_region }}" + image_id: "{{ ec2_ami_id }}" + name: "{{ resource_prefix }}-test-enf_cnt" + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + wait: true + register: restart_multiple_instances + + - ansible.builtin.assert: + that: + - restart_multiple_instances is not failed + - restart_multiple_instances.changed + - '"instances" in restart_multiple_instances' + - restart_multiple_instances.instances | length == 3 + - '"reboot_success" in restart_multiple_instances' + - restart_multiple_instances.reboot_success | length == 3 + - '"reboot_failed" in restart_multiple_instances' + - restart_multiple_instances.reboot_success | length == 0 + - '"ec2:StopInstances" in restart_multiple_instances.resource_actions' + - '"ec2:StartInstances" in restart_multiple_instances.resource_actions' + - name: Enforce instance count to 6 - Launch 3 more instances (check_mode) amazon.aws.ec2_instance: instance_type: "{{ ec2_instance_type }}"