mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adding an integration test for the ec2_elb module
This commit is contained in:
parent
1576e8d611
commit
c9df855d38
13 changed files with 286 additions and 10 deletions
|
@ -48,7 +48,7 @@ $(CREDENTIALS_FILE):
|
||||||
@exit 1
|
@exit 1
|
||||||
|
|
||||||
amazon: $(CREDENTIALS_FILE)
|
amazon: $(CREDENTIALS_FILE)
|
||||||
BOTO_CONFIG=/dev/null ansible-playbook amazon.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
|
ANSIBLE_SSH_PIPELINING=no BOTO_CONFIG=/dev/null ansible-playbook amazon.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -e "resource_prefix=$(CLOUD_RESOURCE_PREFIX)" -v $(TEST_FLAGS) ; \
|
||||||
RC=$$? ; \
|
RC=$$? ; \
|
||||||
CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make amazon_cleanup ; \
|
CLOUD_RESOURCE_PREFIX="$(CLOUD_RESOURCE_PREFIX)" make amazon_cleanup ; \
|
||||||
exit $$RC;
|
exit $$RC;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
- hosts: testhost
|
- hosts: amazon
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
roles:
|
roles:
|
||||||
- { role: test_ec2_key, tags: test_ec2_key }
|
- { role: test_ec2_key, tags: test_ec2_key }
|
||||||
|
@ -9,6 +9,24 @@
|
||||||
#- { role: test_ec2_facts, tags: test_ec2_facts }
|
#- { role: test_ec2_facts, tags: test_ec2_facts }
|
||||||
- { role: test_ec2_elb_lb, tags: test_ec2_elb_lb }
|
- { role: test_ec2_elb_lb, tags: test_ec2_elb_lb }
|
||||||
#- { role: test_ec2_eip, tags: test_ec2_eip }
|
#- { role: test_ec2_eip, tags: test_ec2_eip }
|
||||||
#- { role: test_ec2_elb, tags: test_ec2_elb }
|
|
||||||
#- { role: test_ec2_ami, tags: test_ec2_ami }
|
#- { role: test_ec2_ami, tags: test_ec2_ami }
|
||||||
#- { role: test_ec2, tags: test_ec2 }
|
#- { role: test_ec2, tags: test_ec2 }
|
||||||
|
|
||||||
|
# complex test for ec2_elb, split up over multiple plays
|
||||||
|
# since there is a setup component as well as the test which
|
||||||
|
# runs on a different set of hosts (ec2 instances)
|
||||||
|
|
||||||
|
- hosts: amazon
|
||||||
|
roles:
|
||||||
|
- { role: ec2_provision_instances, tags: test_ec2_elb, count: 5 }
|
||||||
|
|
||||||
|
- hosts: ec2
|
||||||
|
gather_facts: no
|
||||||
|
remote_user: ec2-user
|
||||||
|
sudo: true
|
||||||
|
roles:
|
||||||
|
- { role: ec2_elb_instance_setup, tags: test_ec2_elb }
|
||||||
|
|
||||||
|
- hosts: amazon
|
||||||
|
roles:
|
||||||
|
- { role: test_ec2_elb, tags: test_ec2_elb }
|
||||||
|
|
|
@ -25,5 +25,5 @@ groups_tree_var=3000
|
||||||
grandparent_var=2000
|
grandparent_var=2000
|
||||||
overridden_in_parent=2000
|
overridden_in_parent=2000
|
||||||
|
|
||||||
[amazon:children]
|
[amazon]
|
||||||
local
|
localhost ansible_ssh_host=127.0.0.1 ansible_connection=local
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
# defaults for ec2_elb_setup
|
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<head>Hi!</head>
|
||||||
|
<body>
|
||||||
|
Hello!
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1 @@
|
||||||
|
dependencies: []
|
14
test/integration/roles/ec2_elb_instance_setup/tasks/main.yml
Normal file
14
test/integration/roles/ec2_elb_instance_setup/tasks/main.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
# tasks file for ec2_elb_setup
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# install apache on the ec2 instances
|
||||||
|
|
||||||
|
- name: install apache on new ec2 instances
|
||||||
|
yum: name=httpd
|
||||||
|
|
||||||
|
- name: start and enable apache
|
||||||
|
service: name=httpd state=started enabled=yes
|
||||||
|
|
||||||
|
- name: create an index.html landing page
|
||||||
|
copy: dest=/var/www/html/index.html src=index.html owner=root group=root mode=0644
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
# defaults file for ec2_provision_isntances
|
||||||
|
count: 1
|
|
@ -0,0 +1,3 @@
|
||||||
|
dependencies:
|
||||||
|
- prepare_tests
|
||||||
|
- setup_ec2
|
|
@ -0,0 +1,49 @@
|
||||||
|
---
|
||||||
|
# tasks file for ec2_provision_instances
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# create a keypair using the ssh key
|
||||||
|
|
||||||
|
- name: create the keypair for ec2
|
||||||
|
ec2_key:
|
||||||
|
name: "{{ resource_prefix }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
key_material: "{{ key_material }}"
|
||||||
|
wait: yes
|
||||||
|
state: present
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# create some instances for testing, and add them to a new
|
||||||
|
# group ("ec2") for use later
|
||||||
|
|
||||||
|
- name: create ec2 instances for testing
|
||||||
|
ec2:
|
||||||
|
instance_type: t1.micro
|
||||||
|
image: ami-fb8e9292
|
||||||
|
group: default
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
key_name: "{{ resource_prefix }}"
|
||||||
|
wait: yes
|
||||||
|
instance_tags:
|
||||||
|
Name: "{{ resource_prefix }}"
|
||||||
|
exact_count: "{{ count }}"
|
||||||
|
count_tag:
|
||||||
|
Name: "{{ resource_prefix }}"
|
||||||
|
register: ec2_provision_result
|
||||||
|
|
||||||
|
- name: add ec2 instances to a new group
|
||||||
|
add_host:
|
||||||
|
hostname: "{{ item.public_ip }}"
|
||||||
|
groups: "ec2"
|
||||||
|
ansible_ssh_private_key_file: "{{ sshkey }}"
|
||||||
|
with_items: ec2_provision_result.instances
|
||||||
|
|
||||||
|
- name: wait for the instances to become available
|
||||||
|
wait_for:
|
||||||
|
port: 22
|
||||||
|
host: "{{ item.public_ip }}"
|
||||||
|
with_items: ec2_provision_result.instances
|
|
@ -1,3 +1 @@
|
||||||
dependencies:
|
dependencies: []
|
||||||
- prepare_tests
|
|
||||||
- setup_ec2
|
|
||||||
|
|
|
@ -1,2 +1,186 @@
|
||||||
---
|
---
|
||||||
# tasks file for test_ec2_elb
|
# tasks file for test_ec2_elb
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# create an ELB for testing
|
||||||
|
|
||||||
|
- name: create the test load balancer
|
||||||
|
ec2_elb_lb:
|
||||||
|
name: "{{ resource_prefix }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
state: present
|
||||||
|
zones:
|
||||||
|
- "{{ ec2_region }}b"
|
||||||
|
- "{{ ec2_region }}c"
|
||||||
|
listeners:
|
||||||
|
- protocol: http
|
||||||
|
load_balancer_port: 80
|
||||||
|
instance_port: 80
|
||||||
|
health_check:
|
||||||
|
ping_protocol: http
|
||||||
|
ping_port: 80
|
||||||
|
ping_path: "/index.html"
|
||||||
|
response_timeout: 5
|
||||||
|
interval: 10
|
||||||
|
unhealthy_threshold: 3
|
||||||
|
healthy_threshold: 2
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert the test load balancer was created correctly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- '"failed" not in result'
|
||||||
|
- 'result.elb.status == "created"'
|
||||||
|
- '"{{ ec2_region }}b" in result.elb.zones'
|
||||||
|
- '"{{ ec2_region }}c" in result.elb.zones'
|
||||||
|
- 'result.elb.health_check.healthy_threshold == 2'
|
||||||
|
- 'result.elb.health_check.interval == 10'
|
||||||
|
- 'result.elb.health_check.target == "HTTP:80/index.html"'
|
||||||
|
- 'result.elb.health_check.timeout == 5'
|
||||||
|
- 'result.elb.health_check.unhealthy_threshold == 3'
|
||||||
|
- '[80, 80, "HTTP", "HTTP"] in result.elb.listeners'
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# add one of the instances to the LB
|
||||||
|
|
||||||
|
- name: add first instance to the load balancer
|
||||||
|
ec2_elb:
|
||||||
|
ec2_elbs: "{{ resource_prefix }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
instance_id: "{{ ec2_provision_result.instance_ids[0] }}"
|
||||||
|
state: present
|
||||||
|
wait_timeout: 300
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert the first instance was added ok
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == True'
|
||||||
|
- '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# add all other instances to the LB
|
||||||
|
|
||||||
|
- name: add other instances to the load balancer
|
||||||
|
ec2_elb:
|
||||||
|
ec2_elbs: "{{ resource_prefix }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
instance_id: "{{ item }}"
|
||||||
|
state: present
|
||||||
|
wait_timeout: 300
|
||||||
|
with_items: "ec2_provision_result.instance_ids[1:]"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert the other instances were added ok
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'item.changed == True'
|
||||||
|
- '"{{resource_prefix}}" in item.ansible_facts.ec2_elbs'
|
||||||
|
with_items: result.results
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# shutdown http first instance so it goes out of service
|
||||||
|
|
||||||
|
#- name: terminate first instance
|
||||||
|
# ec2:
|
||||||
|
# ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
# ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
# region: "{{ ec2_region }}"
|
||||||
|
# state: 'absent'
|
||||||
|
# instance_ids: "{{ ec2_provision_result.instance_ids[0] }}"
|
||||||
|
# register: result
|
||||||
|
#
|
||||||
|
#- name: assert the instance was terminated
|
||||||
|
# assert:
|
||||||
|
# that:
|
||||||
|
# - 'result.changed == True'
|
||||||
|
# - 'result.instance_ids[0] == ec2_provision_result.instance_ids[0]'
|
||||||
|
#
|
||||||
|
#- name: wait for the instance to die
|
||||||
|
# wait_for: port=80 host="{{ec2_provision_result.instances[0].public_ip}}" state=absent
|
||||||
|
|
||||||
|
- name: "shutdown the apache service on the first instance ({{ec2_provision_result.instances[0].public_ip}})"
|
||||||
|
service: name=httpd state=stopped
|
||||||
|
remote_user: "ec2-user"
|
||||||
|
sudo: yes
|
||||||
|
sudo_user: root
|
||||||
|
delegate_to: "{{ec2_provision_result.instances[0].public_ip}}"
|
||||||
|
|
||||||
|
- name: assert that the httpd service was stopped
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == True'
|
||||||
|
|
||||||
|
- name: pause long enough for the instance to go out of service
|
||||||
|
pause: seconds=60
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# remove the out of service instance
|
||||||
|
|
||||||
|
- name: remove the out of service instance
|
||||||
|
ec2_elb:
|
||||||
|
ec2_elbs: "{{ resource_prefix }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
instance_id: "{{ ec2_provision_result.instance_ids[0] }}"
|
||||||
|
state: absent
|
||||||
|
wait_timeout: 300
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert that the out of service instance was removed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == True'
|
||||||
|
- '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# remove another instance that is still in service
|
||||||
|
|
||||||
|
- name: remove the second instance
|
||||||
|
ec2_elb:
|
||||||
|
ec2_elbs: "{{ resource_prefix }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
instance_id: "{{ ec2_provision_result.instance_ids[1] }}"
|
||||||
|
state: absent
|
||||||
|
wait_timeout: 300
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert that the second instance was removed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == True'
|
||||||
|
- '"{{resource_prefix}}" in result.ansible_facts.ec2_elbs'
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# remove all other instances
|
||||||
|
|
||||||
|
- name: remove the rest of the instances
|
||||||
|
ec2_elb:
|
||||||
|
ec2_elbs: "{{ resource_prefix }}"
|
||||||
|
ec2_access_key: "{{ ec2_access_key }}"
|
||||||
|
ec2_secret_key: "{{ ec2_secret_key }}"
|
||||||
|
region: "{{ ec2_region }}"
|
||||||
|
instance_id: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
wait_timeout: 300
|
||||||
|
with_items: "ec2_provision_result.instance_ids[2:]"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert the other instances were removed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'item.changed == True'
|
||||||
|
- '"{{resource_prefix}}" in item.ansible_facts.ec2_elbs'
|
||||||
|
with_items: result.results
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
---
|
|
||||||
# vars file for test_ec2_elb
|
|
Loading…
Reference in a new issue