mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
781fd7099a
- Move legacy tests into a separate directory. - Reduce common dependencies between targets.
252 lines
7.3 KiB
YAML
252 lines
7.3 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
|
|
tags:
|
|
- param-check
|
|
|
|
- name: assert failure when called with no parameters
|
|
assert:
|
|
that:
|
|
- 'result.failed'
|
|
- 'result.msg == "Must specify a \"name\" or \"instance_names\""'
|
|
|
|
# ============================================================
|
|
- name: test missing name
|
|
gce:
|
|
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 missing name
|
|
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"'
|
|
|
|
# ============================================================
|
|
- 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"]'
|
|
|
|
# ============================================================
|
|
- 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'
|
|
- '{{ result.msg | match("Disk at index 0 does not match:.*") }}'
|
|
|
|
# ============================================================
|
|
- 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'
|
|
- '{{ result.msg | match("Disk at index 0 is in the wrong mode:.*") }}'
|
|
|
|
# ============================================================
|
|
- 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"'
|