2017-07-24 19:02:58 +02:00
|
|
|
# Test code for the vmware_host module.
|
2017-11-06 17:28:15 +01: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 19:02:58 +02:00
|
|
|
|
|
|
|
- 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
|
|
|
|
|
2019-02-25 09:38:33 +01:00
|
|
|
- name: get a list of hosts from vcsim
|
|
|
|
uri:
|
|
|
|
url: http://{{ vcsim }}:5000/govc_find?filter=H
|
|
|
|
register: hosts
|
|
|
|
|
|
|
|
- name: get a host
|
|
|
|
set_fact:
|
|
|
|
host1: "{{ hosts.json[0] | basename }}"
|
|
|
|
|
|
|
|
- debug: var=host1
|
|
|
|
|
|
|
|
# fetch_ssl_thumbprint needs to be disabled because the host only exists in vcsim
|
|
|
|
|
2017-12-13 17:13:12 +01:00
|
|
|
# Testcase: Add Host
|
2017-07-24 19:02:58 +02: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 }}"
|
2019-02-25 09:38:33 +01:00
|
|
|
fetch_ssl_thumbprint: False
|
2017-07-24 19:02:58 +02:00
|
|
|
state: present
|
2017-12-13 17:13:12 +01:00
|
|
|
register: add_host_result
|
2017-07-24 19:02:58 +02: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 17:13:12 +01:00
|
|
|
register: host_list
|
2017-07-24 19:02:58 +02:00
|
|
|
|
|
|
|
- name: ensure host system is present
|
|
|
|
assert:
|
|
|
|
that:
|
2017-12-21 20:42:53 +01:00
|
|
|
- add_host_result is changed
|
2017-12-13 17:13:12 +01:00
|
|
|
- "{% for host in host_list.json if ((host | basename) == 'test_host_system_0001') -%} True {%- else -%} False {%- endfor %}"
|
2017-07-24 19:02:58 +02:00
|
|
|
|
2017-12-13 17:13:12 +01:00
|
|
|
# Testcase: Add Host again
|
2017-07-24 19:02:58 +02: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 }}"
|
2019-02-25 09:38:33 +01:00
|
|
|
fetch_ssl_thumbprint: False
|
2017-07-24 19:02:58 +02:00
|
|
|
state: present
|
2017-12-13 17:13:12 +01:00
|
|
|
register: readd_host_result
|
|
|
|
|
|
|
|
- name: ensure precend task didn't changed anything
|
|
|
|
assert:
|
|
|
|
that:
|
2017-12-21 20:42:53 +01:00
|
|
|
- not ( readd_host_result is changed)
|
2017-12-13 17:13:12 +01:00
|
|
|
|
|
|
|
# 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 }}"
|
2019-02-25 09:38:33 +01:00
|
|
|
fetch_ssl_thumbprint: False
|
2017-12-13 17:13:12 +01:00
|
|
|
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 19:02:58 +02:00
|
|
|
|
|
|
|
- name: ensure host system is present
|
|
|
|
assert:
|
|
|
|
that:
|
2017-12-21 20:42:53 +01:00
|
|
|
- add_or_reconnect_host_result is changed
|
2017-12-13 17:13:12 +01:00
|
|
|
- "{% for host in host_list.json if ((host | basename) == 'test_host_system_0002') -%} True {%- else -%} False {%- endfor %}"
|
|
|
|
|
2019-02-25 09:38:33 +01:00
|
|
|
## Testcase: Add Host to folder
|
|
|
|
#
|
|
|
|
# It's not possible to connect an ESXi host via vcsim.
|
|
|
|
#
|
|
|
|
# - name: Create host folder
|
|
|
|
# vcenter_folder:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# datacenter: "{{ dc1 }}"
|
|
|
|
# folder_name: "Staging"
|
|
|
|
# folder_type: host
|
|
|
|
# state: present
|
|
|
|
# register: folder_results
|
|
|
|
#
|
|
|
|
# - debug: msg="{{ folder_results }}"
|
|
|
|
#
|
|
|
|
# - name: ensure folder is present
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - folder_results.changed
|
|
|
|
#
|
|
|
|
# - name: Create host folder again
|
|
|
|
# vcenter_folder:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# datacenter: "{{ dc1 }}"
|
|
|
|
# folder_name: "Staging"
|
|
|
|
# folder_type: host
|
|
|
|
# state: present
|
|
|
|
# register: folder_results
|
|
|
|
#
|
|
|
|
# - debug: msg="{{ folder_results }}"
|
|
|
|
#
|
|
|
|
# - name: ensure folder is present
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - folder_results.changed == False
|
|
|
|
#
|
|
|
|
# - name: Add host to folder in check mode
|
|
|
|
# vmware_host:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# esxi_hostname: test_host_system_0003
|
|
|
|
# esxi_username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# esxi_password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# datacenter_name: "{{ dc1 }}"
|
|
|
|
# folder_name: "Staging"
|
|
|
|
# state: present
|
|
|
|
# register: add_host_to_folder_result
|
|
|
|
# check_mode: yes
|
|
|
|
#
|
|
|
|
# - 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
|
|
|
|
#
|
|
|
|
# - name: ensure host system is not present
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - add_host_to_folder_result is changed
|
|
|
|
# - not ("{% for host in host_list.json if ((host | basename) == 'test_host_system_0003') -%} True {%- else -%} False {%- endfor %}")
|
|
|
|
#
|
|
|
|
# - name: Add host to folder
|
|
|
|
# vmware_host:
|
|
|
|
# hostname: "{{ vcsim }}"
|
|
|
|
# username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# validate_certs: no
|
|
|
|
# esxi_hostname: test_host_system_0003
|
|
|
|
# esxi_username: "{{ vcsim_instance.json.username }}"
|
|
|
|
# esxi_password: "{{ vcsim_instance.json.password }}"
|
|
|
|
# datacenter_name: "{{ dc1 }}"
|
|
|
|
# folder_name: "Staging"
|
|
|
|
# state: present
|
|
|
|
# register: add_host_to_folder_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
|
|
|
|
#
|
|
|
|
# - name: ensure host system is present
|
|
|
|
# assert:
|
|
|
|
# that:
|
|
|
|
# - add_host_to_folder_result is changed
|
|
|
|
# - "{% for host in host_list.json if ((host | basename) == 'test_host_system_0003') -%} True {%- else -%} False {%- endfor %}"
|
|
|
|
|
2017-12-13 17:13:12 +01:00
|
|
|
## 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:
|
2017-12-21 20:42:53 +01:00
|
|
|
# - reconnect_host_result is changed
|
2017-12-13 17:13:12 +01:00
|
|
|
# # 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
|
2018-08-30 00:59:36 +02:00
|
|
|
# # https://github.com/ansible/vcenter-test-container/flask_control.py
|
2017-12-13 17:13:12 +01:00
|
|
|
|
|
|
|
## 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:
|
2017-12-21 20:42:53 +01:00
|
|
|
# - remove_host_result is changed
|
2017-12-13 17:13:12 +01:00
|
|
|
# - "{% 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:
|
2017-12-21 20:42:53 +01:00
|
|
|
# - not ( reremove_host_result is changed)
|