Skip to content

Commit

Permalink
enable provision virtual esxi integration target test to run on eco v…
Browse files Browse the repository at this point in the history
…center
  • Loading branch information
shellymiron committed Jun 26, 2024
1 parent 89531a7 commit 5ceae3d
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 27 deletions.
Binary file removed tests/integration/targets/.DS_Store
Binary file not shown.
13 changes: 0 additions & 13 deletions tests/integration/targets/provision_virtual_esxi_test/run.yml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/integration/targets/provision_virtual_esxi_test/runme.sh

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- hosts: localhost
gather_facts: false
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 provision virtual ESXi role
ansible.builtin.include_role:
name: vmware_ops_provision_virtual_esxi_test
tags:
- integration-ci
- eco-vcenter-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
- name: Power off ESXi VM
ansible.builtin.include_role:
name: cloud.vmware_ops.provision_vm
vars:
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 }}"
provision_vm_state: "poweredoff"

- name: Cleanup Virtual Esxi
ansible.builtin.include_role:
name: cloud.vmware_ops.provision_vm
vars:
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 }}"
provision_vm_state: "absent"
provision_vm_force: true

- name: Check if ESXi VM is down
command: ping -c 1 -W 5 {{ esxi_host.instance.ipv4 }}
register: ping_check_result
ignore_errors: true

- name: Set fact if ping is not available
set_fact:
ping_not_available: "{{ ping_check_result.rc != 0 }}"

- name: Verify VM absence in vCenter
community.vmware.vmware_guest_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
validate_certs: no
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: vm_info
ignore_errors: true

- name: Fail if VM is still present in vCenter
fail:
msg: "The VM {{ provision_virtual_esxi_vms[0].name }} is still present in vCenter."
when: vm_info.instance is defined

- name: Cleanup Resource Pool
community.vmware.vmware_resource_pool:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
validate_certs: "{{ provision_virtual_esxi_validate_certs }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
cluster: "{{ provision_virtual_esxi_cluster }}"
resource_pool: "{{ resource_pool_name }}"
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
- name: Test Virtual Esxi Provisioning on Simulator
tags: integration-ci
ansible.builtin.import_role:
name: cloud.vmware_ops.provision_virtual_esxi

- name: Test Virtual Esxi Provisioning on vCenter Env
tags: eco-vcenter-ci
block:
- name: Add 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: present

- name: Provision Virtual Esxi
ansible.builtin.import_role:
name: cloud.vmware_ops.provision_virtual_esxi
vars:
provision_virtual_esxi_resource_pool: "{{ resource_pool_name }}"

- 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.import_role:
name: cloud.vmware_ops.provision_vm
vars:
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 }}"
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: Set fact for esxi instance
set_fact:
esxi_host: "{{ _esxi_host_check }}"

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

always:
- name: "Call cleanup playbook"
ansible.builtin.include_tasks: cleanup_esxi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
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: "Eco-Cluster"
provision_virtual_esxi_folder: "e2e-qe"
provision_virtual_esxi_datacenter: "Eco-Datacenter"
provision_virtual_esxi_datastore_iso_path: "[eco-nfs-datastore-iso] esxi_8.iso"
resource_pool_name: ci-resource-pool-test
provision_virtual_esxi_vms:
- name: ci-esxi-test-1
network_name: "VM Network"
provision_virtual_esxi_networks:
- name: "{{ network_name }}"
device_type: "vmxnet3"
type: "dhcp"
mac: "00:50:56:8b:95:ff"
provision_virtual_esxi_disks:
- size_gb: 100
type: thin
datastore: datastore1
provision_virtual_esxi_memory_mb: 10000
provision_virtual_esxi_cpus: 8
provision_vm_datastore: "datastore1"

0 comments on commit 5ceae3d

Please sign in to comment.