1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes for EC2 module integration tests.

This commit is contained in:
Matt Clay 2017-05-03 08:20:39 +08:00
parent a42b892f70
commit 00f8e3d360
9 changed files with 989 additions and 863 deletions

View file

@ -7,6 +7,7 @@ rackspace_region:
# AWS Credentials
ec2_access_key:
ec2_secret_key:
security_token:
# GCE Credentials
gce_service_account_email:

View file

@ -1,3 +1,4 @@
dependencies:
- prepare_tests
- setup_sshkey
- setup_ec2

View file

@ -1,4 +1,3 @@
# common setup tasks for ec2 module tests
# (c) 2014, James Laska <jlaska@ansible.com>
# This file is part of Ansible
@ -16,12 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: generate random string
command: '{{ ansible_python.executable }} -c "import string,random; print str().join(random.choice(string.ascii_lowercase) for _ in range(8));"'
register: random_string
tags:
- prepare
- name: create random file
shell: mktemp /tmp/id_rsa.XXXXXX
register: sshkey
@ -40,16 +33,15 @@
- prepare
- name: record fingerprint
shell: ssh-keygen -lf {{sshkey.stdout}}.pub | awk '{print $2}'
shell: ssh-keygen -lf {{sshkey.stdout}}.pub
register: fingerprint
tags:
- prepare
- name: set facts for future roles
set_fact:
random_string: '{{random_string.stdout}}'
sshkey: '{{sshkey.stdout}}'
key_material: '{{key_material.stdout}}'
fingerprint: '{{fingerprint.stdout}}'
fingerprint: '{{fingerprint.stdout.split()[1]}}'
tags:
- prepare

View file

@ -24,6 +24,8 @@
# test credentials from environment
# test credential parameters
- block:
# ============================================================
# create test elb with listeners, certificate, and health check
@ -33,6 +35,7 @@
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
security_token: "{{ security_token }}"
state: present
zones:
- us-east-1c
@ -98,6 +101,7 @@
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
security_token: "{{ security_token }}"
state: present
zones:
- us-east-1b
@ -135,6 +139,7 @@
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
security_token: "{{ security_token }}"
state: present
zones:
- us-east-1b
@ -167,6 +172,7 @@
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
security_token: "{{ security_token }}"
state: present
zones:
- us-east-1b
@ -199,6 +205,7 @@
region: "{{ ec2_region }}"
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
security_token: "{{ security_token }}"
state: present
zones:
- us-east-1b
@ -253,9 +260,16 @@
# ============================================================
- name: test invalid region parameter
ec2_elb_lb:
name="{{ tag_prefix }}"
region='asdf querty 1234'
state=present
name: "{{ tag_prefix }}"
region: 'asdf querty 1234'
state: present
listeners:
- protocol: http
load_balancer_port: 80
instance_port: 80
zones:
- us-east-1c
- us-east-1d
register: result
ignore_errors: true
@ -263,7 +277,7 @@
assert:
that:
- 'result.failed'
- 'result.msg.startswith("value of region must be one of:")'
- 'result.msg.startswith("Region asdf querty 1234 does not seem to be available ")'
# ============================================================
@ -364,7 +378,7 @@
assert:
that:
- 'result.failed'
- '"InvalidClientTokenId" in result.msg'
- '"InvalidClientTokenId" in result.exception'
# ============================================================
@ -389,6 +403,8 @@
- 'result.failed'
- '"No handler was ready to authenticate. 1 handlers were checked." in result.msg'
always:
# ============================================================
- name: remove the test load balancer completely
ec2_elb_lb:
@ -397,6 +413,7 @@
state: absent
ec2_access_key: "{{ ec2_access_key }}"
ec2_secret_key: "{{ ec2_secret_key }}"
security_token: "{{ security_token }}"
register: result
- name: assert the load balancer was removed

View file

@ -8,6 +8,8 @@
# - include: ../../setup_ec2/tasks/common.yml module_name=ec2_group
- block:
# ============================================================
- name: test failure with no parameters
ec2_group:
@ -182,6 +184,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=absent
register: result
@ -198,6 +201,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=present
register: result
@ -215,6 +219,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=present
ignore_errors: true
register: result
@ -233,6 +238,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=present
register: result
@ -251,6 +257,7 @@
EC2_REGION: '{{ec2_region}}'
EC2_ACCESS_KEY: '{{ec2_access_key}}'
EC2_SECRET_KEY: '{{ec2_secret_key}}'
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
register: result
- name: assert state=absent (expected changed=true)
@ -259,6 +266,8 @@
- 'result.changed'
- 'not result.group_id'
always:
# ============================================================
- name: test state=absent (expected changed=false)
ec2_group:
@ -268,6 +277,7 @@
EC2_REGION: '{{ec2_region}}'
EC2_ACCESS_KEY: '{{ec2_access_key}}'
EC2_SECRET_KEY: '{{ec2_secret_key}}'
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
register: result
- name: assert state=absent (expected changed=false)

View file

@ -1,3 +1,4 @@
dependencies:
- prepare_tests
- setup_sshkey
- setup_ec2

View file

