You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/vmware_host/tasks/main.yml

307 lines
9.2 KiB
YAML

# Test code for the vmware_host module.
# 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)
- 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
- 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
# Testcase: Add Host
- 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 }}"
fetch_ssl_thumbprint: False
state: present
register: add_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
- name: ensure host system is present
assert:
that:
- add_host_result is changed
- "{% for host in host_list.json if ((host | basename) == 'test_host_system_0001') -%} True {%- else -%} False {%- endfor %}"
# Testcase: Add Host again
- 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 }}"
fetch_ssl_thumbprint: False
state: present
register: readd_host_result
- name: ensure precend task didn't changed anything
assert:
that:
- not ( readd_host_result is 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 }}"
fetch_ssl_thumbprint: False
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
- name: ensure host system is present
assert:
that:
- add_or_reconnect_host_result is changed
- "{% for host in host_list.json if ((host | basename) == 'test_host_system_0002') -%} True {%- else -%} False {%- endfor %}"
## 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 %}"
## 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 is 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
# # https://github.com/ansible/vcenter-test-container/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 is 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 is changed)