From 8b5e5538285f03c360807fd1e09c00a77d52bd94 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Mon, 16 Nov 2015 18:38:27 +0100 Subject: [PATCH 1/2] cloudstack: add tests for cs_volume --- test/integration/cloudstack.yml | 1 + .../roles/test_cs_volume/defaults/main.yml | 6 + .../roles/test_cs_volume/meta/main.yml | 3 + .../roles/test_cs_volume/tasks/main.yml | 183 ++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 test/integration/roles/test_cs_volume/defaults/main.yml create mode 100644 test/integration/roles/test_cs_volume/meta/main.yml create mode 100644 test/integration/roles/test_cs_volume/tasks/main.yml diff --git a/test/integration/cloudstack.yml b/test/integration/cloudstack.yml index 93ba7876d8c..3ad4ed08349 100644 --- a/test/integration/cloudstack.yml +++ b/test/integration/cloudstack.yml @@ -22,3 +22,4 @@ - { role: test_cs_account, tags: test_cs_account } - { role: test_cs_firewall, tags: test_cs_firewall } - { role: test_cs_loadbalancer_rule, tags: test_cs_loadbalancer_rule } + - { role: test_cs_volume, tags: test_cs_volume } diff --git a/test/integration/roles/test_cs_volume/defaults/main.yml b/test/integration/roles/test_cs_volume/defaults/main.yml new file mode 100644 index 00000000000..546469f33fc --- /dev/null +++ b/test/integration/roles/test_cs_volume/defaults/main.yml @@ -0,0 +1,6 @@ +--- +test_cs_instance_1: "{{ cs_resource_prefix }}-vm1" +test_cs_instance_2: "{{ cs_resource_prefix }}-vm2" +test_cs_instance_template: CentOS 5.3(64-bit) no GUI (Simulator) +test_cs_instance_offering_1: Small Instance +test_cs_disk_offering_1: Small diff --git a/test/integration/roles/test_cs_volume/meta/main.yml b/test/integration/roles/test_cs_volume/meta/main.yml new file mode 100644 index 00000000000..03e38bd4f7a --- /dev/null +++ b/test/integration/roles/test_cs_volume/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - test_cs_common diff --git a/test/integration/roles/test_cs_volume/tasks/main.yml b/test/integration/roles/test_cs_volume/tasks/main.yml new file mode 100644 index 00000000000..fa1f1026028 --- /dev/null +++ b/test/integration/roles/test_cs_volume/tasks/main.yml @@ -0,0 +1,183 @@ +--- +- name: setup + cs_volume: name={{ cs_resource_prefix }}_vol state=absent + register: vol +- name: verify setup + assert: + that: + - vol|success + +- 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|success + +- 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|success + +- 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|failed + - "vol.msg == 'missing required arguments: name'" + +- name: test create volume + cs_volume: + name: "{{ cs_resource_prefix }}_vol" + disk_offering: "{{ test_cs_disk_offering_1 }}" + register: vol +- name: verify results test create volume + assert: + that: + - vol|changed + - 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 }}" + register: vol +- name: verify results test create volume idempotence + assert: + that: + - not vol|changed + - vol.name == "{{ cs_resource_prefix }}_vol" + +- 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|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: + - not vol|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|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: + - not vol|changed + - vol.name == "{{ cs_resource_prefix }}_vol" + - vol.vm == "{{ test_cs_instance_2 }}" + - 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|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: + - not vol|changed + - vol.name == "{{ cs_resource_prefix }}_vol" + - vol.attached is undefined + +- name: test delete volume + cs_volume: + name: "{{ cs_resource_prefix }}_vol" + state: absent + register: vol +- name: verify results test create volume + assert: + that: + - vol|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: + - not vol|changed + +- name: cleanup instance 1 + cs_instance: + name: "{{ test_cs_instance_1 }}" + state: absent + register: instance +- name: verify create instance + assert: + that: + - instance|success + +- name: cleanup instance 2 + cs_instance: + name: "{{ test_cs_instance_2 }}" + state: absent + register: instance +- name: verify create instance + assert: + that: + - instance|success From b0525da8c879faf837fba026c908bf0521e7629f Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sat, 5 Dec 2015 15:19:43 +0100 Subject: [PATCH 2/2] cloudstack: cs_volume: add tests for volume resize See https://github.com/ansible/ansible-modules-extras/pull/1333 --- .../roles/test_cs_volume/defaults/main.yml | 2 +- .../roles/test_cs_volume/tasks/main.yml | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/test/integration/roles/test_cs_volume/defaults/main.yml b/test/integration/roles/test_cs_volume/defaults/main.yml index 546469f33fc..311a99bbe82 100644 --- a/test/integration/roles/test_cs_volume/defaults/main.yml +++ b/test/integration/roles/test_cs_volume/defaults/main.yml @@ -3,4 +3,4 @@ test_cs_instance_1: "{{ cs_resource_prefix }}-vm1" test_cs_instance_2: "{{ cs_resource_prefix }}-vm2" test_cs_instance_template: CentOS 5.3(64-bit) no GUI (Simulator) test_cs_instance_offering_1: Small Instance -test_cs_disk_offering_1: Small +test_cs_disk_offering_1: Custom diff --git a/test/integration/roles/test_cs_volume/tasks/main.yml b/test/integration/roles/test_cs_volume/tasks/main.yml index fa1f1026028..ae57039cee8 100644 --- a/test/integration/roles/test_cs_volume/tasks/main.yml +++ b/test/integration/roles/test_cs_volume/tasks/main.yml @@ -43,22 +43,54 @@ 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|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: - not vol|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|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: + - not vol|changed + - vol.size == 10 * 1024 ** 3 - vol.name == "{{ cs_resource_prefix }}_vol" - name: test attach volume