mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Fix ec2_instance eventual consistency when wait: false (#51885)
* Do not return 'instances' when wait is false * Added integration tests for wait: false * Added changelog fragment * Fix test suite to work with ec2_instance * Additional permissions * Enforce boto3 version * Fix broken tests * Improve error messages * fix linter issues
This commit is contained in:
committed by
Will Thames
parent
d0db99e023
commit
5c6b16edc3
@@ -20,7 +20,7 @@
|
||||
ebs:
|
||||
delete_on_termination: true
|
||||
<<: *aws_connection_info
|
||||
register: instance_creation
|
||||
register: basic_instance
|
||||
|
||||
- name: Make basic instance(check mode)
|
||||
ec2_instance:
|
||||
@@ -28,7 +28,7 @@
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
security_groups: "{{ sg.group_id }}"
|
||||
instance_type: t2.micro
|
||||
vpc_subnet_id: "{{ testing_subnet_c.subnet.id }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
volumes:
|
||||
- device_name: /dev/sda1
|
||||
ebs:
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
- name: set connection information for all tasks
|
||||
set_fact:
|
||||
aws_connection_info: &aws_connection_info
|
||||
aws_access_key: "{{ aws_access_key }}"
|
||||
aws_secret_key: "{{ aws_secret_key }}"
|
||||
security_token: "{{ security_token }}"
|
||||
region: "{{ aws_region }}"
|
||||
no_log: true
|
||||
|
||||
- name: New instance and don't wait for it to complete
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-no-wait"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
wait: false
|
||||
instance_type: t2.micro
|
||||
<<: *aws_connection_info
|
||||
register: in_test_vpc
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- in_test_vpc is not failed
|
||||
- in_test_vpc is changed
|
||||
- in_test_vpc.instances is not defined
|
||||
- in_test_vpc.instance_ids is defined
|
||||
- in_test_vpc.instance_ids | length > 0
|
||||
|
||||
- name: New instance and don't wait for it to complete ( check mode )
|
||||
ec2_instance:
|
||||
name: "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
image_id: "{{ ec2_ami_image[aws_region] }}"
|
||||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
|
||||
tags:
|
||||
TestId: "{{ resource_prefix }}"
|
||||
wait: false
|
||||
instance_type: t2.micro
|
||||
<<: *aws_connection_info
|
||||
check_mode: yes
|
||||
|
||||
- name: Facts for ec2 test instance
|
||||
ec2_instance_facts:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait"
|
||||
"instance-state-name": "running"
|
||||
<<: *aws_connection_info
|
||||
register: real_instance_fact
|
||||
until: real_instance_fact.instances | length > 0
|
||||
retries: 10
|
||||
|
||||
- name: Facts for checkmode ec2 test instance
|
||||
ec2_instance_facts:
|
||||
filters:
|
||||
"tag:Name": "{{ resource_prefix }}-test-no-wait-checkmode"
|
||||
"instance-state-name": "running"
|
||||
<<: *aws_connection_info
|
||||
register: checkmode_instance_fact
|
||||
|
||||
- name: "Confirm whether the check mode is working normally."
|
||||
assert:
|
||||
that:
|
||||
- "{{ real_instance_fact.instances | length }} > 0"
|
||||
- "{{ checkmode_instance_fact.instances | length }} == 0"
|
||||
@@ -98,7 +98,7 @@
|
||||
- include_tasks: iam_instance_role.yml
|
||||
- include_tasks: checkmode_tests.yml
|
||||
- include_tasks: ebs_optimized.yml
|
||||
|
||||
- include_tasks: instance_no_wait.yml
|
||||
|
||||
# ============================================================
|
||||
|
||||
|
||||
@@ -36,3 +36,11 @@
|
||||
that:
|
||||
- ec2_instance_cpu_options_creation.failed
|
||||
- 'ec2_instance_cpu_options_creation.msg == "cpu_options is only supported with botocore >= 1.10.16"'
|
||||
|
||||
always:
|
||||
- name: cleanup c4.large in case graceful failure was in fact a graceful success
|
||||
ec2_instance:
|
||||
state: absent
|
||||
name: "ansible-test-{{ resource_prefix | regex_search('([0-9]+)$') }}-ec2"
|
||||
<<: *aws_connection_info
|
||||
ignore_errors: yes
|
||||
|
||||
@@ -16,7 +16,7 @@ PYTHON=${ANSIBLE_TEST_PYTHON_INTERPRETER:-python}
|
||||
export ANSIBLE_ROLES_PATH=../
|
||||
virtualenv --system-site-packages --python "${PYTHON}" "${MYTMPDIR}/botocore-less-than-1.10.16"
|
||||
source "${MYTMPDIR}/botocore-less-than-1.10.16/bin/activate"
|
||||
"${PYTHON}" -m pip install 'botocore<1.10.16' boto3
|
||||
"${PYTHON}" -m pip install 'botocore<1.10.16' 'boto3<1.7.16'
|
||||
ansible-playbook -i ../../inventory -e @../../integration_config.yml -e @../../cloud-config-aws.yml -v playbooks/version_fail.yml "$@"
|
||||
|
||||
# Run full test suite
|
||||
|
||||
Reference in New Issue
Block a user