cs_volume: add volumes extraction and upload features (#54111)

* cs_volume: add volumes extraction and upload features

* cs_volume: Update doc, remove deprecated code

* cs_volume: Add unit tests for extract and upload features
This commit is contained in:
David Passante 2019-03-22 07:09:26 +01:00 committed by René Moser
commit aa32164d15
6 changed files with 612 additions and 340 deletions

View file

@ -1,6 +1,8 @@
---
test_cs_instance_1: "{{ cs_resource_prefix }}-vm1"
test_cs_instance_2: "{{ cs_resource_prefix }}-vm2"
test_cs_instance_3: "{{ cs_resource_prefix }}-vm3"
test_cs_instance_template: "{{ cs_common_template }}"
test_cs_instance_offering_1: Small Instance
test_cs_disk_offering_1: Custom
test_cs_volume_to_upload: http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-xen.vhd.bz2

View file

@ -0,0 +1,296 @@
---
- name: setup
cs_volume: name={{ cs_resource_prefix }}_vol state=absent
register: vol
- name: verify setup
assert:
that:
- vol is successful
- name: setup instance 1
cs_instance:
name: "{{ test_cs_instance_1 }}"
template: "{{ test_cs_instance_template }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- name: setup instance 2
cs_instance:
name: "{{ test_cs_instance_2 }}"
template: "{{ test_cs_instance_template }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- name: test fail if missing name
action: cs_volume
register: vol
ignore_errors: true
- name: verify results of fail if missing name
assert:
that:
- vol is failed
- "vol.msg == 'missing required arguments: name'"
- name: test create volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 20
register: vol
check_mode: true
- name: verify results test create volume in check mode
assert:
that:
- vol is changed
- name: test create volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 20
register: vol
- name: verify results test create volume
assert:
that:
- vol is changed
- vol.size == 20 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test create volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 20
register: vol
- name: verify results test create volume idempotence
assert:
that:
- vol is not changed
- vol.size == 20 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test shrink volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 10
shrink_ok: yes
register: vol
check_mode: true
- name: verify results test create volume in check mode
assert:
that:
- vol is changed
- vol.size == 20 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test shrink volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 10
shrink_ok: yes
register: vol
- name: verify results test create volume
assert:
that:
- vol is changed
- vol.size == 10 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test shrink volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 10
shrink_ok: yes
register: vol
- name: verify results test create volume
assert:
that:
- vol is not changed
- vol.size == 10 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test attach volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_1 }}"
state: attached
register: vol
check_mode: true
- name: verify results test attach volume in check mode
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is not defined
- name: test attach volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_1 }}"
state: attached
register: vol
- name: verify results test attach volume
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_1 }}"
- vol.attached is defined
- name: test attach volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_1 }}"
state: attached
register: vol
- name: verify results test attach volume idempotence
assert:
that:
- vol is not changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_1 }}"
- vol.attached is defined
- name: test attach attached volume to another vm in check mdoe
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_2 }}"
state: attached
register: vol
check_mode: true
- name: verify results test attach attached volume to another vm in check mode
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_1 }}"
- vol.attached is defined
- name: test attach attached volume to another vm
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_2 }}"
state: attached
register: vol
- name: verify results test attach attached volume to another vm
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_2 }}"
- vol.attached is defined
- name: test attach attached volume to another vm idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_2 }}"
state: attached
register: vol
- name: verify results test attach attached volume to another vm idempotence
assert:
that:
- vol is not changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_2 }}"
- vol.attached is defined
- name: test detach volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: detached
register: vol
check_mode: true
- name: verify results test detach volume in check mdoe
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is defined
- name: test detach volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: detached
register: vol
- name: verify results test detach volume
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is undefined
- name: test detach volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: detached
register: vol
- name: verify results test detach volume idempotence
assert:
that:
- vol is not changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is undefined
- name: test delete volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: absent
register: vol
check_mode: true
- name: verify results test create volume in check mode
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test delete volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: absent
register: vol
- name: verify results test create volume
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test delete volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: absent
register: vol
- name: verify results test delete volume idempotence
assert:
that:
- vol is not changed
- name: cleanup instance 1
cs_instance:
name: "{{ test_cs_instance_1 }}"
state: absent
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- name: cleanup instance 2
cs_instance:
name: "{{ test_cs_instance_2 }}"
state: absent
register: instance
- name: verify create instance
assert:
that:
- instance is successful

