Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorency committed Jan 8, 2025
1 parent bf96f5c commit 087dd6c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 26 deletions.
4 changes: 4 additions & 0 deletions plugins/modules/esxi_maintenance_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ def main():
else:
result['result'] = esxi_maint_mode.disable_maintenance_mode()

# this field has the ESXi host object in it, which can't be output by ansible without manipulation.
# but we dont need it in the output anyway, so just delete it
del result['result']['result']

module.exit_json(**result)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,93 @@

- name: Test
block:
- name: "Test setup: Create Virtual ESXi Host"
community.vmware.vmware_guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster: "{{ vm_cluster }}"
datacenter: "{{ vm_datacenter }}"
folder: "{{ vm_folder }}"
state: present
name: "{{ vm }}"
disk: "{{ vm_disk }}"
guest_id: "{{ vm_guest_id }}"
hardware: "{{ vm_hardware }}"

- name: Deploy Virtual ESXi Hosts
- name: Deploy Virtual ESXi Host
community.vmware.vmware_content_deploy_ovf_template:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
cluster: "{{ vcenter_cluster_name }}"
validate_certs: "{{ validate_certs }}"
validate_certs: false
library: "{{ ci_resources_content_library }}"
template: "{{ esxi_content_library_template }}"
datastore: "{{ shared_storage_02 }}"
name: "{{ test_esxi_hostname }}"

- name: Add ESXi Host to vCenter
community.vmware.vmware_host:
- name: Power On Host
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
validate_certs: false
state: powered-on
name: "{{ test_esxi_hostname }}"

- name: Wait For ESXi Host To Have IP
vmware.vmware.guest_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster: "{{ vcenter_cluster_name }}"
validate_certs: false
name: "{{ test_esxi_hostname }}"
register: _esxi_info
until: _esxi_info.guests[0].ipv4 is defined and _esxi_info.guests[0].ipv4
retries: 10
delay: 5

- name: Join Hosts To Cluster
community.vmware.vmware_host:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ vcenter_datacenter }}"
esxi_hostname: "{{ test_esxi_hostname }}"
cluster: "{{ vcenter_cluster_name }}"
esxi_hostname: "{{ _esxi_info.guests[0].ipv4 }}"
esxi_username: root
esxi_password: "!#%135qEt"
state: present
add_connected: false

- name: Unset Host Maintenance Mode
vmware.vmware.esxi_maintenance_mode:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
enable_maintenance_mode: False
name: "{{ _esxi_info.guests[0].ipv4 }}"
register: _set
- name: Check Task Output
ansible.builtin.assert:
that:
- _set is not changed

- name: Set Host Maintenance Mode
vmware.vmware.esxi_maintenance_mode:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
enable_maintenance_mode: true
name: "{{ _esxi_info.guests[0].ipv4 }}"
register: _set

- name: Gather Info about ESXi Host
community.vmware.vmware_host_facts:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
esxi_hostname: "{{ _esxi_info.guests[0].ipv4 }}"
register: _host_info

- name: Check Task Output
ansible.builtin.assert:
that:
- _set is changed
- _host_info.ansible_facts.ansible_in_maintenance_mode

always:
- name: Disconnect Host From vCenter
community.vmware.vmware_host:
Expand All @@ -55,16 +101,17 @@
password: "{{ vcenter_password }}"
cluster: "{{ vcenter_cluster_name }}"
datacenter: "{{ vcenter_datacenter }}"
esxi_hostname: "{{ test_esxi_hostname }}"
esxi_hostname: "{{ _esxi_info.guests[0].ipv4 | default(test_esxi_hostname) }}"
state: absent
- name: "Test cleanup: Delete Virtual ESXi Host"
community.vmware.vmware_guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster: "{{ vm_cluster }}"
datacenter: "{{ vm_datacenter }}"
folder: "{{ vm_folder }}"
cluster: "{{ vcenter_cluster_name }}"
datacenter: "{{ vcenter_datacenter }}"
folder: ""
state: absent
name: "{{ test_esxi_hostname }}"
force: true

0 comments on commit 087dd6c

Please sign in to comment.