2014-03-30 21:49:55 +00:00
|
|
|
# TODO: need tests for read/write mode.
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test missing name
|
|
|
|
gce_pd:
|
|
|
|
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 == "missing required arguments: name"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test state=present (expected changed=true)
|
|
|
|
gce_pd:
|
|
|
|
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.size_gb == 10' # default size
|
|
|
|
- 'result.zone == "us-central1-b"' # default zone
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test state=present (expected changed=false)
|
|
|
|
gce_pd:
|
|
|
|
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_pd:
|
|
|
|
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_pd:
|
|
|
|
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"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test non-default size/zone
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
size_gb: 5
|
|
|
|
zone: us-central1-a
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert non-default size/zone
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.name == "{{ instance_name }}"'
|
|
|
|
- 'result.size_gb == 5'
|
|
|
|
- 'result.zone == "us-central1-a"'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test non-default size/zone (state=absent)
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
size_gb: 5
|
|
|
|
zone: us-central1-a
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert non-default size/zone (state=absent)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.name == "{{ instance_name }}"'
|
|
|
|
- 'result.state == "absent"'
|
2014-04-11 21:40:52 +00:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test image given (state=present)
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
image: debian-7
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert image given (state=present)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.name == "{{ instance_name }}"'
|
|
|
|
- 'result.image == "debian-7"'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test image given (state=absent)
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
image: debian-7
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert image given (state=absent)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.name == "{{ instance_name }}"'
|
|
|
|
- 'result.state == "absent"'
|
2014-04-11 22:45:56 +00:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test snapshot given (state=present)
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
snapshot: "{{ instance_name }}-snapshot"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert image given (state=present)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.name == "{{ instance_name }}"'
|
|
|
|
- 'result.snapshot == "{{ instance_name }}-snapshot"'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test snapshot given (state=absent)
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
snapshot: "{{ instance_name }}-snapshot"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert image given (state=absent)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.name == "{{ instance_name }}"'
|
|
|
|
- 'result.state == "absent"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test both image and snapshot given
|
|
|
|
gce_pd:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
image: "debian-7"
|
|
|
|
snapshot: "{{ instance_name }}-snapshot"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert image given (state=present)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
|
|
|
- 'result.msg == "Cannot give both image (debian-7) and snapshot ({{ instance_name }}-snapshot)"'
|
|
|
|
|