From 7700558cb276790f41370d5c2cbeb7170d9af4b0 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 14 Dec 2020 19:26:06 +0100 Subject: [PATCH] Fixup ec2_eip tests - work around ec2_instance flakes (#333) * Explicitly pass the subnet the instance should live on - try to avoid https://github.com/ansible-collections/community.aws/issues/329 * Make sure we delete the Instance (and free the EIP) before we try to drop the IGW * Use IDs when cleaning up EC2 instances This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/6c0273b79c1b9f02f8e7f452fcbdf1904cf7767d --- .../targets/ec2_eip/tasks/main.yml | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/tests/integration/targets/ec2_eip/tasks/main.yml b/tests/integration/targets/ec2_eip/tasks/main.yml index d296d0197bc..6d904003012 100644 --- a/tests/integration/targets/ec2_eip/tasks/main.yml +++ b/tests/integration/targets/ec2_eip/tasks/main.yml @@ -63,8 +63,10 @@ name: '{{ resource_prefix }}-instance' image_id: '{{ ec2_amis.images[0].image_id }}' security_group: '{{ security_group.group_id }}' + vpc_subnet_id: '{{ vpc_subnet_create.subnet.id }}' wait: no ## Don't delay the tests, we'll check again before we need it - register: ec2_instance_result + register: create_ec2_instance_result + # ===================================================== - name: Look for signs of concurrent EIP tests. Pause if they are running or their prefix comes before ours. vars: @@ -570,19 +572,23 @@ - eip_info.addresses[0].allocation_id is defined - eip_info.addresses[0].instance_id == '{{ instance_info.instances[0].instance_id }}' # ===================================================== - - name: Cleanup IGW - ec2_vpc_igw: - state: absent - vpc_id: '{{ vpc_result.vpc.id }}' - register: vpc_igw - name: Cleanup instance ec2_instance: - name: '{{ resource_prefix }}-instance' + instance_ids: '{{ create_ec2_instance_result.instance_ids }}' state: absent - name: Cleanup instance eip ec2_eip: state: absent public_ip: '{{ instance_eip.public_ip }}' + register: eip_cleanup + retries: 5 + delay: 5 + until: eip_cleanup is successful + - name: Cleanup IGW + ec2_vpc_igw: + state: absent + vpc_id: '{{ vpc_result.vpc.id }}' + register: vpc_igw - name: Cleanup security group ec2_group: state: absent @@ -642,6 +648,18 @@ cidr_block: '{{ vpc_cidr }}' # ===================================================== always: + - name: Cleanup instance (by id) + ec2_instance: + instance_ids: '{{ create_ec2_instance_result.instance_ids }}' + state: absent + wait: true + ignore_errors: true + - name: Cleanup instance (by name) + ec2_instance: + name: '{{ resource_prefix }}-instance' + state: absent + wait: true + ignore_errors: true - name: Cleanup ENI A ec2_eni: state: absent @@ -652,20 +670,19 @@ state: absent eni_id: '{{ eni_create_b.interface.id }}' ignore_errors: true + - name: Cleanup instance eip + ec2_eip: + state: absent + public_ip: '{{ instance_eip.public_ip }}' + retries: 5 + delay: 5 + until: eip_cleanup is successful + ignore_errors: true - name: Cleanup IGW ec2_vpc_igw: state: absent vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw - - name: Cleanup instance - ec2_instance: - name: '{{ resource_prefix }}-instance' - state: absent - ignore_errors: true - - name: Cleanup instance eip - ec2_eip: - state: absent - public_ip: '{{ instance_eip.public_ip }}' ignore_errors: true - name: Cleanup security group ec2_group: