Skip to content

Commit

Permalink
ACA-1562: modify maintenance mode test and adjust for vcenter env
Browse files Browse the repository at this point in the history
  • Loading branch information
prabinovRedhat committed Jun 26, 2024
1 parent 77657c0 commit b214181
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 29 deletions.
13 changes: 0 additions & 13 deletions tests/integration/targets/esxi_maintenance_mode_test/run.yml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/integration/targets/esxi_maintenance_mode_test/runme.sh

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- hosts: localhost
gather_facts: no
collections:
- community.general

tasks:
- name: Import eco-vcenter credentials
ansible.builtin.include_vars:
file: ../../integration_config.yml
tags: eco-vcenter-ci

- name: Import simulator vars
ansible.builtin.include_vars:
file: vars.yml
tags: integration-ci

- name: Vcsim
ansible.builtin.import_role:
name: prepare_soap
tags: integration-ci

- name: Import esxi maintenance test
ansible.builtin.include_role:
name: vmware_ops_esxi_maintenance_mode_test
tags:
- eco-vcenter-ci
- integration-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# tasks/add_resource_pool.yml

- name: Add or Remove Resource Pool
community.vmware.vmware_resource_pool:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
cluster: "{{ provision_virtual_esxi_cluster }}"
validate_certs: "{{ provision_virtual_esxi_validate_certs }}"
resource_pool: "{{ resource_pool_name }}"
state: "{{ state }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
- name: Test esxi maintenance on simulator
tags: integration-ci
block:
- name: Enable Maintenance Mode
ansible.builtin.include_role:
name: cloud.vmware_ops.esxi_maintenance_mode
vars:
esxi_maintenance_mode_enable: True

- name: Disable Maintenance Mode
ansible.builtin.include_role:
name: cloud.vmware_ops.esxi_maintenance_mode
vars:
esxi_maintenance_mode_enable: False

- name: Test esxi maintenance mode on vcenter env
tags: eco-vcenter-ci
block:
- name: Run task for adding resource pool
ansible.builtin.include_tasks: add_or_remove_resource_pool.yml
vars:
state: present

- name: Provision Virtual Esxi
ansible.builtin.import_role:
name: cloud.vmware_ops.provision_virtual_esxi

- name: Wait until ESXi VM is powered off after OS installation
community.vmware.vmware_guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
port: "{{ provision_virtual_esxi_port }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
validate_certs: "{{ provision_virtual_esxi_validate_certs }}"
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: _esxi_power_status
until: _esxi_power_status.instance.hw_power_status == 'poweredOff'
retries: 30
delay: 20

- name: Power on ESXi VM if it is off
ansible.builtin.include_role:
name: cloud.vmware_ops.provision_vm
vars:
provision_vm_state: "poweredon"

- name: Wait until ESXi VM has an IP address
community.vmware.vmware_guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
port: "{{ provision_virtual_esxi_port }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
validate_certs: "{{ provision_virtual_esxi_validate_certs }}"
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: _esxi_host_check
until: _esxi_host_check.instance.ipv4 is defined and _esxi_host_check.instance.ipv4 is not none
retries: 30
delay: 10

- name: Check if ESXi is up
wait_for:
host: "{{ _esxi_host_check.instance.ipv4 }}"
port: 22
delay: 10
timeout: 300
state: started

- name: Add ESXI Host To vCenter Cluster
ansible.builtin.import_role:
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: present
vcenter_host_connection_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 }}"

- name: Enable Maintenance Mode
ansible.builtin.import_role:
name: cloud.vmware_ops.esxi_maintenance_mode
vars:
esxi_maintenance_mode_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 }}"
esxi_maintenance_mode_enable: True

- name: Gather ESXI host facts after enabling maintenance mode
community.vmware.vmware_host_facts:
hostname: "{{ _esxi_host_check.instance.ipv4 }}"
username: "{{ vcenter_host_connection_esxi_username }}"
password: "{{ vcenter_host_connection_esxi_password }}"
validate_certs: "{{ esxi_maintenance_mode_validate_certs }}"
register: esxi_facts

- name: Assert if ESXI host is in maintenance mode
ansible.builtin.assert:
that:
- esxi_facts.ansible_facts.ansible_in_maintenance_mode == true
fail_msg: "ESXI host is not in maintenance mode"
success_msg: "ESXI host is in maintenance mode"

- name: Disable Maintenance Mode
ansible.builtin.import_role:
name: cloud.vmware_ops.esxi_maintenance_mode
vars:
esxi_maintenance_mode_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 }}"
esxi_maintenance_mode_enable: False

