diff --git a/tests/integration/targets/.DS_Store b/tests/integration/targets/.DS_Store deleted file mode 100644 index 1260aaf1..00000000 Binary files a/tests/integration/targets/.DS_Store and /dev/null differ diff --git a/tests/integration/targets/provision_virtual_esxi_test/run.yml b/tests/integration/targets/provision_virtual_esxi_test/run.yml deleted file mode 100644 index 578350dd..00000000 --- a/tests/integration/targets/provision_virtual_esxi_test/run.yml +++ /dev/null @@ -1,13 +0,0 @@ -- hosts: localhost - gather_facts: no - collections: - - community.general - - tasks: - - name: Vcsim - ansible.builtin.import_role: - name: prepare_soap - - - name: Import provision virtual ESXi role - ansible.builtin.import_role: - name: provision_virtual_esxi_test diff --git a/tests/integration/targets/provision_virtual_esxi_test/runme.sh b/tests/integration/targets/provision_virtual_esxi_test/runme.sh deleted file mode 100755 index 798a7b39..00000000 --- a/tests/integration/targets/provision_virtual_esxi_test/runme.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -source ../init.sh -ansible-playbook mock_side_effects.yml & -PID="$!" - -ansible-playbook run.yml -RESULT=$? -pkill -P "$PID" - -exit $RESULT diff --git a/tests/integration/targets/provision_virtual_esxi_test/tasks/main.yml b/tests/integration/targets/provision_virtual_esxi_test/tasks/main.yml deleted file mode 100644 index 7869fdf0..00000000 --- a/tests/integration/targets/provision_virtual_esxi_test/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- name: Provision VM - ansible.builtin.import_role: - name: cloud.vmware_ops.provision_virtual_esxi diff --git a/tests/integration/targets/provision_virtual_esxi_test/mock_side_effects.yml b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/mock_side_effects.yml similarity index 100% rename from tests/integration/targets/provision_virtual_esxi_test/mock_side_effects.yml rename to tests/integration/targets/vmware_ops_provision_virtual_esxi_test/mock_side_effects.yml diff --git a/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/run.yml b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/run.yml new file mode 100644 index 00000000..c9b60d6b --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/run.yml @@ -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 diff --git a/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/tasks/cleanup_esxi.yml b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/tasks/cleanup_esxi.yml new file mode 100644 index 00000000..3ef656e0 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/tasks/cleanup_esxi.yml @@ -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 \ No newline at end of file diff --git a/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/tasks/main.yml b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/tasks/main.yml new file mode 100644 index 00000000..a1abd664 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/tasks/main.yml @@ -0,0 +1,83 @@ +--- +- name: Test Virtual Esxi Provisioning on Simulator + tags: integration-ci + ansible.builtin.include_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 diff --git a/tests/integration/targets/provision_virtual_esxi_test/vars/main.yml b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/vars.yml similarity index 100% rename from tests/integration/targets/provision_virtual_esxi_test/vars/main.yml rename to tests/integration/targets/vmware_ops_provision_virtual_esxi_test/vars.yml diff --git a/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/vars/main.yml b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/vars/main.yml new file mode 100644 index 00000000..35ad0f43 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_virtual_esxi_test/vars/main.yml @@ -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"