2019-11-22 22:42:41 +01:00
|
|
|
# Test code for the vmware_vmotion module.
|
|
|
|
# Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
- import_role:
|
|
|
|
name: prepare_vmware_tests
|
|
|
|
vars:
|
|
|
|
setup_attach_host: true
|
|
|
|
setup_datastore: true
|
2020-01-10 19:01:51 +01:00
|
|
|
setup_resource_pool: true
|
2019-11-22 22:42:41 +01:00
|
|
|
|
2020-01-10 19:01:51 +01:00
|
|
|
- when: vcsim is not defined
|
|
|
|
block:
|
|
|
|
- name: Add ESXi Hosts to vCenter
|
|
|
|
vmware_host:
|
|
|
|
datacenter_name: '{{ dc1 }}'
|
|
|
|
esxi_hostname: '{{ item }}'
|
|
|
|
esxi_username: '{{ esxi_user }}'
|
|
|
|
esxi_password: '{{ esxi_password }}'
|
|
|
|
folder: '/DC0/host'
|
|
|
|
state: present
|
|
|
|
with_items: "{{ esxi_hosts }}"
|
|
|
|
|
|
|
|
- name: Disable the Maintenance Mode
|
|
|
|
vmware_maintenancemode:
|
|
|
|
esxi_hostname: '{{ item }}'
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ esxi_hosts }}"
|
|
|
|
|
|
|
|
- name: Create VM
|
2019-11-22 22:42:41 +01:00
|
|
|
vmware_guest:
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
validate_certs: no
|
|
|
|
name: test_vm1
|
|
|
|
folder: vm
|
|
|
|
esxi_hostname: "{{ esxi1 }}"
|
|
|
|
state: present
|
|
|
|
guest_id: centos7_64Guest
|
|
|
|
disk:
|
|
|
|
- size_gb: 1
|
|
|
|
type: thin
|
|
|
|
datastore: '{{ rw_datastore }}'
|
|
|
|
hardware:
|
|
|
|
version: latest
|
|
|
|
memory_mb: 1024
|
|
|
|
num_cpus: 1
|
|
|
|
scsi: paravirtual
|
|
|
|
register: vm_create
|
|
|
|
|
2020-01-10 19:01:51 +01:00
|
|
|
- name: Perform vMotion of non-existing VM
|
|
|
|
vmware_vmotion:
|
|
|
|
hostname: '{{ vcenter_hostname }}'
|
|
|
|
username: '{{ vcenter_username }}'
|
|
|
|
password: '{{ vcenter_password }}'
|
|
|
|
validate_certs: no
|
|
|
|
vm_name: not_a_thing
|
|
|
|
destination_host: '{{ esxi2 }}'
|
|
|
|
destination_datastore: '{{ rw_datastore }}'
|
|
|
|
register: vm_vmotion
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- vm_vmotion.msg == "Failed to find the virtual machine with not_a_thing"
|
|
|
|
|
|
|
|
|
2019-11-22 22:42:41 +01:00
|
|
|
- name: Perform vMotion of virtual machine
|
|
|
|
vmware_vmotion:
|
|
|
|
hostname: '{{ vcenter_hostname }}'
|
|
|
|
username: '{{ vcenter_username }}'
|
|
|
|
password: '{{ vcenter_password }}'
|
|
|
|
validate_certs: no
|
|
|
|
vm_name: test_vm1
|
|
|
|
destination_host: '{{ esxi2 }}'
|
2020-01-10 19:01:51 +01:00
|
|
|
destination_datastore: '{{ rw_datastore }}'
|
2019-11-22 22:42:41 +01:00
|
|
|
register: vm_vmotion
|
|
|
|
|
|
|
|
- name: assert that changes were made
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- vm_vmotion is changed
|
|
|
|
|
2020-01-10 19:01:51 +01:00
|
|
|
|
|
|
|
- name: Add ESXi Hosts to a cluster
|
|
|
|
vmware_host:
|
|
|
|
datacenter_name: '{{ dc1 }}'
|
|
|
|
cluster_name: '{{ ccr1 }}'
|
|
|
|
esxi_hostname: '{{ item }}'
|
|
|
|
esxi_username: '{{ esxi_user }}'
|
|
|
|
esxi_password: '{{ esxi_password }}'
|
|
|
|
state: present
|
|
|
|
with_items: "{{ esxi_hosts }}"
|
|
|
|
|
|
|
|
- name: Disable the Maintenance Mode
|
|
|
|
vmware_maintenancemode:
|
|
|
|
esxi_hostname: '{{ item }}'
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ esxi_hosts }}"
|
|
|
|
|
2019-11-22 22:42:41 +01:00
|
|
|
- name: Perform vMotion of virtual machine to resource_pool
|
|
|
|
vmware_vmotion:
|
|
|
|
hostname: '{{ vcenter_hostname }}'
|
|
|
|
username: '{{ vcenter_username }}'
|
|
|
|
password: '{{ vcenter_password }}'
|
|
|
|
validate_certs: no
|
2020-01-10 19:01:51 +01:00
|
|
|
vm_name: test_vm1
|
2019-11-22 22:42:41 +01:00
|
|
|
destination_host: '{{ esxi1 }}'
|
2020-01-10 19:01:51 +01:00
|
|
|
destination_resourcepool: DC0_C0_RP1
|
2019-11-22 22:42:41 +01:00
|
|
|
register: vm_vmotion_to_rp
|
|
|
|
|
|
|
|
- name: assert that changes were made
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- vm_vmotion_to_rp is changed
|
|
|
|
|
2020-01-10 19:01:51 +01:00
|
|
|
- name: Perform storage vMotion of virtual machine
|
2019-11-22 22:42:41 +01:00
|
|
|
vmware_vmotion:
|
|
|
|
hostname: '{{ vcenter_hostname }}'
|
|
|
|
username: '{{ vcenter_username }}'
|
|
|
|
password: '{{ vcenter_password }}'
|
|
|
|
validate_certs: no
|
2020-01-10 19:01:51 +01:00
|
|
|
vm_name: test_vm1
|
|
|
|
destination_host: '{{ esxi2 }}'
|
|
|
|
destination_datastore: '{{ rw_datastore }}'
|
2019-11-22 22:42:41 +01:00
|
|
|
register: vm_vmotion_to_datastore
|
|
|
|
|
|
|
|
- name: assert that changes were made
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- vm_vmotion_to_datastore is changed
|