Skip to content

Commit

Permalink
add destroy stage
Browse files Browse the repository at this point in the history
  • Loading branch information
elsapassaro committed Mar 19, 2024
1 parent 102bebd commit d9aa868
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 6 deletions.
20 changes: 20 additions & 0 deletions tests/e2e/molecule/provision_vm/destroy.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions tests/e2e/molecule/provision_vm/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependency:
name: galaxy

driver:
name: docker
name: podman

platforms:
- name: instance
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/molecule/provision_vm/vars/deprovision_vm_vars.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions tests/e2e/molecule/provision_vm/vars/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
2 changes: 2 additions & 0 deletions tests/integration/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
collections:
- name: community.vmware
version: "4.2.0"
- name: vmware.vmware_rest
version: "2.3.1"
- name: containers.podman

0 comments on commit d9aa868

Please sign in to comment.