diff --git a/tests/e2e/molecule/provision_vm/destroy.yml b/tests/e2e/molecule/provision_vm/destroy.yml new file mode 100644 index 00000000..b65fac70 --- /dev/null +++ b/tests/e2e/molecule/provision_vm/destroy.yml @@ -0,0 +1,20 @@ +--- +- name: Deprovision VM + hosts: localhost + gather_facts: false + tasks: + - name: Include vSphere datacenter creds + ansible.builtin.include_vars: + file: ../vault_files/vsphere_creds.yml + + - name: Include deprovision VM vars + ansible.builtin.include_vars: + file: vars/deprovision_vm_vars.yml + + - name: Deprovision a VM + ansible.builtin.import_role: + name: provision_vm + + - name: Verify that VM is absent + ansible.builtin.include_tasks: + file: post_validations/verify_vm_deprovisioning.yml diff --git a/tests/e2e/molecule/provision_vm/molecule.yml b/tests/e2e/molecule/provision_vm/molecule.yml index e5ae83d8..b67500f7 100644 --- a/tests/e2e/molecule/provision_vm/molecule.yml +++ b/tests/e2e/molecule/provision_vm/molecule.yml @@ -3,7 +3,7 @@ dependency: name: galaxy driver: - name: docker + name: podman platforms: - name: instance @@ -26,10 +26,11 @@ provisioner: ANSIBLE_ROLES_PATH: "../../../../roles" config_options: defaults: - vault_password_file: ${HOME}/vsphere_crds_vault_pass.txt + vault_password_file: ${HOME}/vault.pass callback_whitelist: junit playbooks: converge: ../converge.yml + destroy: destroy.yml verifier: name: ansible diff --git a/tests/e2e/molecule/provision_vm/post_validations/verify_vm_deprovisioning.yml b/tests/e2e/molecule/provision_vm/post_validations/verify_vm_deprovisioning.yml new file mode 100644 index 00000000..bdc45359 --- /dev/null +++ b/tests/e2e/molecule/provision_vm/post_validations/verify_vm_deprovisioning.yml @@ -0,0 +1,22 @@ +--- +- name: Verify Deprovisioned VM + ansible.builtin.include_vars: + file: ../vars/deprovision_vm_vars.yml + +- name: Check that VM does not exist + community.vmware.vmware_vm_info: + hostname: "{{ provision_vm_hostname }}" + username: "{{ provision_vm_username }}" + password: "{{ provision_vm_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + vm_name: "{{ provision_vm_name }}" + register: vm_info + ignore_errors: true + +- ansible.builtin.debug: + var: vm_info + +- name: Fail the task if the VM exists + ansible.builtin.fail: + msg: "Provisioned VM still exists" + when: not vm_info.failed diff --git a/tests/e2e/molecule/provision_vm/post_validations/verify_vm_post_provisioning.yml b/tests/e2e/molecule/provision_vm/post_validations/verify_vm_post_provisioning.yml index 7d793eb0..16191236 100644 --- a/tests/e2e/molecule/provision_vm/post_validations/verify_vm_post_provisioning.yml +++ b/tests/e2e/molecule/provision_vm/post_validations/verify_vm_post_provisioning.yml @@ -1,7 +1,7 @@ --- - name: Verify Provisioned VM ansible.builtin.include_vars: - file: vars.yml + file: ../vars/vars.yml - name: Check VM existence community.vmware.vmware_vm_info: diff --git a/tests/e2e/molecule/provision_vm/vars/deprovision_vm_vars.yml b/tests/e2e/molecule/provision_vm/vars/deprovision_vm_vars.yml new file mode 100644 index 00000000..202985eb --- /dev/null +++ b/tests/e2e/molecule/provision_vm/vars/deprovision_vm_vars.yml @@ -0,0 +1,8 @@ +# vars.yaml +provision_vm_validate_certs: false +provision_vm_cluster: "nestedcluster" +provision_vm_folder: "/nesteddatacenter/vm" +provision_vm_datacenter: "nesteddatacenter" +provision_vm_name: "qe-provision-vm" +provision_vm_state: "absent" +provision_vm_force: true \ No newline at end of file diff --git a/tests/e2e/molecule/provision_vm/vars/vars.yml b/tests/e2e/molecule/provision_vm/vars/vars.yml index c8384d67..d469a7fa 100644 --- a/tests/e2e/molecule/provision_vm/vars/vars.yml +++ b/tests/e2e/molecule/provision_vm/vars/vars.yml @@ -3,7 +3,7 @@ provision_vm_validate_certs: false provision_vm_cluster: "nestedcluster" provision_vm_folder: "/nesteddatacenter/vm" provision_vm_datacenter: "nesteddatacenter" -provision_vm_name: "smiron-provision-vm-2" +provision_vm_name: "qe-provision-vm" provision_vm_state: "poweredon" provision_vm_cdrom: - controller_number: 0 @@ -35,6 +35,6 @@ provision_vm_hardware: num_cpus: 4 boot_firmware: efi secure_boot: true -# provision_vm_guest_id: "rhel9_64Guest" +provision_vm_guest_id: "rhel9_64Guest" provision_vm_datastore: "Datastore-host1" -provision_vm_template: "provision-vm-template" +# provision_vm_template: "provision-vm-template" diff --git a/tests/integration/requirements.yml b/tests/integration/requirements.yml index a7276e35..38e398af 100644 --- a/tests/integration/requirements.yml +++ b/tests/integration/requirements.yml @@ -1,4 +1,6 @@ collections: - name: community.vmware + version: "4.2.0" - name: vmware.vmware_rest + version: "2.3.1" - name: containers.podman