View file

@ -0,0 +1,150 @@
---
- name: setup
cs_volume:
zone: "{{ cs_common_zone_adv }}"
name: "{{ cs_resource_prefix }}_upload"
state: absent
register: uploaded_vol
- name: verify setup
assert:
that:
- uploaded_vol is successful
- name: setup instance
cs_instance:
zone: "{{ cs_common_zone_adv }}"
name: "{{ test_cs_instance_3 }}"
template: "{{ test_cs_instance_template }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
register: instance
- name: verify setup instance
assert:
that:
- instance is successful
- name: setup stop instance
cs_instance:
zone: "{{ cs_common_zone_adv }}"
name: "{{ test_cs_instance_3 }}"
state: stopped
register: instance
- name: verify stop instance
assert:
that:
- instance is successful
- instance.state == 'Stopped'
- name: setup get instance facts
cs_instance_facts:
name: "{{ test_cs_instance_3 }}"
register: instance
- name: verify setup get instance facts
assert:
that:
- instance is successful
- name: test extract volume in check mode
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: extracted
name: "{{ instance.volumes[0].name }}"
check_mode: yes
register: extracted_vol
- name: verify test extract volume in check mode
assert:
that:
- extracted_vol is successful
- extracted_vol is changed
- extracted_vol.state == "Ready"
- extracted_vol.name == "{{ instance.volumes[0].name }}"
- extracted_vol.url is not defined
- name: test extract volume
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: extracted
name: "{{ instance.volumes[0].name }}"
register: extracted_vol
- name: verify test extract volume
assert:
that:
- extracted_vol is successful
- extracted_vol is changed
- extracted_vol.state == "DOWNLOAD_URL_CREATED"
- extracted_vol.name == "{{ instance.volumes[0].name }}"
- extracted_vol.url is defined
- name: test upload volume with missing param
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: uploaded
name: "{{ cs_resource_prefix }}_upload"
url: "{{ test_cs_volume_to_upload }}"
ignore_errors: yes
register: uploaded_vol
- name: verify upload volume with missing param
assert:
that:
- uploaded_vol is failed
- uploaded_vol is not changed
- 'uploaded_vol.msg == "state is uploaded but all of the following are missing: format"'
- name: test upload volume in check mode
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: uploaded
name: "{{ cs_resource_prefix }}_upload"
format: VHD
url: "{{ test_cs_volume_to_upload }}"
check_mode: yes
register: uploaded_vol
- name: verify upload volume in check mode
assert:
that:
- uploaded_vol is successful
- uploaded_vol is changed
- uploaded_vol.name is not defined
- name: test upload volume
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: uploaded
name: "{{ cs_resource_prefix }}_upload"
format: VHD
url: "{{ test_cs_volume_to_upload }}"
register: uploaded_vol
- name: verify upload volume
assert:
that:
- uploaded_vol is successful
- uploaded_vol is changed
- uploaded_vol.name == "{{ cs_resource_prefix }}_upload"
- uploaded_vol.state == "Uploaded"
- name: test upload volume idempotence
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: uploaded
name: "{{ cs_resource_prefix }}_upload"
format: VHD
url: "{{ test_cs_volume_to_upload }}"
register: uploaded_vol
- name: verify upload volume idempotence
assert:
that:
- uploaded_vol is successful
- uploaded_vol is not changed
- uploaded_vol.name == "{{ cs_resource_prefix }}_upload"
- uploaded_vol.state == "Uploaded"
- name: delete volume
cs_volume:
zone: "{{ cs_common_zone_adv }}"
state: absent
name: "{{ cs_resource_prefix }}_upload"
register: uploaded_vol
- name: verify delete volume
assert:
that:
- uploaded_vol is successful
- uploaded_vol is changed

