2017-12-10 15:55:55 +00:00
|
|
|
# Test code for the vmware_datastore_facts module.
|
2018-02-26 07:53:22 +00:00
|
|
|
# Copyright (c) 2017, Tim Rightnour <thegarbledone@gmail.com>
|
|
|
|
# Copyright (c) 2018, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2017-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
- name: make sure pyvmomi is installed
|
|
|
|
pip:
|
|
|
|
name: pyvmomi
|
|
|
|
state: latest
|
|
|
|
|
|
|
|
- name: store the vcenter container ip
|
|
|
|
set_fact:
|
|
|
|
vcsim: "{{ lookup('env', 'vcenter_host') }}"
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
var: vcsim
|
|
|
|
|
|
|
|
- name: Wait for Flask controller to come up online
|
|
|
|
wait_for:
|
|
|
|
host: "{{ vcsim }}"
|
|
|
|
port: 5000
|
|
|
|
state: started
|
|
|
|
|
|
|
|
- name: kill vcsim
|
|
|
|
uri:
|
2018-02-26 07:53:22 +00:00
|
|
|
url: http://{{ vcsim }}:5000/killall
|
2017-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
- name: start vcsim
|
|
|
|
uri:
|
2018-02-26 07:53:22 +00:00
|
|
|
url: http://{{ vcsim }}:5000/spawn?ds=2&datacenter=1&cluster=1&folder=0
|
2017-12-10 15:55:55 +00:00
|
|
|
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:
|
2018-02-26 07:53:22 +00:00
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=CCR
|
2017-12-10 15:55:55 +00:00
|
|
|
register: clusters
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
cl1: "{{ clusters['json'][0] }}"
|
|
|
|
|
|
|
|
- name: get a list of Datacenters from vcsim
|
|
|
|
uri:
|
2018-02-26 07:53:22 +00:00
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=DC
|
2017-12-10 15:55:55 +00:00
|
|
|
register: datacenters
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
dc1: "{{ datacenters['json'][0] }}"
|
|
|
|
|
|
|
|
- name: get a list of Datastores from vcsim
|
|
|
|
uri:
|
2018-02-26 07:53:22 +00:00
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=D
|
2017-12-10 15:55:55 +00:00
|
|
|
register: datastores
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
ds1: "{{ datastores['json'][0] }}"
|
|
|
|
|
|
|
|
# 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: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance['json']['username'] }}"
|
|
|
|
password: "{{ vcsim_instance['json']['password'] }}"
|
|
|
|
datacenter: "{{ dc1 | basename }}"
|
|
|
|
register: datastore_facts_0001
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: "{{ datastore_facts_0001 }}"
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "datastore_facts_0001['datastores'][0]['capacity'] is defined"
|
|
|
|
- "datastore_facts_0001['datastores'][1]['capacity'] is defined"
|
|
|
|
|
|
|
|
# Testcase 0002: Get a full list of datastores in a cluster
|
|
|
|
- name: get list of facts about datastores - no dc
|
|
|
|
vmware_datastore_facts:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance['json']['username'] }}"
|
|
|
|
password: "{{ vcsim_instance['json']['password'] }}"
|
|
|
|
cluster: "{{ cl1 | basename }}"
|
|
|
|
register: datastore_facts_0002
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: "{{ datastore_facts_0002 }}"
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "datastore_facts_0002['datastores'][0]['capacity'] is defined"
|
|
|
|
- "datastore_facts_0002['datastores'][1]['capacity'] is defined"
|
|
|
|
|
|
|
|
# Testcase 0003: Find a specific datastore
|
|
|
|
- name: get list of facts about one datastore
|
|
|
|
vmware_datastore_facts:
|
|
|
|
validate_certs: False
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance['json']['username'] }}"
|
|
|
|
password: "{{ vcsim_instance['json']['password'] }}"
|
|
|
|
datacenter: "{{ dc1 | basename }}"
|
|
|
|
name: "{{ ds1 | basename }}"
|
|
|
|
register: datastore_facts_0003
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
msg: "{{ datastore_facts_0003 }}"
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "datastore_facts_0003['datastores'][0]['name'] == ds1 | basename"
|
|
|
|
- "datastore_facts_0003['datastores'][0]['capacity'] is defined"
|