Skip to content

Commit

Permalink
Merge pull request redhat-cop#1 from elsapassaro/add_deprovisioning
Browse files Browse the repository at this point in the history
Add deprovisioning stage
  • Loading branch information
shellymiron committed Mar 19, 2024
2 parents 6a05a40 + d9aa868 commit 636f395
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 22 deletions.
24 changes: 24 additions & 0 deletions tests/e2e/molecule/provision_vm/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- 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
vars:
provision_vm_hostname: "{{ vCenter_hostname }}"
provision_vm_username: "{{ vCenter_username }}"
provision_vm_password: "{{ vCenter_password }}"

- name: Verify that VM is absent
ansible.builtin.include_tasks:
file: post_validations/verify_vm_deprovisioning.yml
7 changes: 4 additions & 3 deletions tests/e2e/molecule/provision_vm/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
dependency:
name: galaxy

# driver:
# name: docker
driver:
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,19 @@
---
- 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: "{{ vCenter_hostname }}"
username: "{{ vCenter_username }}"
password: "{{ vCenter_password }}"
validate_certs: "{{ provision_vm_validate_certs }}"
vm_name: "{{ provision_vm_name }}"
register: vm_info
ignore_errors: true

- 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
Expand Up @@ -5,9 +5,9 @@

- name: Check VM existence
community.vmware.vmware_vm_info:
hostname: "{{ provision_vm_hostname }}"
username: "{{ provision_vm_username }}"
password: "{{ provision_vm_password }}"
hostname: "{{ vCenter_hostname }}"
username: "{{ vCenter_username }}"
password: "{{ vCenter_password }}"
validate_certs: "{{ provision_vm_validate_certs }}"
vm_name: "{{ provision_vm_name }}"
register: vm_info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- name: Provision a VM
ansible.builtin.import_role:
name: provision_vm
vars:
provision_vm_hostname: "{{ vCenter_hostname }}"
provision_vm_username: "{{ vCenter_username }}"
provision_vm_password: "{{ vCenter_password }}"

- name: Verify Provisioned VM
ansible.builtin.include_tasks:
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"
26 changes: 13 additions & 13 deletions tests/e2e/molecule/vault_files/vsphere_creds.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
$ANSIBLE_VAULT;1.1;AES256
62353361643765386533316139656438306166613765336366376563313666666538663838306336
3335623861613631303431623730366564663635643863640a396435306332373639326232643531
63356366366232623830383762653230626139343731366466623262626132623736663732366562
3237326363346263360a623535353534343365663431616537663634353563383639313334343463
35353637373237386133633234383939356537316632376139613366376132323436306464313439
34373939333930353931356432356361376437383338313732663866373663623865613166626632
36306564336464346164656431363865633465613864373231303538333935356434353966383164
65663566613333396435363866623066623530306662646162353665613034663434336261313865
36353738396334633263343766623736343362393765333030386563343563393138363035373135
31613839636538373339346266333863336139363534393339383361376232303939313036633263
66396438613030613433376334663637616566326566643162363430326239316334623534316437
31613962633362383132653166656561366535323236656363333736313536623663386434313234
30646130353664346530383264323433313666393162373261373465336266623032
39656266323032616132376530316632633133316234363564313635353064363365343431313631
6530383432643133663361623536353634386230326338610a653731663737653334616638353462
39313462313966653832376162353139306463323635383065653632653164313533623866666230
3762616333306463360a653333663966613565633231343034386634636366333530346563653166
32623366626334363361323661346230333135333062613964613766336337313739633333386235
38313235366463343531623362666635396439613035636563333366333336376335373263326534
36383866383766623937636461313130616166663536313361393736343230656239333230313338
31366535313239666535326432326431366435393335393239326535616161336437313563376462
36623061343537306231373366333564306165363931633434353563663931333331306538656362
63323038343139316638386137366562346439643466363933353435396632656432353636636463
65373135663337643262633630313261613065366237613638333430303864333733643964656338
39363835303966323561313237383034326330373463663738623530313666303763393731393432
3233
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 636f395

Please sign in to comment.