2019-03-26 19:24:10 +01:00
|
|
|
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
---
|
|
|
|
- name: setup server
|
|
|
|
hcloud_server:
|
|
|
|
name: "{{hcloud_server_name}}"
|
|
|
|
server_type: cx11
|
|
|
|
image: ubuntu-18.04
|
|
|
|
state: started
|
|
|
|
location: "fsn1"
|
2019-05-27 07:48:48 +02:00
|
|
|
register: vol_server
|
2019-03-26 19:24:10 +01:00
|
|
|
- name: verify setup server
|
|
|
|
assert:
|
|
|
|
that:
|
2019-05-27 07:48:48 +02:00
|
|
|
- vol_server is changed
|
2019-03-26 19:24:10 +01:00
|
|
|
|
|
|
|
- name: test missing size parameter on create Volume
|
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
server: "{{hcloud_server_name}}"
|
|
|
|
register: result
|
|
|
|
ignore_errors: yes
|
|
|
|
- name: verify fail test missing size parameter on create Volume
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
- 'result.msg == "missing required arguments: size"'
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test create Volume with check mode
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
size: 10
|
|
|
|
location: "fsn1"
|
|
|
|
register: result
|
|
|
|
check_mode: yes
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify create Volume with check mode result
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test create Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
size: 10
|
|
|
|
location: "fsn1"
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test create Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.name == "{{hcloud_volume_name}}"
|
|
|
|
- volume.hcloud_volume.location == "fsn1"
|
|
|
|
- volume.hcloud_volume.size == 10
|
|
|
|
- volume.hcloud_volume.server != "{{hcloud_server_name}}"
|
2019-10-02 20:19:10 +02:00
|
|
|
- volume.hcloud_volume.linux_device is defined
|
2019-03-26 19:24:10 +01:00
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test create Volume idempotence
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
size: 10
|
|
|
|
location: "fsn1"
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test create Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is not changed
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test attach Volume with checkmode
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
server: "{{hcloud_server_name}}"
|
|
|
|
check_mode: yes
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test attach Volume with checkmode
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.server != "{{hcloud_server_name}}"
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test attach Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
server: "{{hcloud_server_name}}"
|
|
|
|
register: volume
|
|
|
|
- name: verify attach volume
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.server == "{{hcloud_server_name}}"
|
2019-05-27 07:48:48 +02:00
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test attach Volume idempotence
|
2019-05-27 07:48:48 +02:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
server: "{{hcloud_server_name}}"
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify attach Volume idempotence
|
2019-05-27 07:48:48 +02:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is not changed
|
|
|
|
- volume.hcloud_volume.server == "{{hcloud_server_name}}"
|
2019-03-26 19:24:10 +01:00
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test detach Volume with checkmode
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
check_mode: yes
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify detach Volume with checkmode
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.server == "{{hcloud_server_name}}"
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test detach Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
register: volume
|
|
|
|
- name: verify detach volume
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.location == "fsn1"
|
|
|
|
- volume.hcloud_volume.server != "{{hcloud_server_name}}"
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test update Volume label
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
labels:
|
|
|
|
key: value
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test update Volume label
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.labels.key == "value"
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test update Volume label with the same label
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
labels:
|
|
|
|
key: value
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test update Volume lable with the same label
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is not changed
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test increase Volume size
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
size: 11
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test increase Volume size
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.size == 11
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test decreace Volume size
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
size: 10
|
|
|
|
register: volume
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify test decreace Volume size
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is not changed
|
|
|
|
- volume.hcloud_volume.size == 11
|
|
|
|
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: test update Volume delete protection
|
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
delete_protection: true
|
|
|
|
register: volume
|
|
|
|
- name: verify test update Volume delete protection
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.delete_protection is sameas true
|
|
|
|
|
|
|
|
- name: test update Volume delete protection idempotency
|
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
delete_protection: true
|
|
|
|
register: volume
|
|
|
|
- name: verify test update Volume delete protection idempotency
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is not changed
|
|
|
|
- volume.hcloud_volume.delete_protection is sameas true
|
|
|
|
|
|
|
|
- name: test Volume without delete protection set to be idempotent
|
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
register: volume
|
|
|
|
- name: verify test Volume without delete protection set to be idempotent
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is not changed
|
|
|
|
- volume.hcloud_volume.delete_protection is sameas true
|
|
|
|
|
|
|
|
- name: test delete Volume fails if it is protected
|
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
state: absent
|
|
|
|
ignore_errors: yes
|
|
|
|
register: result
|
|
|
|
- name: verify delete Volume fails if it is protected
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
- 'result.msg == "volume deletion is protected"'
|
|
|
|
|
|
|
|
- name: test update Volume delete protection
|
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
delete_protection: false
|
|
|
|
register: volume
|
|
|
|
- name: verify test update Volume delete protection
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- volume is changed
|
|
|
|
- volume.hcloud_volume.delete_protection is sameas false
|
|
|
|
|
|
|
|
- name: test delete Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
hcloud_volume:
|
|
|
|
name: "{{hcloud_volume_name}}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
2019-10-18 23:28:12 +02:00
|
|
|
- name: verify delete Volume
|
2019-03-26 19:24:10 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is success
|
|
|
|
|
|
|
|
- name: cleanup
|
|
|
|
hcloud_server:
|
|
|
|
name: "{{ hcloud_server_name }}"
|
|
|
|
state: absent
|
|
|
|
register: result
|
|
|
|
- name: verify cleanup
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is success
|