- name: Gather ESXI host facts after disabling maintenance mode
community.vmware.vmware_host_facts:
hostname: "{{ _esxi_host_check.instance.ipv4 }}"
username: "{{ vcenter_host_connection_esxi_username }}"
password: "{{ vcenter_host_connection_esxi_password }}"
validate_certs: "{{ esxi_maintenance_mode_validate_certs }}"
register: esxi_facts

- name: Assert if ESXI host is out of maintenance mode
ansible.builtin.assert:
that:
- esxi_facts.ansible_facts.ansible_in_maintenance_mode == false
fail_msg: "ESXI host is still in maintenance mode"
success_msg: "ESXI host is out of maintenance mode"

always:
- name: Remove ESXI Host From vCenter Cluster
ansible.builtin.import_role:
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: absent
vcenter_host_connection_esxi_hostname: "{{ _esxi_host_check.instance.ipv4 | default('') }}"

- name: Cleanup Virtual Esxi
ansible.builtin.include_role:
name: cloud.vmware_ops.provision_vm
vars:
provision_vm_state: "absent"
provision_vm_force: true

- name: Run task for removing resource pool
ansible.builtin.include_tasks: add_or_remove_resource_pool.yml
vars:
state: absent
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ esxi_maintenance_mode_username: "test"
esxi_maintenance_mode_password: "test"
esxi_maintenance_mode_validate_certs: false
esxi_maintenance_mode_port: "8989"
esxi_maintenance_mode_esxi_hostname: DC0_C0_H2
esxi_maintenance_mode_esxi_hostname: DC0_C0_H2
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# General vars
resource_prefix: host-maintenance
resource_pool_name: "{{ resource_prefix }}-pool"
cluster_name: "Eco-Cluster"
datacenter_name: "Eco-Datacenter"
network_name: "TestNetwork"

# Vars for cloud.vmware_ops.provision_virtual_esxi role
provision_virtual_esxi_hostname: "{{ vcenter_hostname }}"
provision_virtual_esxi_username: "{{ vcenter_username }}"
provision_virtual_esxi_password: "{{ vcenter_password }}"
provision_virtual_esxi_validate_certs: false
provision_virtual_esxi_port: 443
provision_virtual_esxi_cluster: "{{ cluster_name }}"
provision_virtual_esxi_datacenter: "{{ datacenter_name }}"
provision_virtual_esxi_folder: ""
provision_virtual_esxi_resource_pool: "{{ resource_pool_name }}"
provision_virtual_esxi_datastore_iso_path: "[eco-nfs-datastore-iso] custom_esxi_8.iso"
provision_virtual_esxi_vms:
- name: ci-vcenter-maintenance-test
provision_virtual_esxi_networks:
- name: "{{ network_name }}"
device_type: "vmxnet3"
type: "dhcp"
mac: "00:50:56:8b:93:a5"
provision_virtual_esxi_disks:
- size_gb: 100
type: thin
datastore: datastore1

# Vars for cloud.vmware_ops.vcenter_host_connection role
vcenter_host_connection_hostname: "{{ vcenter_hostname }}"
vcenter_host_connection_username: "{{ vcenter_username }}"
vcenter_host_connection_password: "{{ vcenter_password }}"
vcenter_host_connection_validate_certs: false
vcenter_host_connection_port: 443
vcenter_host_connection_cluster: "{{ cluster_name }}"
vcenter_host_connection_datacenter: "{{ datacenter_name }}"
vcenter_host_connection_esxi_username: "root"
vcenter_host_connection_esxi_password: "!#%135qEt"

# Var for cloud.vmware_ops.provision_vm role
provision_vm_hostname: "{{ provision_virtual_esxi_hostname }}"
provision_vm_username: "{{ provision_virtual_esxi_username }}"
provision_vm_password: "{{ provision_virtual_esxi_password }}"
provision_vm_validate_certs: false
provision_vm_port: "{{ provision_virtual_esxi_port }}"
provision_vm_cluster: "{{ provision_virtual_esxi_cluster }}"
provision_vm_datacenter: "{{ provision_virtual_esxi_datacenter }}"
provision_vm_name: "{{ provision_virtual_esxi_vms[0].name }}"

# Vars for esxi_maintenance_mode role
esxi_maintenance_mode_hostname: "{{ vcenter_hostname }}"
esxi_maintenance_mode_username: "{{ vcenter_username }}"
esxi_maintenance_mode_password: "{{ vcenter_password }}"
esxi_maintenance_mode_validate_certs: false
esxi_maintenance_mode_port: "443"

0 comments on commit b214181

Please sign in to comment.