From c64eef56defbaa4a66a3d1ae042bfa68eb2c7eaa Mon Sep 17 00:00:00 2001 From: Dan K Date: Sun, 30 May 2021 05:36:42 +0000 Subject: [PATCH] Merge ec2_asg_instance_refresh and ec2_asg_instance_refreshes_info targets --- .../ec2_asg_instance_refresh/tasks/main.yml | 107 ++++++ .../defaults/main.yml | 6 - .../tasks/main.yml | 336 ------------------ .../tasks/refresh_and_cancel_three_times.yml | 18 - .../vars/main.yml | 0 5 files changed, 107 insertions(+), 360 deletions(-) delete mode 100644 tests/integration/targets/ec2_asg_instance_refreshes_info/defaults/main.yml delete mode 100644 tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/main.yml delete mode 100644 tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/refresh_and_cancel_three_times.yml delete mode 100644 tests/integration/targets/ec2_asg_instance_refreshes_info/vars/main.yml diff --git a/tests/integration/targets/ec2_asg_instance_refresh/tasks/main.yml b/tests/integration/targets/ec2_asg_instance_refresh/tasks/main.yml index 1dd61285780..037bf856216 100644 --- a/tests/integration/targets/ec2_asg_instance_refresh/tasks/main.yml +++ b/tests/integration/targets/ec2_asg_instance_refresh/tasks/main.yml @@ -246,6 +246,113 @@ - "'can not pass preferences dict when canceling a refresh' in result.msg" ignore_errors: no + # ============================================================ + # ============================================================ + + - name: run setup with refresh_and_cancel_three_times.yml + include_tasks: refresh_and_cancel_three_times.yml + loop: "{{ query('sequence', 'start=1 end=3') }}" + + - name: test getting info for an ASG name + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + region: "{{ aws_region }}" + ignore_errors: yes + register: output + + - assert: + that: + - output | community.general.json_query(inst_refresh_id_json_query) | unique | length == 3 + vars: + inst_refresh_id_json_query: instance_refreshes[].instance_refresh_id + + - name: test using fake refresh ID + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + ids: ['0e367f58-blabla-bla-bla-ca870dc5dbfe'] + ignore_errors: yes + register: output + + - assert: + that: + - "{{ output.instance_refreshes|length }} == 0 " + + - name: test using a real refresh ID + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + ids: [ '{{ refreshout.instance_refresh_id }}' ] + ignore_errors: yes + register: output + + - assert: + that: + - "{{ output.instance_refreshes|length }} == 1 " + + - name: test getting info for an ASG name which doesn't exist + ec2_asg_instance_refreshes_info: + name: n0n3x1stentname27b + ignore_errors: yes + register: output + + - assert: + that: + - "'Failed to describe InstanceRefreshes: An error occurred (ValidationError) when calling the DescribeInstanceRefreshes operation: AutoScalingGroup name not found - AutoScalingGroup n0n3x1stentname27b not found' == output.msg" + + - name: assert that the correct number of records are returned + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + ignore_errors: yes + register: output + + - assert: + that: + - "{{ output.instance_refreshes|length }} == 3" + + - name: assert that valid message with fake-token is returned + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + next_token: "fake-token-123" + ignore_errors: yes + register: output + + - assert: + that: + - '"Failed to describe InstanceRefreshes: An error occurred (InvalidNextToken) when calling the DescribeInstanceRefreshes operation: The token ''fake-token-123'' is invalid." == output.msg' + + - name: assert that max records=1 returns no more than one record + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + max_records: 1 + ignore_errors: yes + register: output + + - assert: + that: + - "{{ output.instance_refreshes|length }} < 2" + + - name: assert that valid message with real-token is returned + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + next_token: "{{ output.next_token }}" + ignore_errors: yes + register: output + + - assert: + that: + - "{{ output.instance_refreshes|length }} == 2 " + + - name: test using both real nextToken and max_records=1 + ec2_asg_instance_refreshes_info: + name: "{{ resource_prefix }}-asg" + max_records: 1 + next_token: "{{ output.next_token }}" + ignore_errors: yes + register: output + + - assert: + that: + - "{{ output.instance_refreshes|length }} == 1" + always: diff --git a/tests/integration/targets/ec2_asg_instance_refreshes_info/defaults/main.yml b/tests/integration/targets/ec2_asg_instance_refreshes_info/defaults/main.yml deleted file mode 100644 index dd9f26a32d6..00000000000 --- a/tests/integration/targets/ec2_asg_instance_refreshes_info/defaults/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -# defaults file for ec2_asg -# Amazon Linux 2 AMI 2019.06.12 (HVM), GP2 Volume Type -vpc_seed: '{{ resource_prefix }}' -ec2_ami_name: 'amzn2-ami-hvm-2.0.20190612-x86_64-gp2' -subnet_a_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.32.0/24' diff --git a/tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/main.yml b/tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/main.yml deleted file mode 100644 index b14bba5bc3f..00000000000 --- a/tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/main.yml +++ /dev/null @@ -1,336 +0,0 @@ ---- -- name: setup credentials and region - module_defaults: - group/aws: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - - collections: - - amazon.aws - - block: - - #NOTE: entire ASG setup is 'borrowed' from ec2_asg - - name: Find AMI to use - ec2_ami_info: - owners: 'amazon' - filters: - name: '{{ ec2_ami_name }}' - register: ec2_amis - - set_fact: - ec2_ami_image: '{{ ec2_amis.images[0].image_id }}' - - - name: load balancer name has to be less than 32 characters - set_fact: - load_balancer_name: "{{ item }}-lb" - loop: "{{ resource_prefix | regex_findall('.{8}$') }}" - - # Set up the testing dependencies: VPC, subnet, security group, and two launch configurations - - name: Create VPC for use in testing - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - cidr_block: '{{ subnet_a_cidr }}' - tenancy: default - register: testing_vpc - - - name: Create internet gateway for use in testing - ec2_vpc_igw: - vpc_id: "{{ testing_vpc.vpc.id }}" - state: present - register: igw - - - name: Create subnet for use in testing - ec2_vpc_subnet: - state: present - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: '{{ subnet_a_cidr }}' - az: "{{ aws_region }}a" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: testing_subnet - - - name: create routing rules - ec2_vpc_route_table: - vpc_id: "{{ testing_vpc.vpc.id }}" - tags: - created: "{{ resource_prefix }}-route" - routes: - - dest: 0.0.0.0/0 - gateway_id: "{{ igw.gateway_id }}" - subnets: - - "{{ testing_subnet.subnet.id }}" - - - name: create a security group with the vpc created in the ec2_setup - ec2_group: - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ testing_vpc.vpc.id }}" - rules: - - proto: tcp - from_port: 22 - to_port: 22 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 80 - to_port: 80 - cidr_ip: 0.0.0.0/0 - register: sg - - - name: ensure launch configs exist - ec2_lc: - name: "{{ item }}" - assign_public_ip: true - image_id: "{{ ec2_ami_image }}" - user_data: | - package_upgrade: true - package_update: true - packages: - - httpd - runcmd: - - "service httpd start" - security_groups: "{{ sg.group_id }}" - instance_type: t3.micro - loop: - - "{{ resource_prefix }}-lc" - - "{{ resource_prefix }}-lc-2" - - - name: launch asg and do not wait for instances to be deemed healthy (no ELB) - ec2_asg: - name: "{{ resource_prefix }}-asg" - launch_config_name: "{{ resource_prefix }}-lc" - desired_capacity: 1 - min_size: 1 - max_size: 1 - vpc_zone_identifier: "{{ testing_subnet.subnet.id }}" - wait_for_instances: no - state: present - register: output - - - assert: - that: - - "output.viable_instances == 0" - - # ============================================================ - # ============================================================ - - - name: run setup with refresh_and_cancel_three_times.yml - include_tasks: refresh_and_cancel_three_times.yml - loop: "{{ query('sequence', 'start=1 end=3') }}" - - - name: test getting info for an ASG name - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - region: "{{ aws_region }}" - ignore_errors: yes - register: output - - - assert: - that: - - output | community.general.json_query(inst_refresh_id_json_query) | unique | length == 3 - vars: - inst_refresh_id_json_query: instance_refreshes[].instance_refresh_id - - - name: test using fake refresh ID - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - ids: ['0e367f58-blabla-bla-bla-ca870dc5dbfe'] - ignore_errors: yes - register: output - - - assert: - that: - - "{{ output.instance_refreshes|length }} == 0 " - - - name: test using a real refresh ID - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - ids: [ '{{ refreshout.instance_refresh_id }}' ] - ignore_errors: yes - register: output - - - assert: - that: - - "{{ output.instance_refreshes|length }} == 1 " - - - name: test getting info for an ASG name which doesn't exist - ec2_asg_instance_refreshes_info: - name: n0n3x1stentname27b - ignore_errors: yes - register: output - - - assert: - that: - - "'Failed to describe InstanceRefreshes: An error occurred (ValidationError) when calling the DescribeInstanceRefreshes operation: AutoScalingGroup name not found - AutoScalingGroup n0n3x1stentname27b not found' == output.msg" - - - name: assert that the correct number of records are returned - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - ignore_errors: yes - register: output - - - assert: - that: - - "{{ output.instance_refreshes|length }} == 3" - - - name: assert that valid message with fake-token is returned - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - next_token: "fake-token-123" - ignore_errors: yes - register: output - - - assert: - that: - - '"Failed to describe InstanceRefreshes: An error occurred (InvalidNextToken) when calling the DescribeInstanceRefreshes operation: The token ''fake-token-123'' is invalid." == output.msg' - - - name: assert that max records=1 returns no more than one record - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - max_records: 1 - ignore_errors: yes - register: output - - - assert: - that: - - "{{ output.instance_refreshes|length }} < 2" - - - name: assert that valid message with real-token is returned - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - next_token: "{{ output.next_token }}" - ignore_errors: yes - register: output - - - assert: - that: - - "{{ output.instance_refreshes|length }} == 2 " - - - name: test using both real nextToken and max_records=1 - ec2_asg_instance_refreshes_info: - name: "{{ resource_prefix }}-asg" - max_records: 1 - next_token: "{{ output.next_token }}" - ignore_errors: yes - register: output - - - assert: - that: - - "{{ output.instance_refreshes|length }} == 1" - - always: - - - name: kill asg - ec2_asg: - name: "{{ resource_prefix }}-asg" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - - # Remove the testing dependencies - - - name: remove the load balancer - ec2_elb_lb: - name: "{{ load_balancer_name }}" - state: absent - security_group_ids: - - "{{ sg.group_id }}" - subnets: "{{ testing_subnet.subnet.id }}" - wait: yes - connection_draining_timeout: 60 - listeners: - - protocol: http - load_balancer_port: 80 - instance_port: 80 - health_check: - ping_protocol: tcp - ping_port: 80 - ping_path: "/" - response_timeout: 5 - interval: 10 - unhealthy_threshold: 4 - healthy_threshold: 2 - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - - - name: remove launch configs - ec2_lc: - name: "{{ resource_prefix }}-lc" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - loop: - - "{{ resource_prefix }}-lc" - - "{{ resource_prefix }}-lc-2" - - - name: delete launch template - ec2_launch_template: - name: "{{ resource_prefix }}-lt" - state: absent - register: del_lt - retries: 10 - until: del_lt is not failed - ignore_errors: true - - - name: remove the security group - ec2_group: - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ testing_vpc.vpc.id }}" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - - - name: remove routing rules - ec2_vpc_route_table: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - tags: - created: "{{ resource_prefix }}-route" - routes: - - dest: 0.0.0.0/0 - gateway_id: "{{ igw.gateway_id }}" - subnets: - - "{{ testing_subnet.subnet.id }}" - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - - - name: remove internet gateway - ec2_vpc_igw: - vpc_id: "{{ testing_vpc.vpc.id }}" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - - - name: remove the subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: '{{ subnet_a_cidr }}' - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - - - name: remove the VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - cidr_block: '{{ subnet_a_cidr }}' - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 diff --git a/tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/refresh_and_cancel_three_times.yml b/tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/refresh_and_cancel_three_times.yml deleted file mode 100644 index b840117e453..00000000000 --- a/tests/integration/targets/ec2_asg_instance_refreshes_info/tasks/refresh_and_cancel_three_times.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -- name: test starting a refresh with an ASG name - ec2_asg_instance_refresh: - name: "{{ resource_prefix }}-asg" - state: "started" - ignore_errors: no - retries: 10 - delay: 5 - register: refreshout - until: refreshout is not failed -- debug: var=refreshout - -- name: test canceling a refresh with an ASG name - ec2_asg_instance_refresh: - name: "{{ resource_prefix }}-asg" - state: "cancelled" - ignore_errors: yes diff --git a/tests/integration/targets/ec2_asg_instance_refreshes_info/vars/main.yml b/tests/integration/targets/ec2_asg_instance_refreshes_info/vars/main.yml deleted file mode 100644 index e69de29bb2d..00000000000