2017-07-31 04:48:57 +02:00
|
|
|
# Test code for the vmware_guest_find module.
|
|
|
|
# (c) 2017, James Tanner <tanner.jc@gmail.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
2017-06-22 19:49:58 +02:00
|
|
|
- name: make sure pyvmomi is installed
|
|
|
|
pip:
|
|
|
|
name: pyvmomi
|
2017-06-30 16:18:20 +02:00
|
|
|
state: latest
|
2017-06-22 19:49:58 +02:00
|
|
|
|
|
|
|
- name: store the vcenter container ip
|
|
|
|
set_fact:
|
|
|
|
vcsim: "{{ lookup('env', 'vcenter_host') }}"
|
|
|
|
- debug: var=vcsim
|
|
|
|
|
2017-07-21 18:12:43 +02:00
|
|
|
- name: wait for flask server
|
|
|
|
wait_for:
|
|
|
|
host: "{{ vcsim }}"
|
|
|
|
port: 5000
|
|
|
|
state: started
|
|
|
|
|
2017-06-22 19:49:58 +02:00
|
|
|
- name: kill vcsim
|
|
|
|
uri:
|
|
|
|
url: "{{ 'http://' + vcsim + ':5000/killall' }}"
|
2017-07-21 18:12:43 +02:00
|
|
|
|
2017-06-22 19:49:58 +02:00
|
|
|
- name: start vcsim
|
|
|
|
uri:
|
|
|
|
url: "{{ 'http://' + vcsim + ':5000/spawn?cluster=2' }}"
|
|
|
|
register: vcsim_instance
|
|
|
|
|
2017-07-21 18:12:43 +02:00
|
|
|
- name: wait for vcsim server
|
|
|
|
wait_for:
|
|
|
|
host: "{{ vcsim }}"
|
|
|
|
port: 443
|
|
|
|
state: started
|
|
|
|
|
2017-06-22 19:49:58 +02:00
|
|
|
- name: get a list of VMS from vcsim
|
|
|
|
uri:
|
2017-06-27 17:58:57 +02:00
|
|
|
url: "{{ 'http://' + vcsim + ':5000/govc_find?filter=VM' }}"
|
2017-06-22 19:49:58 +02:00
|
|
|
register: vmlist
|
|
|
|
|
|
|
|
- debug: var=vcsim_instance
|
|
|
|
- debug: var=vmlist
|
|
|
|
|
|
|
|
# vcsim embeds the datacenter into the path and
|
|
|
|
# the VM name, so it can be chopped out for later
|
|
|
|
# use or verification
|
|
|
|
- name: show the datacenter(s)
|
|
|
|
debug:
|
|
|
|
msg: "{{ (item|basename).split('_')[0] }}"
|
|
|
|
with_items: "{{ vmlist['json'] }}"
|
|
|
|
|
|
|
|
- name: find folders for each vm
|
|
|
|
vmware_guest_find:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance['json']['username'] }}"
|
|
|
|
password: "{{ vcsim_instance['json']['password'] }}"
|
|
|
|
name: "{{ item|basename }}"
|
|
|
|
datacenter: "{{ (item|basename).split('_')[0] }}"
|
|
|
|
with_items: "{{ vmlist['json'] }}"
|
|
|
|
register: folders
|
|
|
|
|
|
|
|
- debug: var=item
|
|
|
|
with_items: "{{ folders.results }}"
|
|
|
|
|
|
|
|
# We only care that each VM was found, not that the folder path
|
|
|
|
# is completely accurate. Eventually the test should be extended
|
|
|
|
# to validate the full path for each VM.
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "{{ 'folders' in item }}"
|
|
|
|
- "{{ item['folders']|length == 1 }}"
|
|
|
|
with_items: "{{ folders.results }}"
|
2017-06-27 17:58:57 +02:00
|
|
|
|
|
|
|
# Testcase 2: Find VMS using UUID
|
|
|
|
- name: get details about VMS from vcsim
|
|
|
|
uri:
|
|
|
|
url: "{{ 'http://' + vcsim + ':5000/govc_vm_info' }}"
|
|
|
|
register: vms_detail_list
|
|
|
|
|
|
|
|
- name: find folders for each vm using UUID
|
|
|
|
vmware_guest_find:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance['json']['username'] }}"
|
|
|
|
password: "{{ vcsim_instance['json']['password'] }}"
|
|
|
|
uuid: "{{ vms_detail_list['json'][item|basename]['UUID'] }}"
|
|
|
|
datacenter: "{{ (item|basename).split('_')[0] }}"
|
|
|
|
with_items: "{{ vmlist['json'] }}"
|
|
|
|
register: folders_uuid
|
|
|
|
|
|
|
|
- debug: var=item
|
|
|
|
with_items: "{{ folders_uuid.results }}"
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "{{ 'folders' in item }}"
|
|
|
|
- "{{ item['folders']|length == 1 }}"
|
|
|
|
with_items: "{{ folders_uuid.results }}"
|