Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cs_template: implement update and revamp #37015

Merged
merged 19 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
360 changes: 234 additions & 126 deletions lib/ansible/modules/cloud/cloudstack/cs_template.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/integration/targets/cs_template/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/cs
shippable/cs/group1
5 changes: 5 additions & 0 deletions test/integration/targets/cs_template/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
cs_template_hypervisor: Simulator
cs_template_os_type: Other Linux (64-bit)
cs_template_url: http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-vmware.ova
cs_template_format: OVA
3 changes: 3 additions & 0 deletions test/integration/targets/cs_template/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- cs_common
3 changes: 3 additions & 0 deletions test/integration/targets/cs_template/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- import_tasks: test1.yml
- import_tasks: test2.yml
160 changes: 160 additions & 0 deletions test/integration/targets/cs_template/tasks/test1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
- name: setup template
cs_template:
name: "ansible-template-test1"
state: absent
register: template
- name: verify setup template
assert:
that:
- template is successful

- name: test download template in check mode
cs_template:
name: "ansible-template-test1"
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
cross_zones: yes
register: template
check_mode: yes
- name: verify test download template in check mode
assert:
that:
- template is changed

- name: test download template
cs_template:
name: "ansible-template-test1"
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
cross_zones: yes
register: template
- name: verify test download template
assert:
that:
- template is changed
- template.name == "ansible-template-test1"
- template.display_text == "ansible-template-test1"
- template.cross_zones == true

- name: test download template idempotence
cs_template:
name: "ansible-template-test1"
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
cross_zones: yes
register: template
- name: verify test download template idempotence
assert:
that:
- template is not changed
- template.name == "ansible-template-test1"
- template.display_text == "ansible-template-test1"
- template.cross_zones == true

- name: test update template in check mode
cs_template:
name: "ansible-template-test1"
display_text: "{{ cs_resource_prefix }}-template display_text"
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
is_featured: yes
cross_zones: yes
register: template
check_mode: yes
- name: verify test update template in check mode
assert:
that:
- template is changed
- template.name == "ansible-template-test1"
- template.display_text == "ansible-template-test1"
- template.cross_zones == true
- template.is_featured == false

- name: test update template
cs_template:
name: "ansible-template-test1"
display_text: "{{ cs_resource_prefix }}-template display_text"
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
is_featured: yes
cross_zones: yes
register: template
- name: verify test update template
assert:
that:
- template is changed
- template.name == "ansible-template-test1"
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
- template.cross_zones == true
- template.is_featured == true

- name: test update template idempotence
cs_template:
name: "ansible-template-test1"
display_text: "{{ cs_resource_prefix }}-template display_text"
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
is_featured: yes
cross_zones: yes
register: template
- name: verify test update template idempotence
assert:
that:
- template is not changed
- template.name == "ansible-template-test1"
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
- template.cross_zones == true
- template.is_featured == true

- name: test remove template in check mode
cs_template:
name: "ansible-template-test1"
state: absent
cross_zones: yes
register: template
check_mode: yes
- name: verify test remove template in check mode
assert:
that:
- template is changed
- template.name == "ansible-template-test1"
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
- template.cross_zones == true

- name: test remove template
cs_template:
name: "ansible-template-test1"
state: absent
cross_zones: yes
register: template
- name: verify test remove template
assert:
that:
- template is changed
- template.name == "ansible-template-test1"
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
- template.cross_zones == true

- name: test remove template idempotence
cs_template:
name: "ansible-template-test1"
state: absent
cross_zones: yes
register: template
- name: verify test remove template idempotence
assert:
that:
- template is not changed
176 changes: 176 additions & 0 deletions test/integration/targets/cs_template/tasks/test2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
---
- name: setup template first template
cs_template:
name: ansible-template-test2
display_text: first template
state: absent
template_find_options: display_text
register: template
- name: verify setup template first template
assert:
that:
- template is successful

- name: setup template second template
cs_template:
name: ansible-template-test2
display_text: second template
state: absent
template_find_options: display_text
register: template
- name: verify setup template second template
assert:
that:
- template is successful

- name: test register first template
cs_template:
name: ansible-template-test2
display_text: first template
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
cross_zones: yes
template_find_options: display_text
register: template_first
- name: verify test register first template
assert:
that:
- template_first is changed
- template_first.name == "ansible-template-test2"
- template_first.display_text == "first template"
- template_first.cross_zones == true

- name: test register second template
cs_template:
name: ansible-template-test2
display_text: second template
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
cross_zones: yes
template_find_options: display_text
register: template_second
- name: verify test register second template
assert:
that:
- template_second is changed
- template_second.name == "ansible-template-test2"
- template_second.display_text == "second template"
- template_second.cross_zones == true
- template_second.id != template_first.id

- name: test multiple template same name absent without find options
cs_template:
name: ansible-template-test2
state: absent
register: template
ignore_errors: yes
- name: verify test multiple template same name absent without find options
assert:
that:
- template is failed
- template.msg.startswith('Multiple templates found')

- name: test update second template
cs_template:
name: ansible-template-test2
display_text: second template
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
is_featured: yes
is_public: yes
cross_zones: yes
template_find_options: display_text
register: template
- name: verify test update second template
assert:
that:
- template is changed
- template.name == "ansible-template-test2"
- template.display_text == "second template"
- template.cross_zones == true
- template.id == template_second.id
- template.is_featured == true
- template.is_public == true

- name: test update second template idempotence
cs_template:
name: ansible-template-test2
display_text: second template
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
is_featured: yes
is_public: yes
cross_zones: yes
template_find_options: display_text
register: template
- name: verify test update second template idempotence
assert:
that:
- template is not changed
- template.name == "ansible-template-test2"
- template.display_text == "second template"
- template.cross_zones == true
- template.id == template_second.id
- template.is_featured == true

- name: test update second template idempotence 2
cs_template:
name: ansible-template-test2
display_text: second template
url: "{{ cs_template_url }}"
format: "{{ cs_template_format }}"
hypervisor: "{{ cs_template_hypervisor }}"
os_type: "{{ cs_template_os_type }}"
cross_zones: yes
template_find_options: display_text
register: template
- name: verify test update second template idempotence
assert:
that:
- template is not changed
- template.name == "ansible-template-test2"
- template.display_text == "second template"
- template.cross_zones == true
- template.id == template_second.id

- name: test delete first template
cs_template:
name: ansible-template-test2
display_text: first template
state: absent
template_find_options: display_text
register: template
- name: verify test delete first template
assert:
that:
- template is changed
- template.name == "ansible-template-test2"
- template.display_text == "first template"
- template.cross_zones == true
- template.id == template_first.id
- template.is_featured == false

- name: test delete second template
cs_template:
name: ansible-template-test2
display_text: second template
state: absent
template_find_options: display_text
register: template
- name: verify test delete second template
assert:
that:
- template is changed
- template.name == "ansible-template-test2"
- template.display_text == "second template"
- template.cross_zones == true
- template.id == template_second.id
- template.is_featured == true
3 changes: 0 additions & 3 deletions test/sanity/validate-modules/ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ lib/ansible/modules/cloud/cloudstack/cs_staticnat.py E324
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E322
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E325
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E326
lib/ansible/modules/cloud/cloudstack/cs_template.py E324
lib/ansible/modules/cloud/cloudstack/cs_template.py E325
lib/ansible/modules/cloud/cloudstack/cs_template.py E326
lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py E325
lib/ansible/modules/cloud/cloudstack/cs_volume.py E322
lib/ansible/modules/cloud/cloudstack/cs_volume.py E324
Expand Down