1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/legacy/roles/test_gce/tasks/main.yml
Matt Martz 4fe08441be Deprecate tests used as filters (#32361)
* Warn on tests used as filters

* Update docs, add aliases for tests that fit more gramatically with test syntax

* Fix rst formatting

* Add successful filter, alias of success

* Remove renamed_deprecation, it was overkill

* Make directory alias for is_dir

* Update tests to use proper jinja test syntax

* Update additional documentation, living outside of YAML files, to reflect proper jinja test syntax

* Add conversion script, porting guide updates, and changelog updates

* Update newly added uses of tests as filters

* No underscore variable

* Convert recent tests as filter changes to win_stat

* Fix some changes related to rebasing a few integration tests

* Make tests_as_filters_warning explicitly accept the name of the test, instead of inferring the name

* Add test for tests_as_filters_warning

* Update tests as filters in newly added/modified tests

* Address recent changes to several integration tests

* Address recent changes in cs_vpc
2017-11-27 17:58:08 -05:00

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 is 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 is 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"'