From 89703b328490966db287700bb4bc3a422e96d98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Thu, 19 Dec 2019 11:25:37 -0500 Subject: [PATCH] vmware/test: more modular teardown.yml Some teardown tasks are now enabled only if we have ESXi in the configuration file. On my system and in a vcenter only scenario, `vcenter_folder` goes from 42.7 to 31.2s. --- .../tasks/init_real_lab.yml | 2 + .../prepare_vmware_tests/tasks/teardown.yml | 97 ------------------- .../tasks/teardown_with_esxi.yml | 96 ++++++++++++++++++ 3 files changed, 98 insertions(+), 97 deletions(-) create mode 100644 test/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml diff --git a/test/integration/targets/prepare_vmware_tests/tasks/init_real_lab.yml b/test/integration/targets/prepare_vmware_tests/tasks/init_real_lab.yml index 445005e18c7..9450084fd17 100644 --- a/test/integration/targets/prepare_vmware_tests/tasks/init_real_lab.yml +++ b/test/integration/targets/prepare_vmware_tests/tasks/init_real_lab.yml @@ -1,4 +1,6 @@ --- +- include_tasks: teardown_with_esxi.yml + when: esxi_hosts|length > 0 - include_tasks: teardown.yml - when: setup_esxi_instance is not defined diff --git a/test/integration/targets/prepare_vmware_tests/tasks/teardown.yml b/test/integration/targets/prepare_vmware_tests/tasks/teardown.yml index 9c9e52a2436..aba390592ee 100644 --- a/test/integration/targets/prepare_vmware_tests/tasks/teardown.yml +++ b/test/integration/targets/prepare_vmware_tests/tasks/teardown.yml @@ -1,101 +1,4 @@ --- - -- 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 - ignore_errors: yes - -- name: Remove the VM prepared by prepare_vmware_tests - vmware_guest: - name: "{{ item.name }}" - force: yes - state: absent - with_items: '{{ virtual_machines + virtual_machines_in_cluster }}' - -- name: Remove the test_vm* VMs - vmware_guest: - name: "{{ item }}" - force: yes - 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: yes - -- name: Remove the DVSwitch - vmware_dvswitch: - datacenter_name: '{{ dc1 }}' - state: absent - switch_name: '{{ item }}' - loop: - - '{{ dvswitch1 }}' - - dvswitch_0001 - - dvswitch_0002 - ignore_errors: yes - -- name: Remove the vSwitches - vmware_vswitch: - hostname: '{{ item }}' - username: '{{ esxi_user }}' - password: '{{ esxi_password }}' - switch_name: "{{ switch1 }}" - state: absent - with_items: "{{ esxi_hosts }}" - ignore_errors: yes - -- name: Remove ESXi Hosts to vCenter - vmware_host: - datacenter_name: '{{ dc1 }}' - cluster_name: ccr1 - esxi_hostname: '{{ item }}' - esxi_username: '{{ esxi_user }}' - esxi_password: '{{ esxi_password }}' - state: absent - with_items: "{{ esxi_hosts }}" - ignore_errors: yes - -- name: Umount NFS datastores to ESXi (1/2) - vmware_host_datastore: - hostname: '{{ item }}' - username: '{{ esxi_user }}' - password: '{{ esxi_password }}' - datastore_name: '{{ ro_datastore }}' - state: absent - with_items: "{{ esxi_hosts }}" - -- name: Umount NFS datastores to ESXi (2/2) - vmware_host_datastore: - hostname: '{{ item }}' - username: '{{ esxi_user }}' - password: '{{ esxi_password }}' - datastore_name: '{{ rw_datastore }}' - state: absent - with_items: "{{ esxi_hosts }}" - - name: Delete a datastore cluster to datacenter vmware_datastore_cluster: datacenter_name: "{{ dc1 }}" diff --git a/test/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml b/test/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml new file mode 100644 index 00000000000..2707847ef25 --- /dev/null +++ b/test/integration/targets/prepare_vmware_tests/tasks/teardown_with_esxi.yml @@ -0,0 +1,96 @@ +--- +- 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 + ignore_errors: yes + +- name: Remove the VM prepared by prepare_vmware_tests + vmware_guest: + name: "{{ item.name }}" + force: yes + state: absent + with_items: '{{ virtual_machines + virtual_machines_in_cluster }}' + +- name: Remove the test_vm* VMs + vmware_guest: + name: "{{ item }}" + force: yes + 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: yes + +- name: Remove the DVSwitch + vmware_dvswitch: + datacenter_name: '{{ dc1 }}' + state: absent + switch_name: '{{ item }}' + loop: + - '{{ dvswitch1 }}' + - dvswitch_0001 + - dvswitch_0002 + ignore_errors: yes + +- name: Remove the vSwitches + vmware_vswitch: + hostname: '{{ item }}' + username: '{{ esxi_user }}' + password: '{{ esxi_password }}' + switch_name: "{{ switch1 }}" + state: absent + with_items: "{{ esxi_hosts }}" + ignore_errors: yes + +- name: Remove ESXi Hosts to vCenter + vmware_host: + datacenter_name: '{{ dc1 }}' + cluster_name: ccr1 + esxi_hostname: '{{ item }}' + esxi_username: '{{ esxi_user }}' + esxi_password: '{{ esxi_password }}' + state: absent + with_items: "{{ esxi_hosts }}" + ignore_errors: yes + +- name: Umount NFS datastores to ESXi (1/2) + vmware_host_datastore: + hostname: '{{ item }}' + username: '{{ esxi_user }}' + password: '{{ esxi_password }}' + datastore_name: '{{ ro_datastore }}' + state: absent + with_items: "{{ esxi_hosts }}" + +- name: Umount NFS datastores to ESXi (2/2) + vmware_host_datastore: + hostname: '{{ item }}' + username: '{{ esxi_user }}' + password: '{{ esxi_password }}' + datastore_name: '{{ rw_datastore }}' + state: absent + with_items: "{{ esxi_hosts }}"