97 lines
2.8 KiB
YAML
97 lines
2.8 KiB
YAML
# TODO: lots of attributes not covered: machine_type, zone, metadata, tags, etc.
|
|
#
|
|
# ============================================================
|
|
- name: test with no parameters
|
|
gce:
|
|
register: result
|
|
ignore_errors: true
|
|
|
|
- name: assert failure when called with no parameters
|
|
assert:
|
|
that:
|
|
- 'result.failed'
|
|
- 'result.msg == "Missing GCE connection parameters in libcloud secrets file."'
|
|
|
|
# ============================================================
|
|
- name: test missing name
|
|
gce:
|
|
service_account_email: "{{ service_account_email }}"
|
|
pem_file: "{{ pem_file }}"
|
|
project_id: "{{ project_id }}"
|
|
register: result
|
|
ignore_errors: true
|
|
|
|
- name: assert failure when called with no parameters
|
|
assert:
|
|
that:
|
|
- 'result.failed'
|
|
- 'result.msg == "Must specify a \"name\" or \"instance_names\""'
|
|
|
|
# ============================================================
|
|
- name: test state=present (expected changed=true)
|
|
gce:
|
|
name: "{{ instance_name }}"
|
|
service_account_email: "{{ service_account_email }}"
|
|
pem_file: "{{ pem_file }}"
|
|
project_id: "{{ project_id }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: assert state=present (expected changed=true)
|
|
assert:
|
|
that:
|
|
- 'result.changed'
|
|
- 'result.name == "{{ instance_name }}"'
|
|
- 'result.state == "present"'
|
|
|
|
# ============================================================
|
|
- name: test state=present (expected changed=false)
|
|
gce:
|
|
name: "{{ instance_name }}"
|
|
service_account_email: "{{ service_account_email }}"
|
|
pem_file: "{{ pem_file }}"
|
|
project_id: "{{ project_id }}"
|
|
state: present
|
|
register: result
|
|
|
|
- name: assert state=present (expected changed=false)
|
|
assert:
|
|
that:
|
|
- 'not result.changed'
|
|
- 'result.name == "{{ instance_name }}"'
|
|
- 'result.state == "present"'
|
|
|
|
# ============================================================
|
|
- name: test state=absent (expected changed=true)
|
|
gce:
|
|
name: "{{ instance_name }}"
|
|
service_account_email: "{{ service_account_email }}"
|
|
pem_file: "{{ pem_file }}"
|
|
project_id: "{{ project_id }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: assert state=absent (expected changed=true)
|
|
assert:
|
|
that:
|
|
- 'result.changed'
|
|
- 'result.name == "{{ instance_name }}"'
|
|
- 'result.state == "absent"'
|
|
|
|
# ============================================================
|
|
- name: test state=absent (expected changed=false)
|
|
gce:
|
|
name: "{{ instance_name }}"
|
|
service_account_email: "{{ service_account_email }}"
|
|
pem_file: "{{ pem_file }}"
|
|
project_id: "{{ project_id }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: assert state=absent (expected changed=false)
|
|
assert:
|
|
that:
|
|
- 'not result.changed'
|
|
- 'result.name == "{{ instance_name }}"'
|
|
- 'result.state == "absent"'
|
|
|