1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

vmware: refactoring of vmware test roles -- part2 (#55724)

Refactoring of the following roles to make use of the new
`prepare_vmware_tests` role.

- `vmware_datacenter`
- `vmware_datastore_cluster`
- `vmware_datastore_facts`
- `vmware_datastore_maintenancemode`

This patch depends on: https://github.com/ansible/ansible/pull/55719

Original PR: https://github.com/ansible/ansible/pull/54882
This commit is contained in:
Gonéri Le Bouder 2019-04-30 06:22:50 -04:00 committed by ansibot
parent c8c0f8c51a
commit 0e83384dfd
8 changed files with 198 additions and 290 deletions

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -2,95 +2,49 @@
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for vcsim controller to come online {{ vcsim }} - import_role:
wait_for: name: prepare_vmware_tests
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim - &add_dc
uri: name: Add datacenter
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
register: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: get a list of Datacenter from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=DC
register: datacenters
- debug: var=vcsim_instance
- debug: var=datacenters
# Testcase 0001: Add Datacenter
- name: add datacenter
vmware_datacenter: vmware_datacenter:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter_name: datacenter_0001 datacenter_name: datacenter_0001
state: present state: present
register: dc_result register: dc_result
- name: get a list of Datacenter from vcsim after adding datacenter - debug:
uri: var: dc_result
url: http://{{ vcsim }}:5000/govc_find?filter=DC
register: new_datacenters
- name: ensure datacenter is present - name: Ensure datacenter is present
assert: assert:
that: that:
- "{{ dc_result.changed == true }}" - dc_result.changed
- "{{ '/datacenter_0001' in new_datacenters['json'] }}"
# Testcase 0002: Try to add same datacenter - <<: *add_dc
- name: add datacenter again to check idempotent behavior name: add datacenter again to check idempotent behavior
vmware_datacenter:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
datacenter_name: datacenter_0001
state: present
register: dc_result_two
- name: ensure datacenter status is not changed - name: Ensure datacenter status is not changed
assert: assert:
that: that:
- "{{ dc_result_two.changed == false }}" - not dc_result.changed
# FIXME: Uncomment this testcase once vcsim supports datacenter delete method - when: vcsim is not defined
# Currently, vcsim does not support datacenter delete option, block:
# Once this feature is available we can uncomment following testcase - name: Delete datacenter
vmware_datacenter:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter_name: datacenter_0001
state: absent
register: dc_result_delete
# Testcase 0002: Delete Datacenter - name: Ensure datacenter is absent
#- name: add datacenter assert:
# vmware_datacenter: that:
# validate_certs: False - dc_result_delete.changed
# hostname: "{{ vcsim }}"
# username: "{{ vcsim_instance['json']['username'] }}"
# password: "{{ vcsim_instance['json']['password'] }}"
# datacenter_name: datacenter_0001
# state: absent
# register: dc_result_delete
#- name: get a list of Datacenter from vcsim after adding datacenter
# uri:
# url: http://{{ vcsim }}:5000/govc_find?filter=DC
# register: new_datacenters_delete
#- name: ensure datacenter is absent
# assert:
# that:
# - "{{ dc_result_delete.changed == true }}"
# - "{{ '/datacenter_0001' not in new_datacenters_delete['json'] }}

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -2,45 +2,14 @@
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for Flask controller to come up online - import_role:
wait_for: name: prepare_vmware_tests
host: '{{ vcsim }}'
port: 5000
state: started
- name: Kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: Start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
register: vcsim_instance
- name: Wait for Flask controller to come up online
wait_for:
host: '{{ vcsim }}'
port: 443
state: started
- debug:
var: vcsim_instance
- name: Get datacenter
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=DC
register: datacenters
- name: store the vcenter container ip
set_fact:
dc1: "{{ datacenters['json'][0] | basename }}"
- name: Add a datastore cluster to datacenter (check-mode) - name: Add a datastore cluster to datacenter (check-mode)
vmware_datastore_cluster: &add_datastore_cluster vmware_datastore_cluster: &add_datastore_cluster
hostname: '{{ vcsim }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcsim_instance.json.username }}' username: '{{ vcenter_username }}'
password: '{{ vcsim_instance.json.password }}' password: '{{ vcenter_password }}'
validate_certs: no validate_certs: no
datacenter_name: "{{ dc1 }}" datacenter_name: "{{ dc1 }}"
datastore_cluster_name: DSC1 datastore_cluster_name: DSC1
@ -50,7 +19,7 @@
- assert: - assert:
that: that:
- add_dsc_check.changed == true - add_dsc_check.changed
- name: Add a datastore cluster to datacenter - name: Add a datastore cluster to datacenter
vmware_datastore_cluster: *add_datastore_cluster vmware_datastore_cluster: *add_datastore_cluster
@ -58,7 +27,7 @@
- assert: - assert:
that: that:
- add_dsc.changed == true - add_dsc.changed
- name: Add a datastore cluster to datacenter again - name: Add a datastore cluster to datacenter again
vmware_datastore_cluster: *add_datastore_cluster vmware_datastore_cluster: *add_datastore_cluster
@ -66,13 +35,13 @@
- assert: - assert:
that: that:
- add_dsc.changed == false - not add_dsc.changed
- name: Delete a datastore cluster to datacenter (check-mode) - name: Delete a datastore cluster to datacenter (check-mode)
vmware_datastore_cluster: &delete_datastore_cluster vmware_datastore_cluster: &delete_datastore_cluster
hostname: '{{ vcsim }}' hostname: '{{ vcenter_hostname }}'
username: '{{ vcsim_instance.json.username }}' username: '{{ vcenter_username }}'
password: '{{ vcsim_instance.json.password }}' password: '{{ vcenter_password }}'
validate_certs: no validate_certs: no
datacenter_name: "{{ dc1 }}" datacenter_name: "{{ dc1 }}"
datastore_cluster_name: DSC1 datastore_cluster_name: DSC1
@ -82,13 +51,14 @@
- assert: - assert:
that: that:
- delete_dsc_check.changed == true - delete_dsc_check.changed
# TODO: vcsim does not support delete operation on datastore cluster - when: vcsim is not defined
#- name: Delete a datastore cluster to datacenter block:
# vmware_datastore_cluster: *delete_datastore_cluster - name: Delete a datastore cluster to datacenter
# register: delete_dsc_check vmware_datastore_cluster: *delete_datastore_cluster
register: delete_dsc_check
#- assert: - assert:
# that: that:
# - delete_dsc_check.changed == true - delete_dsc_check.changed

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -3,77 +3,77 @@
# Copyright (c) 2018, Ansible Project # Copyright (c) 2018, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?ds=2&datacenter=1&cluster=1&folder=0
register: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: get a list of Clusters from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=CCR
register: clusters
- set_fact:
cl1: "{{ clusters['json'][0] }}"
- name: get a list of Datacenters from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=DC
register: datacenters
- set_fact:
dc1: "{{ datacenters['json'][0] }}"
- name: get a list of Datastores from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=D
register: datastores
- set_fact:
ds1: "{{ datastores['json'][0] }}"
# Testcase 0001: Get a full list of datastores in a datacenter # Testcase 0001: Get a full list of datastores in a datacenter
# - name: get list of facts about datastores
# vmware_datastore_facts:
# validate_certs: False
# hostname: "{{ vcenter_hostname }}"
# username: "{{ vcenter_username }}"
# password: "{{ vcenter_password }}"
# datacenter: "{{ dc1 }}"
# register: datastore_facts_0001
# - assert:
# that:
# - "datastore_facts_0001.datastores|length == 0"
- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true
setup_datastore: true
- when: vcsim is not defined
block:
- name: get list of facts about datastores from the ESXi
vmware_datastore_facts:
validate_certs: False
hostname: '{{ hostvars[item].ansible_host }}'
username: '{{ hostvars[item].ansible_user }}'
password: '{{ hostvars[item].ansible_password }}'
register: facts_from_esxi
with_items: "{{ groups['esxi-lab'] }}"
- assert:
that:
- "facts_from_esxi.results[0].datastores|length == 2"
- name: get list of facts about datastores - name: get list of facts about datastores
vmware_datastore_facts: vmware_datastore_facts:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 | basename }}" datacenter: "{{ dc1 }}"
register: datastore_facts_0001 gather_nfs_mount_info: true
register: facts_from_vcenter_with_dc_filter
- debug: # Depends-On: https://github.com/ansible/ansible/pull/54879
msg: "{{ datastore_facts_0001 }}" - when: vcsim is not defined
block:
- name: get list of facts about datastores
vmware_datastore_facts:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
gather_nfs_mount_info: true
register: facts_from_vcenter_with_no_filter
- assert: - assert:
that: that:
- "datastore_facts_0001['datastores'][0]['capacity'] is defined" - "facts_from_vcenter_with_dc_filter.datastores|length == 2"
- "datastore_facts_0001['datastores'][1]['capacity'] is defined" - "facts_from_vcenter_with_no_filter.datastores|length == 2"
- "facts_from_vcenter_with_no_filter.datastores[0]['capacity'] is defined"
# Testcase 0002: Get a full list of datastores in a cluster # Testcase 0002: Get a full list of datastores in a cluster
- name: get list of facts about datastores - no dc - name: get list of facts about datastores - no dc
vmware_datastore_facts: vmware_datastore_facts:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
cluster: "{{ cl1 | basename }}" cluster: "{{ ccr1 }}"
register: datastore_facts_0002 register: datastore_facts_0002
- debug: - debug:
@ -82,17 +82,16 @@
- assert: - assert:
that: that:
- "datastore_facts_0002['datastores'][0]['capacity'] is defined" - "datastore_facts_0002['datastores'][0]['capacity'] is defined"
- "datastore_facts_0002['datastores'][1]['capacity'] is defined"
# Testcase 0003: Find a specific datastore # Testcase 0003: Find a specific datastore
- name: get list of facts about one datastore - name: get list of facts about one datastore
vmware_datastore_facts: vmware_datastore_facts:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 | basename }}" datacenter: "{{ dc1 }}"
name: "{{ ds1 | basename }}" name: "{{ ds1 }}"
register: datastore_facts_0003 register: datastore_facts_0003
- debug: - debug:
@ -100,16 +99,16 @@
- assert: - assert:
that: that:
- "datastore_facts_0003['datastores'][0]['name'] == ds1 | basename" - "datastore_facts_0003['datastores'][0]['name'] == ds1"
- "datastore_facts_0003['datastores'][0]['capacity'] is defined" - "datastore_facts_0003['datastores'][0]['capacity'] is defined"
- name: get list of extended facts about one datastore - name: get list of extended facts about one datastore
vmware_datastore_facts: vmware_datastore_facts:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 | basename }}" datacenter: "{{ dc1 }}"
name: "{{ ds1 | basename }}" name: "{{ ds1 | basename }}"
gather_nfs_mount_info: True gather_nfs_mount_info: True
gather_vmfs_mount_info: True gather_vmfs_mount_info: True
@ -120,16 +119,16 @@
- assert: - assert:
that: that:
- "datastore_facts_0004['datastores'][0]['name'] == ds1 | basename" - "datastore_facts_0004['datastores'][0]['name'] == ds1"
- "datastore_facts_0004['datastores'][0]['capacity'] is defined" - "datastore_facts_0004['datastores'][0]['capacity'] is defined"
- name: get list of facts about one datastore in check mode - name: get list of facts about one datastore in check mode
vmware_datastore_facts: vmware_datastore_facts:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 | basename }}" datacenter: "{{ dc1 }}"
name: "{{ ds1 | basename }}" name: "{{ ds1 | basename }}"
register: datastore_facts_0005 register: datastore_facts_0005
@ -138,5 +137,5 @@
- assert: - assert:
that: that:
- "datastore_facts_0005['datastores'][0]['name'] == ds1 | basename" - "datastore_facts_0005['datastores'][0]['name'] == ds1"
- "datastore_facts_0005['datastores'][0]['capacity'] is defined" - "datastore_facts_0005['datastores'][0]['capacity'] is defined"

