-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elb_instance - initial integration tests (#768)
elb_instance - initial integration tests SUMMARY Rewrite elb_instance (ec2_elb) for boto3 ISSUE TYPE Feature Pull Request COMPONENT NAME elb_instance ADDITIONAL INFORMATION fixes: #384 Reviewed-by: Markus Bergholz <[email protected]> Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None>
- Loading branch information
Showing
16 changed files
with
753 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- elb_instance - Python 3 compatability fix (https://github.com/ansible-collections/community.aws/issues/384). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cloud/aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
# defaults file for ec2_elb_lb | ||
elb_name_1: 'ansible-test-{{ tiny_prefix }}-1' | ||
elb_name_2: 'ansible-test-{{ tiny_prefix }}-2' | ||
|
||
vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' | ||
subnet_cidr_1: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24' | ||
subnet_cidr_2: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24' | ||
|
||
availability_zone_a: '{{ ec2_availability_zone_names[0] }}' | ||
availability_zone_b: '{{ ec2_availability_zone_names[1] }}' | ||
|
||
elb_listeners: | ||
- protocol: tcp | ||
load_balancer_port: 80 | ||
instance_port: 80 | ||
instance_protocol: tcp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dependencies: | ||
- prepare_tests | ||
- setup_ec2 | ||
- setup_ec2_facts |
16 changes: 16 additions & 0 deletions
16
tests/integration/targets/elb_instance/tasks/cleanup_elbs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- name: remove the public load balancer | ||
elb_classic_lb: | ||
name: "{{ elb_name_1 }}" | ||
state: absent | ||
wait: true | ||
register: result | ||
ignore_errors: true | ||
|
||
- name: remove the private load balancer | ||
elb_classic_lb: | ||
name: "{{ elb_name_2 }}" | ||
state: absent | ||
wait: true | ||
register: result | ||
ignore_errors: true |
23 changes: 23 additions & 0 deletions
23
tests/integration/targets/elb_instance/tasks/cleanup_instances.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
- name: Delete instance | ||
ec2_instance: | ||
instance_ids: | ||
- '{{ instance_a }}' | ||
- '{{ instance_b }}' | ||
state: absent | ||
wait: true | ||
ignore_errors: true | ||
|
||
- name: Delete ASG | ||
ec2_asg: | ||
name: "ansible-test-{{ tiny_prefix }}-elb" | ||
state: absent | ||
ignore_errors: true | ||
register: ec2_asg_a | ||
|
||
- name: Delete Launch Template | ||
ec2_lc: | ||
name: "ansible-test-{{ tiny_prefix }}-elb" | ||
state: absent | ||
ignore_errors: true | ||
register: ec2_lc_a |
26 changes: 26 additions & 0 deletions
26
tests/integration/targets/elb_instance/tasks/cleanup_vpc.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
- name: delete security groups | ||
ec2_group: | ||
name: '{{ item }}' | ||
state: absent | ||
ignore_errors: true | ||
loop: | ||
- '{{ resource_prefix }}-a' | ||
- '{{ resource_prefix }}-b' | ||
|
||
- name: delete subnets | ||
ec2_vpc_subnet: | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
cidr: '{{ item }}' | ||
state: absent | ||
ignore_errors: true | ||
loop: | ||
- '{{ subnet_cidr_1 }}' | ||
- '{{ subnet_cidr_2 }}' | ||
|
||
- name: delete VPC | ||
ec2_vpc_net: | ||
cidr_block: '{{ vpc_cidr }}' | ||
state: absent | ||
name: '{{ resource_prefix }}' | ||
ignore_errors: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
- module_defaults: | ||
group/aws: | ||
region: "{{ aws_region }}" | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
security_token: "{{ security_token | default(omit) }}" | ||
collections: | ||
- community.aws | ||
- amazon.aws | ||
block: | ||
# ============================================================ | ||
|
||
- include_tasks: setup_vpc.yml | ||
- include_tasks: setup_elbs.yml | ||
- include_tasks: setup_instances.yml | ||
|
||
# ============================================================ | ||
|
||
- include_tasks: manage_instances.yml | ||
- include_tasks: manage_asgs.yml | ||
|
||
always: | ||
|
||
# ============================================================ | ||
|
||
- include_tasks: cleanup_elbs.yml | ||
- include_tasks: cleanup_instances.yml | ||
- include_tasks: cleanup_vpc.yml |
110 changes: 110 additions & 0 deletions
110
tests/integration/targets/elb_instance/tasks/manage_asgs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
- name: Get ASG info | ||
ec2_asg_info: | ||
name: "ansible-test-{{ tiny_prefix }}-elb$" | ||
register: asg_info | ||
|
||
- name: Store Instance ID from ASG | ||
set_fact: | ||
instance_asg: '{{ asg_info.results[0].instances[0].instance_id }}' | ||
|
||
- name: 'Remove an instance from ELB (check_mode)' | ||
elb_instance: | ||
instance_id: '{{ instance_asg }}' | ||
state: 'absent' | ||
wait_timeout: 60 | ||
register: remove_instance | ||
check_mode: true | ||
|
||
- elb_classic_lb_info: | ||
names: '{{ elb_name_1 }}' | ||
register: elb_info_1 | ||
- elb_classic_lb_info: | ||
names: '{{ elb_name_2 }}' | ||
register: elb_info_2 | ||
|
||
- assert: | ||
that: | ||
- remove_instance is successful | ||
# - remove_instance is changed | ||
# It really shouldn't be returning a fact here | ||
- '"ansible_facts" in remove_instance' | ||
- '"ec2_elbs" in remove_instance.ansible_facts' | ||
- elb_name_1 in remove_instance.ansible_facts.ec2_elbs | ||
- elb_name_2 in remove_instance.ansible_facts.ec2_elbs | ||
# Check the real state didn't change | ||
- instance_asg in elb_info_1.elbs[0].instances_inservice | ||
- instance_asg in elb_info_2.elbs[0].instances_inservice | ||
|
||
- name: 'Remove an instance from ELB' | ||
elb_instance: | ||
instance_id: '{{ instance_asg }}' | ||
state: 'absent' | ||
wait_timeout: 60 | ||
register: remove_instance | ||
|
||
- elb_classic_lb_info: | ||
names: '{{ elb_name_1 }}' | ||
register: elb_info_1 | ||
- elb_classic_lb_info: | ||
names: '{{ elb_name_2 }}' | ||
register: elb_info_2 | ||
|
||
- assert: | ||
that: | ||
- remove_instance is successful | ||
- remove_instance is changed | ||
# It really shouldn't be returning a fact here | ||
- '"ansible_facts" in remove_instance' | ||
- '"ec2_elbs" in remove_instance.ansible_facts' | ||
- elb_name_1 in remove_instance.ansible_facts.ec2_elbs | ||
- elb_name_2 in remove_instance.ansible_facts.ec2_elbs | ||
# Check the real state | ||
- instance_asg not in elb_info_1.elbs[0].instances_inservice | ||
- instance_asg not in elb_info_2.elbs[0].instances_inservice | ||
|
||
- name: 'Remove an instance from ELB - idempotency (check_mode)' | ||
elb_instance: | ||
instance_id: '{{ instance_asg }}' | ||
state: 'absent' | ||
wait_timeout: 60 | ||
register: remove_instance | ||
check_mode: true | ||
|
||
- elb_classic_lb_info: | ||
names: '{{ elb_name_1 }}' | ||
register: elb_info_1 | ||
- elb_classic_lb_info: | ||
names: '{{ elb_name_2 }}' | ||
register: elb_info_2 | ||
|
||
- assert: | ||
that: | ||
- remove_instance is successful | ||
- remove_instance is not changed | ||
# Check the real state | ||
- instance_asg not in elb_info_1.elbs[0].instances_inservice | ||
- instance_asg not in elb_info_2.elbs[0].instances_inservice | ||
|
||
- name: 'Remove an instance from ELB - idempotency' | ||
elb_instance: | ||
instance_id: '{{ instance_asg }}' | ||
state: 'absent' | ||
wait_timeout: 60 | ||
register: remove_instance | ||
|
||
- elb_classic_lb_info: | ||
names: '{{ elb_name_1 }}' | ||
register: elb_info_1 | ||
- elb_classic_lb_info: | ||
names: '{{ elb_name_2 }}' | ||
register: elb_info_2 | ||
|
||
- assert: | ||
that: | ||
- remove_instance is successful | ||
# XXX always returns the ELBs the ASG belongs to | ||
# - remove_instance is not changed | ||
# Check the real state | ||
- instance_asg not in elb_info_1.elbs[0].instances_inservice | ||
- instance_asg not in elb_info_2.elbs[0].instances_inservice |
Oops, something went wrong.