mirror of https://github.com/ansible/ansible.git
Basic integration test for gce_tag. (#17928)
parent
ed134d81f1
commit
28dc527b2c
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
# defaults file for test_gce_tags
|
||||||
|
instance_name: "{{ resource_prefix|lower }}"
|
||||||
|
service_account_email: "{{ gce_service_account_email }}"
|
||||||
|
pem_file: "{{ gce_pem_file }}"
|
||||||
|
project_id: "{{ gce_project_id }}"
|
||||||
|
zone: "us-central1-c"
|
||||||
|
machine_type: f1-micro
|
||||||
|
image: debian-8
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
# test role for gce_tag
|
||||||
|
- include: setup.yml
|
||||||
|
- include: test.yml
|
||||||
|
- include: teardown.yml
|
@ -0,0 +1,20 @@
|
|||||||
|
# GCE Tag Setup.
|
||||||
|
# ============================================================
|
||||||
|
- name: "Create instance for executing gce_tag tests"
|
||||||
|
gce:
|
||||||
|
instance_names: "{{ instance_name }}"
|
||||||
|
machine_type: "{{ machine_type }}"
|
||||||
|
image: "{{ image }}"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert VM created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- 'result.instance_names[0] == "{{ instance_name }}"'
|
||||||
|
- 'result.state == "present"'
|
@ -0,0 +1,18 @@
|
|||||||
|
# GCE Tag Teardown.
|
||||||
|
# ============================================================
|
||||||
|
- name: "Teardown instance used in gce_tag test"
|
||||||
|
gce:
|
||||||
|
instance_names: "{{ instance_name }}"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert VM removed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- 'result.instance_names[0] == "{{ instance_name }}"'
|
||||||
|
- 'result.state == "absent"'
|
@ -0,0 +1,133 @@
|
|||||||
|
# GCE Tag Integration Tests.
|
||||||
|
|
||||||
|
## Parameter checking tests ##
|
||||||
|
# ============================================================
|
||||||
|
- name: "test missing param: instance_name"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
tags:
|
||||||
|
- param-check
|
||||||
|
|
||||||
|
- name: "assert failure when param: instance_name missing"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.failed'
|
||||||
|
- 'result.msg == "missing required arguments: instance_name"'
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
- name: "test missing param: tags"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
instance_name: "{{ instance_name }}"
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
tags:
|
||||||
|
- param-check
|
||||||
|
|
||||||
|
- name: "assert failure when param: tags missing"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.failed'
|
||||||
|
- 'result.msg == "Must specify \"tags\""'
|
||||||
|
|
||||||
|
|
||||||
|
## Non-existant instance tests ##
|
||||||
|
# # ============================================================
|
||||||
|
- name: "test tag non-existant instance (state==present)"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
instance_name: "blahblahblah123"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
state: present
|
||||||
|
tags: foo,bar
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: "assert tag failed"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.failed'
|
||||||
|
|
||||||
|
# # ============================================================
|
||||||
|
- name: "test tag non-existant instance (state==absent)"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
instance_name: "blahblahblah123"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
state: absent
|
||||||
|
tags: foo,bar
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: "assert tag failed"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.failed'
|
||||||
|
|
||||||
|
## tagging tests ##
|
||||||
|
# # ============================================================
|
||||||
|
- name: "test tags added (state==present)"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
instance_name: "{{ instance_name }}"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
tags: foo,bar
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: "assert tag successful"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- 'result.tags|length == 2'
|
||||||
|
- 'result.tags == ["foo", "bar"]'
|
||||||
|
|
||||||
|
# # ============================================================
|
||||||
|
- name: "add existing tags, no change (state==present)"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
instance_name: "{{ instance_name }}"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
tags: foo,bar
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: "assert tag successful"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed == False'
|
||||||
|
- 'result.tags == None'
|
||||||
|
|
||||||
|
# # ============================================================
|
||||||
|
- name: "test tags removed from instance (state==absent)"
|
||||||
|
gce_tag:
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
instance_name: "{{ instance_name }}"
|
||||||
|
zone: "{{ zone }}"
|
||||||
|
tags: foo,bar
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: "assert tags removed"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- 'result.tags == ["foo", "bar"]'
|
Loading…
Reference in New Issue