| 1 |
# Test code for the vmware_guest_info module. |
| 2 |
# Copyright: (c) 2017, Abhijeet Kasurde <[email protected]> |
| 3 |
# Copyright: (c) 2018, James E. King III (@jeking3) <[email protected]> |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
- import_role: |
| 7 |
name: prepare_vmware_tests |
| 8 |
vars: |
| 9 |
setup_attach_host: true |
| 10 |
setup_datastore: true |
| 11 |
setup_virtualmachines: true |
| 12 |
|
| 13 |
# Testcase 0001: Get details about virtual machines |
| 14 |
- name: get list of info about virtual machines |
| 15 |
vmware_guest_info: |
| 16 |
validate_certs: false |
| 17 |
hostname: "{{ vcenter_hostname }}" |
| 18 |
username: "{{ vcenter_username }}" |
| 19 |
password: "{{ vcenter_password }}" |
| 20 |
datacenter: "{{ dc1 }}" |
| 21 |
name: "{{ virtual_machines[0].name }}" |
| 22 |
folder: "{{ virtual_machines[0].folder }}" |
| 23 |
register: guest_info_0001 |
| 24 |
|
| 25 |
- debug: |
| 26 |
var: guest_info_0001 |
| 27 |
|
| 28 |
- assert: |
| 29 |
that: |
| 30 |
- "guest_info_0001['instance']['hw_name'] == virtual_machines[0].name" |
| 31 |
- "guest_info_0001['instance']['hw_product_uuid'] is defined" |
| 32 |
- "guest_info_0001['instance']['hw_cores_per_socket'] is defined" |
| 33 |
- "guest_info_0001['instance']['hw_datastores'] is defined" |
| 34 |
- "guest_info_0001['instance']['hw_esxi_host'] is defined" |
| 35 |
- "guest_info_0001['instance']['hw_files'] is defined" |
| 36 |
- "guest_info_0001['instance']['hw_guest_ha_state'] is defined" |
| 37 |
- "guest_info_0001['instance']['hw_is_template'] is defined" |
| 38 |
- "guest_info_0001['instance']['hw_folder'] is defined" |
| 39 |
- "guest_info_0001['instance']['guest_question'] is defined" |
| 40 |
- "guest_info_0001['instance']['guest_consolidation_needed'] is defined" |
| 41 |
- "guest_info_0001['instance']['moid'] is defined" |
| 42 |
- "guest_info_0001['instance']['vimref'] is defined" |
| 43 |
- "'portgroup_portkey' in guest_info_0001['instance']['hw_eth0']" |
| 44 |
- "'portgroup_key' in guest_info_0001['instance']['hw_eth0']" |
| 45 |
- "guest_info_0001['instance']['instance_uuid'] is defined" |
| 46 |
|
| 47 |
- set_fact: vm1_uuid="{{ guest_info_0001['instance']['hw_product_uuid'] }}" |
| 48 |
|
| 49 |
- set_fact: vm1_instance_uuid="{{ guest_info_0001['instance']['instance_uuid'] }}" |
| 50 |
|
| 51 |
- set_fact: vm1_moid="{{ guest_info_0001['instance']['moid'] }}" |
| 52 |
|
| 53 |
- debug: |
| 54 |
var: vm1_uuid |
| 55 |
|
| 56 |
# Testcase 0002: Get details about virtual machines using UUID |
| 57 |
- name: get list of info about virtual machines using UUID |
| 58 |
vmware_guest_info: |
| 59 |
validate_certs: false |
| 60 |
hostname: "{{ vcenter_hostname }}" |
| 61 |
username: "{{ vcenter_username }}" |
| 62 |
password: "{{ vcenter_password }}" |
| 63 |
datacenter: "{{ dc1 }}" |
| 64 |
uuid: "{{ vm1_uuid }}" |
| 65 |
register: guest_info_0002 |
| 66 |
|
| 67 |
- debug: |
| 68 |
var: guest_info_0002 |
| 69 |
|
| 70 |
- name: Get specific details about virtual machines using the vsphere output schema |
| 71 |
vmware_guest_info: |
| 72 |
validate_certs: false |
| 73 |
hostname: "{{ vcenter_hostname }}" |
| 74 |
username: "{{ vcenter_username }}" |
| 75 |
password: "{{ vcenter_password }}" |
| 76 |
datacenter: "{{ dc1 }}" |
| 77 |
uuid: "{{ vm1_uuid }}" |
| 78 |
schema: vsphere |
| 79 |
properties: |
| 80 |
- config.hardware.memoryMB |
| 81 |
- guest |
| 82 |
- name |
| 83 |
- summary.runtime.connectionState |
| 84 |
register: guest_info_0002b |
| 85 |
|
| 86 |
- debug: |
| 87 |
var: guest_info_0002b |
| 88 |
|
| 89 |
- assert: |
| 90 |
that: |
| 91 |
- "guest_info_0002['instance']['hw_name'] == virtual_machines[0].name" |
| 92 |
- "guest_info_0002['instance']['hw_product_uuid'] is defined" |
| 93 |
- "guest_info_0002['instance']['hw_product_uuid'] == vm1_uuid" |
| 94 |
- "guest_info_0002['instance']['hw_cores_per_socket'] is defined" |
| 95 |
- "guest_info_0002b['instance']['config']['hardware']['memoryMB'] is defined" |
| 96 |
- "guest_info_0002b['instance']['config']['hardware']['numCoresPerSocket'] is not defined" |
| 97 |
- "guest_info_0002b['instance']['guest']['toolsVersion'] is defined" |
| 98 |
- "guest_info_0001['instance']['moid'] is defined" |
| 99 |
- "guest_info_0001['instance']['vimref'] is defined" |
| 100 |
- "guest_info_0002b['instance']['overallStatus'] is not defined" |
| 101 |
|
| 102 |
# https://github.com/ansible-collections/vmware/issues/33 |
| 103 |
- name: Get specific details about VM using the vsphere output schema |
| 104 |
vmware_guest_info: |
| 105 |
validate_certs: false |
| 106 |
hostname: "{{ vcenter_hostname }}" |
| 107 |
username: "{{ vcenter_username }}" |
| 108 |
password: "{{ vcenter_password }}" |
| 109 |
datacenter: "{{ dc1 }}" |
| 110 |
uuid: "{{ vm1_uuid }}" |
| 111 |
schema: vsphere |
| 112 |
properties: |
| 113 |
- config.hardware.device.deviceInfo.summary |
| 114 |
register: guest_info_with_list |
| 115 |
|
| 116 |
- debug: |
| 117 |
var: guest_info_with_list |
| 118 |
|
| 119 |
- assert: |
| 120 |
that: |
| 121 |
- "guest_info_with_list['instance']['config']['hardware']['device'] is defined" |
| 122 |
|
| 123 |
# Testcase 0003: Get details about virtual machines without snapshots using UUID |
| 124 |
- name: get empty list of snapshots from virtual machine using UUID |
| 125 |
vmware_guest_info: |
| 126 |
validate_certs: false |
| 127 |
hostname: "{{ vcenter_hostname }}" |
| 128 |
username: "{{ vcenter_username }}" |
| 129 |
password: "{{ vcenter_password }}" |
| 130 |
datacenter: "{{ dc1 }}" |
| 131 |
uuid: "{{ vm1_uuid }}" |
| 132 |
register: guest_info_0003 |
| 133 |
|
| 134 |
- debug: |
| 135 |
var: guest_info_0003 |
| 136 |
|
| 137 |
- assert: |
| 138 |
that: |
| 139 |
- "guest_info_0003['instance']['snapshots']|length == 0" |
| 140 |
- "guest_info_0003['instance']['current_snapshot'] is none" |
| 141 |
|
| 142 |
# Testcase 0004: Get details about virtual machines with two snapshots using UUID |
| 143 |
- name: Create first snapshot |
| 144 |
vmware.vmware.vm_snapshot: &vm_snap |
| 145 |
validate_certs: false |
| 146 |
hostname: "{{ vcenter_hostname }}" |
| 147 |
username: "{{ vcenter_username }}" |
| 148 |
password: "{{ vcenter_password }}" |
| 149 |
datacenter: "{{ dc1 }}" |
| 150 |
name: "{{ virtual_machines[0].name }}" |
| 151 |
folder: "{{ virtual_machines[0].folder }}" |
| 152 |
state: present |
| 153 |
snapshot_name: snap1 |
| 154 |
|
| 155 |
- name: Create second snapshot |
| 156 |
vmware.vmware.vm_snapshot: |
| 157 |
<<: *vm_snap |
| 158 |
snapshot_name: snap2 |
| 159 |
|
| 160 |
- name: get list of snapshots from virtual machine using UUID |
| 161 |
vmware_guest_info: |
| 162 |
validate_certs: false |
| 163 |
hostname: "{{ vcenter_hostname }}" |
| 164 |
username: "{{ vcenter_username }}" |
| 165 |
password: "{{ vcenter_password }}" |
| 166 |
datacenter: "{{ dc1 }}" |
| 167 |
uuid: "{{ vm1_uuid }}" |
| 168 |
register: guest_info_0004 |
| 169 |
|
| 170 |
- debug: |
| 171 |
var: guest_info_0004 |
| 172 |
|
| 173 |
- assert: |
| 174 |
that: |
| 175 |
- "guest_info_0004['instance']['snapshots'] is defined" |
| 176 |
- "guest_info_0004['instance']['snapshots'][0]['name'] == 'snap1'" |
| 177 |
- "guest_info_0004['instance']['snapshots'][1]['name'] == 'snap2'" |
| 178 |
- "guest_info_0004['instance']['current_snapshot']['name'] == 'snap2'" |
| 179 |
- "guest_info_0004['instance']['hw_folder'] is defined" |
| 180 |
|
| 181 |
# Testcase 0005: Get details about virtual machines using UUID |
| 182 |
- name: get list of info about virtual machines using instance UUID |
| 183 |
vmware_guest_info: |
| 184 |
validate_certs: false |
| 185 |
hostname: "{{ vcenter_hostname }}" |
| 186 |
username: "{{ vcenter_username }}" |
| 187 |
password: "{{ vcenter_password }}" |
| 188 |
datacenter: "{{ dc1 }}" |
| 189 |
uuid: "{{ vm1_instance_uuid }}" |
| 190 |
use_instance_uuid: true |
| 191 |
register: guest_info_0005 |
| 192 |
|
| 193 |
- debug: |
| 194 |
msg: "{{ guest_info_0005 }}" |
| 195 |
|
| 196 |
- assert: |
| 197 |
that: |
| 198 |
- "guest_info_0005['instance']['hw_name'] == virtual_machines[0].name" |
| 199 |
- "guest_info_0005['instance']['hw_product_uuid'] is defined" |
| 200 |
- "guest_info_0005['instance']['hw_product_uuid'] == vm1_uuid" |
| 201 |
- "guest_info_0005['instance']['hw_cores_per_socket'] is defined" |
| 202 |
- "guest_info_0005['instance']['hw_datastores'] is defined" |
| 203 |
- "guest_info_0005['instance']['hw_esxi_host'] is defined" |
| 204 |
- "guest_info_0005['instance']['hw_files'] is defined" |
| 205 |
- "guest_info_0005['instance']['hw_guest_ha_state'] is defined" |
| 206 |
- "guest_info_0005['instance']['hw_is_template'] is defined" |
| 207 |
- "guest_info_0005['instance']['hw_folder'] is defined" |
| 208 |
- "guest_info_0005['instance']['guest_question'] is defined" |
| 209 |
- "guest_info_0005['instance']['guest_consolidation_needed'] is defined" |
| 210 |
- "guest_info_0005['instance']['instance_uuid'] is defined" |
| 211 |
- "guest_info_0005['instance']['instance_uuid'] == vm1_instance_uuid" |
| 212 |
- "guest_info_0005['instance']['moid'] is defined" |
| 213 |
- "guest_info_0005['instance']['vimref'] is defined" |
| 214 |
|
| 215 |
# Testcase 0006: Get details about virtual machines using MoID |
| 216 |
- name: get list of information about virtual machines using instance MoID |
| 217 |
vmware_guest_info: |
| 218 |
validate_certs: false |
| 219 |
hostname: "{{ vcenter_hostname }}" |
| 220 |
username: "{{ vcenter_username }}" |
| 221 |
password: "{{ vcenter_password }}" |
| 222 |
datacenter: "{{ dc1 }}" |
| 223 |
moid: "{{ vm1_moid }}" |
| 224 |
use_instance_uuid: true |
| 225 |
register: guest_info_0006 |
| 226 |
|
| 227 |
- debug: |
| 228 |
msg: "{{ guest_info_0006 }}" |
| 229 |
|
| 230 |
- assert: |
| 231 |
that: |
| 232 |
- "guest_info_0006['instance']['hw_name'] == virtual_machines[0].name" |
| 233 |
- "guest_info_0006['instance']['hw_product_uuid'] is defined" |
| 234 |
- "guest_info_0006['instance']['hw_product_uuid'] == vm1_uuid" |
| 235 |
- "guest_info_0006['instance']['hw_cores_per_socket'] is defined" |
| 236 |
- "guest_info_0006['instance']['hw_datastores'] is defined" |
| 237 |
- "guest_info_0006['instance']['hw_esxi_host'] is defined" |
| 238 |
- "guest_info_0006['instance']['hw_files'] is defined" |
| 239 |
- "guest_info_0006['instance']['hw_guest_ha_state'] is defined" |
| 240 |
- "guest_info_0006['instance']['hw_is_template'] is defined" |
| 241 |
- "guest_info_0006['instance']['hw_folder'] is defined" |
| 242 |
- "guest_info_0006['instance']['guest_question'] is defined" |
| 243 |
- "guest_info_0006['instance']['guest_consolidation_needed'] is defined" |
| 244 |
- "guest_info_0006['instance']['instance_uuid'] is defined" |
| 245 |
- "guest_info_0006['instance']['instance_uuid'] == vm1_instance_uuid" |
| 246 |
- "guest_info_0006['instance']['moid'] is defined" |
| 247 |
- "guest_info_0006['instance']['vimref'] is defined" |