2014-03-30 01:27:48 +01:00
|
|
|
# TODO: lots of attributes not covered: machine_type, zone, metadata, tags, etc.
|
|
|
|
#
|
|
|
|
# ============================================================
|
|
|
|
- name: test with no parameters
|
|
|
|
gce:
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
2016-11-11 19:17:47 +01:00
|
|
|
tags:
|
|
|
|
- param-check
|
2014-03-30 01:27:48 +01:00
|
|
|
|
|
|
|
- name: assert failure when called with no parameters
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
2016-11-11 19:17:47 +01:00
|
|
|
- 'result.msg == "Must specify a \"name\" or \"instance_names\""'
|
2014-03-30 01:27:48 +01:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test missing name
|
|
|
|
gce:
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
2016-11-11 19:17:47 +01:00
|
|
|
tags:
|
|
|
|
- param-check
|
2014-03-30 01:27:48 +01:00
|
|
|
|
2016-11-11 19:17:47 +01:00
|
|
|
- name: assert failure when missing name
|
2014-03-30 01:27:48 +01:00
|
|
|
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"'
|
|
|
|
|
2016-11-11 19:17:47 +01:00
|
|
|
# ============================================================
|
|
|
|
- name: test num_instances state=present (expected changed=true)
|
|
|
|
gce:
|
|
|
|
base_name: "{{ instance_name }}"
|
|
|
|
num_instances: 2
|
|
|
|
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"'
|
|
|
|
- 'result.instance_data|length == 2'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test num_instances state=absent (expected changed=true)
|
|
|
|
gce:
|
|
|
|
base_name: "{{ instance_name }}"
|
|
|
|
num_instances: 2
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert num_instances state=absent (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "absent"'
|
|
|
|
- 'result.instance_names == ["{{ instance_name }}-000", "{{ instance_name }}-001"]'
|
|
|
|
|
2014-04-13 00:21:26 +02:00
|
|
|
# ============================================================
|
|
|
|
- name: test disks given (expected changed=true)
|
|
|
|
gce:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
disks:
|
|
|
|
- "{{ instance_name }}-base"
|
|
|
|
- "{{ instance_name }}-extra"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert disks given
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.instance_data[0].disks == ["{{ instance_name }}-base", "{{ instance_name }}-extra"]'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test disks given (expected changed=false)
|
|
|
|
gce:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
disks:
|
|
|
|
- "{{ instance_name }}-base"
|
|
|
|
- "{{ instance_name }}-extra"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert disks given
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'not result.changed'
|
|
|
|
- 'result.instance_data[0].disks == ["{{ instance_name }}-base", "{{ instance_name }}-extra"]'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test disks in the wrong order
|
|
|
|
gce:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
disks:
|
|
|
|
- "{{ instance_name }}-extra"
|
|
|
|
- "{{ instance_name }}-base"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert disks in the wrong order
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
2017-11-27 23:58:08 +01:00
|
|
|
- '{{ result.msg is match("Disk at index 0 does not match:.*") }}'
|
2014-04-13 00:21:26 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test disks given with name and mode
|
|
|
|
gce:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
disks:
|
|
|
|
- { name: "{{ instance_name }}-base", mode: "READ_WRITE" }
|
|
|
|
- { name: "{{ instance_name }}-extra", mode: "READ_ONLY" }
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert disks given
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'not result.changed'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test disks given with name and wrong mode
|
|
|
|
gce:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
disks:
|
|
|
|
- { name: "{{ instance_name }}-base", mode: "READ_ONLY" }
|
|
|
|
- "{{ instance_name }}-extra"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
register: result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert disks given
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.failed'
|
2017-11-27 23:58:08 +01:00
|
|
|
- '{{ result.msg is match("Disk at index 0 is in the wrong mode:.*") }}'
|
2014-04-13 00:21:26 +02:00
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
- name: test disks given, state absent (expected changed=true)
|
|
|
|
gce:
|
|
|
|
name: "{{ instance_name }}"
|
|
|
|
disks:
|
|
|
|
- "{{ instance_name }}-base"
|
|
|
|
- "{{ instance_name }}-extra"
|
|
|
|
service_account_email: "{{ service_account_email }}"
|
|
|
|
pem_file: "{{ pem_file }}"
|
|
|
|
project_id: "{{ project_id }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: assert disks given, state absent (expected changed=true)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "absent"'
|