View file

@ -1,296 +1,3 @@
---
- name: setup
cs_volume: name={{ cs_resource_prefix }}_vol state=absent
register: vol
- name: verify setup
assert:
that:
- vol is successful
- name: setup instance 1
cs_instance:
name: "{{ test_cs_instance_1 }}"
template: "{{ test_cs_instance_template }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- name: setup instance 2
cs_instance:
name: "{{ test_cs_instance_2 }}"
template: "{{ test_cs_instance_template }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- name: test fail if missing name
action: cs_volume
register: vol
ignore_errors: true
- name: verify results of fail if missing name
assert:
that:
- vol is failed
- "vol.msg == 'missing required arguments: name'"
- name: test create volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 20
register: vol
check_mode: true
- name: verify results test create volume in check mode
assert:
that:
- vol is changed
- name: test create volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 20
register: vol
- name: verify results test create volume
assert:
that:
- vol is changed
- vol.size == 20 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test create volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 20
register: vol
- name: verify results test create volume idempotence
assert:
that:
- vol is not changed
- vol.size == 20 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test shrink volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 10
shrink_ok: yes
register: vol
check_mode: true
- name: verify results test create volume in check mode
assert:
that:
- vol is changed
- vol.size == 20 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test shrink volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 10
shrink_ok: yes
register: vol
- name: verify results test create volume
assert:
that:
- vol is changed
- vol.size == 10 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test shrink volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
disk_offering: "{{ test_cs_disk_offering_1 }}"
size: 10
shrink_ok: yes
register: vol
- name: verify results test create volume
assert:
that:
- vol is not changed
- vol.size == 10 * 1024 ** 3
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test attach volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_1 }}"
state: attached
register: vol
check_mode: true
- name: verify results test attach volume in check mode
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is not defined
- name: test attach volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_1 }}"
state: attached
register: vol
- name: verify results test attach volume
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_1 }}"
- vol.attached is defined
- name: test attach volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_1 }}"
state: attached
register: vol
- name: verify results test attach volume idempotence
assert:
that:
- vol is not changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_1 }}"
- vol.attached is defined
- name: test attach attached volume to another vm in check mdoe
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_2 }}"
state: attached
register: vol
check_mode: true
- name: verify results test attach attached volume to another vm in check mode
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_1 }}"
- vol.attached is defined
- name: test attach attached volume to another vm
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_2 }}"
state: attached
register: vol
- name: verify results test attach attached volume to another vm
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_2 }}"
- vol.attached is defined
- name: test attach attached volume to another vm idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
vm: "{{ test_cs_instance_2 }}"
state: attached
register: vol
- name: verify results test attach attached volume to another vm idempotence
assert:
that:
- vol is not changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.vm == "{{ test_cs_instance_2 }}"
- vol.attached is defined
- name: test detach volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: detached
register: vol
check_mode: true
- name: verify results test detach volume in check mdoe
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is defined
- name: test detach volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: detached
register: vol
- name: verify results test detach volume
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is undefined
- name: test detach volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: detached
register: vol
- name: verify results test detach volume idempotence
assert:
that:
- vol is not changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- vol.attached is undefined
- name: test delete volume in check mode
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: absent
register: vol
check_mode: true
- name: verify results test create volume in check mode
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test delete volume
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: absent
register: vol
- name: verify results test create volume
assert:
that:
- vol is changed
- vol.name == "{{ cs_resource_prefix }}_vol"
- name: test delete volume idempotence
cs_volume:
name: "{{ cs_resource_prefix }}_vol"
state: absent
register: vol
- name: verify results test delete volume idempotence
assert:
that:
- vol is not changed
- name: cleanup instance 1
cs_instance:
name: "{{ test_cs_instance_1 }}"
state: absent
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- name: cleanup instance 2
cs_instance:
name: "{{ test_cs_instance_2 }}"
state: absent
register: instance
- name: verify create instance
assert:
that:
- instance is successful
- include_tasks: common.yml
- include_tasks: extract_upload.yml