View file

@ -1,2 +1,3 @@
cloud/vcenter cloud/vcenter
unsupported shippable/vcenter/group1
needs/target/prepare_vmware_tests

View file

@ -3,101 +3,82 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# TODO: vcsim does not support datastore maintenance mode properties # TODO: vcsim does not support datastore maintenance mode properties
- when: vcsim is not defined
block:
- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true
setup_datastore: true
- name: Wait for Flask controller to come up online - name: Enter datastore in maintenance mode
wait_for: vmware_datastore_maintenancemode:
host: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
port: 5000 username: "{{ vcenter_username }}"
state: started password: "{{ vcenter_password }}"
state: present
datastore: "{{ ds1 }}"
validate_certs: no
register: test_result_0001
- name: kill vcsim - debug:
uri: var: test_result_0001
url: http://{{ vcsim }}:5000/killall
- name: start vcsim - name: assert that changes were made
uri: assert:
url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=0 that:
register: vcsim_instance - test_result_0001 is changed
- name: Wait for vcsim server to come up online - name: Enter datastore in maintenance mode again
wait_for: vmware_datastore_maintenancemode:
host: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
port: 443 username: "{{ vcenter_username }}"
state: started password: "{{ vcenter_password }}"
state: present
datastore: "{{ ds1 }}"
validate_certs: no
register: test_result_0002
- name: Get a list of datastores from vcsim - debug:
uri: var: test_result_0002
url: http://{{ vcsim }}:5000/govc_find?filter=D
register: datastores
- name: Enter datastore in maintenance mode - name: assert that no changes were made
vmware_datastore_maintenancemode: assert:
hostname: "{{ vcsim }}" that:
username: "{{ vcsim_instance.json.username }}" - not (test_result_0002 is changed)
password: "{{ vcsim_instance.json.password }}"
state: present
datastore: "{{ item | basename }}"
validate_certs: False
with_items: "{{ datastores['json'] }}"
register: test_result_0001
- debug: var=test_result_0001 - name: Exit datastores from maintenance mode
vmware_datastore_maintenancemode:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
state: absent
datastore: "{{ ds1 }}"
validate_certs: no
register: test_result_0003
- name: assert that changes were made - debug:
assert: var: test_result_0003
that:
- "test_result_0001.results|map(attribute='changed')|unique|list == [true]"
- name: Enter datastore in maintenance mode again - name: assert that changes were made
vmware_datastore_maintenancemode: assert:
hostname: "{{ vcsim }}" that:
username: "{{ vcsim_instance.json.username }}" - test_result_0003 is changed
password: "{{ vcsim_instance.json.password }}"
state: present
datastore: "{{ item | basename }}"
validate_certs: no
with_items: "{{ datastores['json'] }}"
register: test_result_0002
- debug: var=test_result_0002 - name: Exit datastores from maintenance mode again
vmware_datastore_maintenancemode:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
state: absent
datastore: "{{ ds1 }}"
validate_certs: no
register: test_result_0004
- name: assert that no changes were made - debug:
assert: var: test_result_0004
that:
- "test_result_0002.results|map(attribute='changed')|unique|list == [false]"
- name: Exit datastores from maintenance mode - name: assert that no changes were made
vmware_datastore_maintenancemode: assert:
hostname: "{{ vcsim }}" that:
username: "{{ vcsim_instance.json.username }}" - not (test_result_0004 is changed)
password: "{{ vcsim_instance.json.password }}"
state: absent
esxi_hostname: "{{ item | basename }}"
validate_certs: no
with_items: "{{ datastores['json'] }}"
register: test_result_0003
- debug: var=test_result_0003
- name: assert that changes were made
assert:
that:
- "test_result_0003.results|map(attribute='changed')|unique|list == [true]"
- name: Exit datastores from maintenance mode again
vmware_datastore_maintenancemode:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
state: absent
esxi_hostname: "{{ item | basename }}"
validate_certs: no
with_items: "{{ datastores['json'] }}"
register: test_result_0004
- debug: var=test_result_0004
- name: assert that no changes were made
assert:
that:
- "test_result_0004.results|map(attribute='changed')|unique|list == [false]"