@ -13,6 +13,8 @@
# ============================================================
# - include: ../../setup_ec2/tasks/common.yml module_name=ec2_key
- block:
# ============================================================
- name: test with no parameters
ec2_key:
@ -50,7 +52,7 @@
assert:
that:
- 'result.failed'
- 'result.msg.startswith("value of region must be one of:")'
- 'result.msg.startswith("Region asdf querty 1234 does not seem to be available ")'
# ============================================================
- name: test valid region parameter
@ -126,7 +128,7 @@
assert:
that:
- 'result.failed'
- '"EC2ResponseError: 401 Unauthorized" in result.msg'
- '"EC2ResponseError: 401 Unauthorized" in result.module_stderr'
# ============================================================
- name: test credential parameters
@ -142,7 +144,7 @@
assert:
that:
- 'result.failed'
- '"EC2ResponseError: 401 Unauthorized" in result.msg'
- '"EC2ResponseError: 401 Unauthorized" in result.module_stderr'
# ============================================================
- name: test state=absent with key_material
@ -151,6 +153,7 @@
ec2_region={{ec2_region}}
ec2_access_key={{ec2_access_key}}
ec2_secret_key={{ec2_secret_key}}
security_token={{security_token}}
state=absent
register: result
@ -166,6 +169,7 @@
ec2_region={{ec2_region}}
ec2_access_key={{ec2_access_key}}
ec2_secret_key={{ec2_secret_key}}
security_token={{security_token}}
state=present
register: result
@ -189,6 +193,7 @@
EC2_REGION: '{{ec2_region}}'
EC2_ACCESS_KEY: '{{ec2_access_key}}'
EC2_SECRET_KEY: '{{ec2_secret_key}}'
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
register: result
- name: assert state=absent without key_material
@ -209,6 +214,7 @@
EC2_REGION: '{{ec2_region}}'
EC2_ACCESS_KEY: '{{ec2_access_key}}'
EC2_SECRET_KEY: '{{ec2_secret_key}}'
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
register: result
- name: assert state=present with key_material
@ -232,6 +238,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=absent
register: result
@ -249,11 +256,12 @@
name='{{ec2_key_name}}'
state=present
key_material='{{ item }}'
with_file: sshkey ~ '.pub'
with_file: '{{sshkey}}.pub'
environment:
EC2_REGION: '{{ec2_region}}'
EC2_ACCESS_KEY: '{{ec2_access_key}}'
EC2_SECRET_KEY: '{{ec2_secret_key}}'
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
register: result
- name: assert state=present with key_material with_files (expect changed=true)
@ -277,11 +285,12 @@
name='{{ec2_key_name}}'
state=present
key_material='{{ item }}'
with_file: sshkey ~ '.pub'
with_file: '{{sshkey}}.pub'
environment:
EC2_REGION: '{{ec2_region}}'
EC2_ACCESS_KEY: '{{ec2_access_key}}'
EC2_SECRET_KEY: '{{ec2_secret_key}}'
EC2_SECURITY_TOKEN: '{{security_token|default("")}}'
register: result
- name: assert state=present with key_material with_files (expect changed=false)
@ -306,6 +315,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
key_material='{{key_material}}'
state=absent
register: result
@ -318,6 +328,8 @@
- '"key" in result'
- 'result.key == None'
always:
# ============================================================
- name: test state=absent (expect changed=false)
ec2_key:
@ -325,6 +337,7 @@
ec2_region='{{ec2_region}}'
ec2_access_key='{{ec2_access_key}}'
ec2_secret_key='{{ec2_secret_key}}'
security_token='{{security_token}}'
state=absent
register: result

View file

@ -0,0 +1,3 @@
dependencies:
- prepare_tests
- setup_ec2

View file

@ -3,8 +3,14 @@
ecr_name: 'ecr-test-{{ ansible_date_time.epoch }}'
- block:
- name: When creating with check mode
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}'
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
check_mode: yes
@ -17,7 +23,13 @@
- name: When specifying a registry that is inaccessible
ecs_ecr: registry_id=999999999999 name='{{ ecr_name }}' region='{{ ec2_region }}'
ecs_ecr:
registry_id: 999999999999
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
ignore_errors: true
@ -29,7 +41,12 @@
- name: When creating a repository
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}'
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should change and create
@ -40,7 +57,12 @@
- name: When creating a repository that already exists in check mode
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}'
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
check_mode: yes
@ -52,7 +74,12 @@
- name: When creating a repository that already exists
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}'
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should not change
@ -65,6 +92,9 @@
ecs_ecr:
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
delete_policy: yes
register: result
check_mode: yes
@ -81,6 +111,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
policy: '{{ policy }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
check_mode: yes
@ -97,6 +130,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
policy: '{{ policy }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should change and not create
@ -111,6 +147,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
delete_policy: yes
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
check_mode: yes
@ -127,6 +166,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
delete_policy: yes
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should change and not create
@ -141,6 +183,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
policy: '{{ policy | to_json }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should change and not create
@ -155,6 +200,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
policy: '{{ policy }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should not change
@ -167,6 +215,9 @@
ecs_ecr:
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should not change
@ -181,6 +232,9 @@
name: '{{ ecr_name }}'
policy: '{{ policy }}'
delete_policy: yes
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
ignore_errors: true
@ -195,6 +249,9 @@
region: '{{ ec2_region }}'
name: '{{ ecr_name }}'
policy_text: "Ceci n'est pas une JSON"
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
ignore_errors: true
@ -205,7 +262,13 @@
- name: When in check mode, deleting a policy that exists
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}' state=absent
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
state: absent
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
check_mode: yes
@ -218,7 +281,13 @@
- name: When deleting a policy that exists
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}' state=absent
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
state: absent
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should change
@ -228,7 +297,13 @@
- name: When in check mode, deleting a policy that does not exist
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}' state=absent
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
state: absent
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
check_mode: yes
@ -240,7 +315,13 @@
- name: When deleting a policy that does not exist
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}' state=absent
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
state: absent
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
register: result
- name: it should not change
@ -249,5 +330,12 @@
- not result|changed
always:
- name: Delete lingering ECR repository
ecs_ecr: name='{{ ecr_name }}' region='{{ ec2_region }}' state=absent
ecs_ecr:
name: '{{ ecr_name }}'
region: '{{ ec2_region }}'
state: absent
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'