forked from ansible-collections/community.vmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: use vmware.vmware_rest to clean up the resources (ansible-coll…
…ections#1125) tests: use vmware.vmware_rest to clean up the resources Depends-On: ansible/ansible-zuul-jobs#1215 vmware.vmware_rest allow uses to simplify the clean up of the resources and avoid any leaked VM. Also: test VMs use lighter disk size. do not umount the datastore during the teardown. Reviewed-by: None <None>
- Loading branch information
Showing
12 changed files
with
244 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pytest-xdist | |
# We should avoid these two modules with py3 | ||
pytest-mock | ||
mock | ||
aiohttp ; python_version >= '3.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 23 additions & 19 deletions
42
tests/integration/targets/prepare_vmware_tests/tasks/teardown.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 81 additions & 98 deletions
179
tests/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,94 @@ | ||
--- | ||
- name: Clean up the firewall rules | ||
vmware_host_firewall_manager: | ||
cluster_name: '{{ ccr1 }}' | ||
rules: | ||
- name: vvold | ||
enabled: false | ||
- name: CIMHttpServer | ||
enabled: true | ||
allowed_hosts: | ||
all_ip: true | ||
- name: NFC | ||
enabled: true | ||
allowed_hosts: | ||
all_ip: true | ||
- name: Collect the list of the existing VM | ||
vmware.vmware_rest.vcenter_vm_info: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
register: existing_vms | ||
until: existing_vms is not failed | ||
|
||
- name: Turn off the VM | ||
vmware.vmware_rest.vcenter_vm_power: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
state: stop | ||
vm: '{{ item.vm }}' | ||
with_items: "{{ existing_vms.value }}" | ||
ignore_errors: true | ||
|
||
- name: Remove the VM prepared by prepare_vmware_tests | ||
vmware_guest: | ||
name: "{{ item.name }}" | ||
force: true | ||
- name: Delete the VMs | ||
vmware.vmware_rest.vcenter_vm: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
state: absent | ||
with_items: '{{ virtual_machines + virtual_machines_in_cluster }}' | ||
vm: '{{ item.vm }}' | ||
with_items: "{{ existing_vms.value }}" | ||
when: | ||
- not item.name.startswith("vCLS") | ||
|
||
- name: Remove the test_vm* VMs | ||
vmware_guest: | ||
name: "{{ item }}" | ||
force: true | ||
state: absent | ||
with_items: | ||
- test_vm1 | ||
- test_vm2 | ||
- test_vm3 | ||
|
||
- name: Remove the DVS portgroups | ||
vmware_dvs_portgroup: | ||
switch_name: "{{ dvswitch1 }}" | ||
portgroup_name: '{{ item }}' | ||
vlan_id: 0 | ||
num_ports: 32 | ||
portgroup_type: earlyBinding | ||
state: absent | ||
loop: | ||
- DC0_DVPG0 | ||
- DVPG/1 | ||
ignore_errors: true | ||
- name: Build a list of local libraries | ||
vmware.vmware_rest.content_locallibrary_info: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
register: result | ||
retries: 100 | ||
delay: 3 | ||
until: result is not failed | ||
|
||
- name: Remove the DVSwitch | ||
vmware_dvswitch: | ||
datacenter_name: '{{ dc1 }}' | ||
- name: Delete all the local libraries | ||
vmware.vmware_rest.content_locallibrary: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
library_id: "{{ item.id }}" | ||
state: absent | ||
switch_name: '{{ item }}' | ||
loop: | ||
- '{{ dvswitch1 }}' | ||
- dvswitch_0001 | ||
- dvswitch_0002 | ||
ignore_errors: true | ||
with_items: "{{ result.value }}" | ||
|
||
- name: Clean up the VM Network portgroup | ||
vmware_portgroup: | ||
esxi_hostname: '{{ esxi_hosts }}' | ||
switch: isolated_vSwitch | ||
portgroup: VM Network | ||
state: absent | ||
ignore_errors: true | ||
with_items: | ||
- isolated_vSwitch | ||
- vSwitch0 | ||
- name: Build a list of subscribed libraries | ||
vmware.vmware_rest.content_subscribedlibrary_info: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
register: result | ||
|
||
- name: Remove the vSwitches | ||
vmware_vswitch: | ||
hostname: '{{ item }}' | ||
username: '{{ esxi_user }}' | ||
password: '{{ esxi_password }}' | ||
switch_name: "{{ switch1 }}" | ||
- name: Delete all the subscribed libraries | ||
vmware.vmware_rest.content_subscribedlibrary: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
library_id: "{{ item.id }}" | ||
state: absent | ||
with_items: "{{ esxi_hosts }}" | ||
ignore_errors: true | ||
|
||
- include_tasks: move_host_out_of_cluster.yml | ||
|
||
- name: Umount NFS datastores from ESXi (1/2) | ||
vmware_host_datastore: | ||
hostname: '{{ item }}' | ||
username: '{{ esxi_user }}' | ||
password: '{{ esxi_password }}' | ||
datastore_name: '{{ ro_datastore }}' | ||
state: absent | ||
with_items: "{{ esxi_hosts }}" | ||
ignore_errors: true | ||
with_items: "{{ result.value }}" | ||
|
||
- name: Umount NFS datastores from ESXi (2/2) | ||
vmware_host_datastore: | ||
hostname: '{{ item }}' | ||
username: '{{ esxi_user }}' | ||
password: '{{ esxi_password }}' | ||
datastore_name: '{{ rw_datastore }}' | ||
state: absent | ||
with_items: "{{ esxi_hosts }}" | ||
ignore_errors: true | ||
|
||
- name: Remove ESXi Hosts from vCenter | ||
vmware_host: | ||
datacenter_name: '{{ dc1 }}' | ||
cluster_name: '{{ ccr1 }}' | ||
esxi_hostname: '{{ item }}' | ||
esxi_username: '{{ esxi_user }}' | ||
esxi_password: '{{ esxi_password }}' | ||
- name: Get a list of all the datacenters | ||
vmware.vmware_rest.vcenter_datacenter_info: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
register: existing_datacenters | ||
- name: Force delete the existing DC | ||
vmware.vmware_rest.vcenter_datacenter: | ||
vcenter_hostname: '{{ vcenter_hostname }}' | ||
vcenter_username: '{{ vcenter_username }}' | ||
vcenter_password: '{{ vcenter_password }}' | ||
vcenter_validate_certs: false | ||
state: absent | ||
with_items: "{{ esxi_hosts }}" | ||
ignore_errors: true | ||
datacenter: '{{ item.datacenter }}' | ||
force: true | ||
with_items: "{{ existing_datacenters.value }}" | ||
until: _result is succeeded | ||
retries: 10 | ||
delay: 1 | ||
register: _result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,28 @@ | |
# Copyright: (c) 2018, Abhijeet Kasurde <[email protected]> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
- name: Create VMs | ||
vmware_guest: | ||
datacenter: "{{ dc1 }}" | ||
folder: '{{ f0 }}' | ||
name: DC0_H0_VM0 | ||
state: poweredoff | ||
guest_id: debian8_64Guest | ||
disk: | ||
- size_mb: 10 | ||
type: thin | ||
datastore: '{{ rw_datastore }}' | ||
hardware: | ||
memory_mb: 128 | ||
num_cpus: 1 | ||
scsi: paravirtual | ||
version: 11 | ||
cdrom: | ||
type: iso | ||
iso_path: "[{{ ro_datastore }}] fedora.iso" | ||
networks: | ||
- name: VM Network | ||
|
||
- name: Perform all operation in check mode | ||
vmware_guest: | ||
validate_certs: false | ||
|
@@ -27,9 +49,6 @@ | |
register: check_mode_state | ||
check_mode: true | ||
|
||
- debug: | ||
var: check_mode_state | ||
|
||
- name: assert that changes were made | ||
assert: | ||
that: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,39 @@ | |
# Copyright: (c) 2019, Pavan Bidkar <[email protected]> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
- name: Create VMs | ||
vmware_guest: | ||
datacenter: "{{ dc1 }}" | ||
folder: '{{ f0 }}' | ||
name: DC0_H0_VM0 | ||
state: poweredoff | ||
guest_id: debian8_64Guest | ||
disk: | ||
- size_mb: 10 | ||
type: thin | ||
datastore: '{{ rw_datastore }}' | ||
hardware: | ||
memory_mb: 128 | ||
num_cpus: 1 | ||
scsi: paravirtual | ||
version: 11 | ||
cdrom: | ||
type: iso | ||
iso_path: "[{{ ro_datastore }}] fedora.iso" | ||
networks: | ||
- name: VM Network | ||
|
||
- name: clone vm from template and customize GOS | ||
vmware_guest: | ||
validate_certs: false | ||
hostname: "{{ vcenter_hostname }}" | ||
username: "{{ vcenter_username }}" | ||
password: "{{ vcenter_password }}" | ||
name: test_vm1 | ||
template: "{{ virtual_machines[0].name }}" | ||
template: DC0_H0_VM0 | ||
datacenter: "{{ dc1 }}" | ||
state: poweredoff | ||
folder: "{{ virtual_machines[0].folder }}" | ||
folder: "{{ f0 }}" | ||
convert: thin | ||
register: clone_customize | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,39 @@ | |
# Copyright: (c) 2018, Christophe FERREIRA <[email protected]> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
- name: Create VMs | ||
vmware_guest: | ||
datacenter: "{{ dc1 }}" | ||
folder: '{{ f0 }}' | ||
name: DC0_H0_VM0 | ||
state: poweredoff | ||
guest_id: debian8_64Guest | ||
disk: | ||
- size_mb: 10 | ||
type: thin | ||
datastore: '{{ rw_datastore }}' | ||
hardware: | ||
memory_mb: 128 | ||
num_cpus: 1 | ||
scsi: paravirtual | ||
version: 11 | ||
cdrom: | ||
type: iso | ||
iso_path: "[{{ ro_datastore }}] fedora.iso" | ||
networks: | ||
- name: VM Network | ||
|
||
- name: clone vm from template and convert to thin | ||
vmware_guest: | ||
validate_certs: false | ||
hostname: "{{ vcenter_hostname }}" | ||
username: "{{ vcenter_username }}" | ||
password: "{{ vcenter_password }}" | ||
name: test_vm1 | ||
template: "{{ virtual_machines[0].name }}" | ||
template: DC0_H0_VM0 | ||
datacenter: "{{ dc1 }}" | ||
state: poweredoff | ||
folder: "{{ virtual_machines[0].folder }}" | ||
folder: "{{ f0 }}" | ||
convert: thin | ||
register: clone_thin | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.