2017-07-24 17:02:58 +00:00
|
|
|
# Test code for the vmware_host module.
|
2017-11-06 16:28:15 +00:00
|
|
|
# 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)
|
2017-07-24 17:02:58 +00:00
|
|
|
|
|
|
|
- name: make sure pyvmomi is installed
|
|
|
|
pip:
|
|
|
|
name: pyvmomi
|
|
|
|
state: latest
|
2017-10-12 14:20:33 +00:00
|
|
|
when: "{{ ansible_user_id == 'root' }}"
|
2017-07-24 17:02:58 +00:00
|
|
|
|
|
|
|
- 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:
|
|
|
|
url: http://{{ vcsim }}:5000/killall
|
|
|
|
|
|
|
|
- name: start vcsim
|
|
|
|
uri:
|
|
|
|
url: http://{{ vcsim }}:5000/spawn?cluster=2
|
|
|
|
register: vcsim_instance
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
var: 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
|
|
|
|
|
|
|
|
- name: get a datacenter
|
|
|
|
set_fact:
|
|
|
|
dc1: "{{ datacenters.json[0] | basename }}"
|
|
|
|
|
|
|
|
- debug: var=dc1
|
|
|
|
|
|
|
|
- name: get a list of Cluster from vcsim
|
|
|
|
uri:
|
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=CCR
|
|
|
|
register: clusters
|
|
|
|
|
|
|
|
- name: get a cluster
|
|
|
|
set_fact:
|
|
|
|
ccr1: "{{ clusters.json[0] | basename }}"
|
|
|
|
|
|
|
|
- debug: var=ccr1
|
|
|
|
|
2017-12-13 16:13:12 +00:00
|
|
|
# Testcase: Add Host
|
2017-07-24 17:02:58 +00:00
|
|
|
- name: add host
|
|
|
|
vmware_host:
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance.json.username }}"
|
|
|
|
password: "{{ vcsim_instance.json.password }}"
|
|
|
|
validate_certs: no
|
|
|
|
esxi_hostname: test_host_system_0001
|
|
|
|
esxi_username: "{{ vcsim_instance.json.username }}"
|
|
|
|
esxi_password: "{{ vcsim_instance.json.password }}"
|
|
|
|
datacenter_name: "{{ dc1 }}"
|
|
|
|
cluster_name: "{{ ccr1 }}"
|
|
|
|
state: present
|
2017-12-13 16:13:12 +00:00
|
|
|
register: add_host_result
|
2017-07-24 17:02:58 +00:00
|
|
|
|
|
|
|
- name: get a list of host system from vcsim after adding host system
|
|
|
|
uri:
|
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=H
|
2017-12-13 16:13:12 +00:00
|
|
|
register: host_list
|
2017-07-24 17:02:58 +00:00
|
|
|
|
|
|
|
- name: ensure host system is present
|
|
|
|
assert:
|
|
|
|
that:
|
2017-12-13 16:13:12 +00:00
|
|
|
- add_host_result | changed
|
|
|
|
- "{% for host in host_list.json if ((host | basename) == 'test_host_system_0001') -%} True {%- else -%} False {%- endfor %}"
|
2017-07-24 17:02:58 +00:00
|
|
|
|
2017-12-13 16:13:12 +00:00
|
|
|
# Testcase: Add Host again
|
2017-07-24 17:02:58 +00:00
|
|
|
- name: add host again
|
|
|
|
vmware_host:
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance.json.username }}"
|
|
|
|
password: "{{ vcsim_instance.json.password }}"
|
|
|
|
validate_certs: no
|
|
|
|
esxi_hostname: test_host_system_0001
|
|
|
|
esxi_username: "{{ vcsim_instance.json.username }}"
|
|
|
|
esxi_password: "{{ vcsim_instance.json.password }}"
|
|
|
|
datacenter_name: "{{ dc1 }}"
|
|
|
|
cluster_name: "{{ ccr1 }}"
|
|
|
|
state: present
|
2017-12-13 16:13:12 +00:00
|
|
|
register: readd_host_result
|
|
|
|
|
|
|
|
- name: ensure precend task didn't changed anything
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not (readd_host_result|changed)
|
|
|
|
|
|
|
|
# Testcase: Add Host via add_or_reconnect state
|
|
|
|
- name: add host via add_or_reconnect
|
|
|
|
vmware_host:
|
|
|
|
hostname: "{{ vcsim }}"
|
|
|
|
username: "{{ vcsim_instance.json.username }}"
|
|
|
|
password: "{{ vcsim_instance.json.password }}"
|
|
|
|
validate_certs: no
|
|
|
|
esxi_hostname: test_host_system_0002
|
|
|
|
esxi_username: "{{ vcsim_instance.json.username }}"
|
|
|
|
esxi_password: "{{ vcsim_instance.json.password }}"
|
|
|
|
datacenter_name: "{{ dc1 }}"
|
|
|
|
cluster_name: "{{ ccr1 }}"
|
|
|
|
state: add_or_reconnect
|
|
|
|
register: add_or_reconnect_host_result
|
|
|
|
|
|
|
|
- name: get a list of host system from vcsim after adding host system
|
|
|
|
uri:
|
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=H
|
|
|
|
register: host_list
|
2017-07-24 17:02:58 +00:00
|
|
|
|
|
|
|
- name: ensure host system is present
|
|
|
|
assert:
|
|
|
|
that:
|
2017-12-13 16:13:12 +00:00
|
|
|
- add_or_reconnect_host_result | changed
|
|
|
|
- "{% for host in host_list.json if ((host | basename) == 'test_host_system_0002') -%} True {%- else -%} False {%- endfor %}"
|
|
|
|
|
|
|
|
## Testcase: Reconnect Host
|
|
|
|
#
|
|
|
|
# ReconnectHost_Task need to be implemented in vcsim for this test to work
|
|
|
|
# https://github.com/vmware/govmomi/tree/master/vcsim#supported-methods
|
|
|
|
#
|
|
|
|
#- name: reconnect host
|
|
|
|
# vmware_host:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# esxi_hostname: test_host_system_0001
|
|
|
|
# datacenter_name: "{{ dc1 }}"
|
|
|
|
# cluster_name: "{{ ccr1 }}"
|
|
|
|
# state: reconnect
|
|
|
|
# register: reconnect_host_result
|
|
|
|
#
|
|
|
|
#- name: ensure host system has been reconnected
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - reconnect_host_result | changed
|
|
|
|
# # it would be a good idea to check the events on the host to see the reconnect
|
|
|
|
# # https://github.com/vmware/govmomi/blob/master/govc/USAGE.md#events
|
|
|
|
# # "govc events ..." need to be callable from
|
|
|
|
# # test/utils/docker/vcenter-simulator/flask_control.py
|
|
|
|
|
|
|
|
## Testcase: Remove Host
|
|
|
|
#
|
|
|
|
# EnterMaintenanceMode_Task need to be implemented in vcsim for this test to work
|
|
|
|
# https://github.com/vmware/govmomi/tree/master/vcsim#supported-methods
|
|
|
|
#
|
|
|
|
#- name: remove host
|
|
|
|
# vmware_host:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# esxi_hostname: test_host_system_0001
|
|
|
|
# datacenter_name: "{{ dc1 }}"
|
|
|
|
# cluster_name: "{{ ccr1 }}"
|
|
|
|
# state: absent
|
|
|
|
# register: remove_host_result
|
|
|
|
#
|
|
|
|
#- name: get a list of host system from vcsim after removing host system
|
|
|
|
# uri:
|
|
|
|
# url: http://{{ vcsim }}:5000/govc_find?filter=H
|
|
|
|
# register: host_list
|
|
|
|
#
|
|
|
|
#- name: ensure host system is absent
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - remove_host_result | changed
|
|
|
|
# - "{% for host in host_list.json if ((host | basename) == 'test_host_system_0001') -%} False {%- else -%} True {%- endfor %}"
|
|
|
|
|
|
|
|
## Testcase: Remove Host again
|
|
|
|
#
|
|
|
|
# EnterMaintenanceMode_Task need to be implemented in vcsim for this test to work
|
|
|
|
# https://github.com/vmware/govmomi/tree/master/vcsim#supported-methods
|
|
|
|
#
|
|
|
|
#- name: remove host again
|
|
|
|
# vmware_host:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# esxi_hostname: test_host_system_0001
|
|
|
|
# datacenter_name: "{{ dc1 }}"
|
|
|
|
# cluster_name: "{{ ccr1 }}"
|
|
|
|
# state: absent
|
|
|
|
# register: reremove_host_result
|
|
|
|
#
|
|
|
|
#- name: ensure precend task didn't changed anything
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - not (reremove_host_result|changed)
|