diff --git a/tests/integration/targets/vm_list_group_by_clusters_info/defaults/main.yml b/tests/integration/targets/vm_list_group_by_clusters_info/defaults/main.yml new file mode 100644 index 00000000..9e4b8b84 --- /dev/null +++ b/tests/integration/targets/vm_list_group_by_clusters_info/defaults/main.yml @@ -0,0 +1,18 @@ +vcenter_port: 443 +run_on_simulator: false + +test_folder: test-vm_list_group_by_cluster_info + +vm_name: eco-vm-test +vm_cluster: "Eco-Cluster" +vm_datacenter: "Eco-Datacenter" +vm_folder: "/Eco-Datacenter/vm/{{ test_folder }}" +vm_guest_id: "rhel8_64Guest" +vm_disk: + - size_gb: 10 + type: thin + autoselect_datastore: true +vm_hardware: + memory_mb: 2000 + num_cpus: 2 + boot_firmware: efi diff --git a/tests/integration/targets/vm_list_group_by_clusters_info/tasks/main.yml b/tests/integration/targets/vm_list_group_by_clusters_info/tasks/main.yml index 7747ff11..0b5eda2f 100644 --- a/tests/integration/targets/vm_list_group_by_clusters_info/tasks/main.yml +++ b/tests/integration/targets/vm_list_group_by_clusters_info/tasks/main.yml @@ -1,18 +1,83 @@ --- -- name: VM list group by clusters and folders - vmware.vmware.vm_list_group_by_clusters_info: - validate_certs: false - hostname: "{{ vcenter_hostname }}" - username: "{{ vcenter_username }}" - password: "{{ vcenter_password }}" - detailed_vms: false - port: "{{ vcenter_port }}" - register: __res +- block: + - name: "Test setup: Create VM folder {{ test_folder }}" + community.vmware.vcenter_folder: + validate_certs: false + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + datacenter: "{{ vm_datacenter }}" + folder_name: "{{ test_folder }}" + folder_type: vm + state: present + when: not run_on_simulator -- name: Assert values - ansible.builtin.assert: - that: - - __res.changed == False - - __res.vm_list_group_by_clusters_info | length == 1 - - __res.vm_list_group_by_clusters_info['cluster1'] | length == 1 - - __res.vm_list_group_by_clusters_info['cluster1']['folder1'] | length == 1 + - name: "Test setup: Create VM guest {{ vm_name }}" + community.vmware.vmware_guest: + validate_certs: false + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + cluster: "{{ vm_cluster }}" + datacenter: "{{ vm_datacenter }}" + folder: "{{ vm_folder }}" + state: present + name: "{{ vm_name }}" + disk: "{{ vm_disk }}" + guest_id: "{{ vm_guest_id }}" + hardware: "{{ vm_hardware }}" + when: not run_on_simulator + + - name: VM list group by clusters and folders + vmware.vmware.vm_list_group_by_clusters_info: + validate_certs: false + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + detailed_vms: false + port: "{{ vcenter_port }}" + register: __res + + - name: Assert values + ansible.builtin.assert: + that: + - __res.changed == False + - __res.vm_list_group_by_clusters_info | length == 1 + - __res.vm_list_group_by_clusters_info['cluster1'] | length == 1 + - __res.vm_list_group_by_clusters_info['cluster1']['folder1'] | length == 1 + when: run_on_simulator + + - name: Assert values + ansible.builtin.assert: + that: + - __res.changed == False + - __res.vm_list_group_by_clusters_info[vm_cluster][test_folder] | length == 1 + - __res.vm_list_group_by_clusters_info[vm_cluster][test_folder][0]['name'] == vm_name + when: not run_on_simulator + + always: + - name: "Test teardown: Destroy VM guest {{ vm_name }}" + community.vmware.vmware_guest: + validate_certs: false + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + cluster: "{{ vm_cluster }}" + datacenter: "{{ vm_datacenter }}" + folder: "{{ vm_folder }}" + state: absent + force: true + name: "{{ vm_name }}" + when: not run_on_simulator + + - name: "Test teardown: Remove VM folder {{ test_folder }}" + community.vmware.vcenter_folder: + validate_certs: false + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + datacenter: "{{ vm_datacenter }}" + folder_name: "{{ test_folder }}" + folder_type: vm + state: absent + when: not run_on_simulator diff --git a/tests/integration/targets/vm_list_group_by_clusters_info/vars.yml b/tests/integration/targets/vm_list_group_by_clusters_info/vars.yml index af304fae..d61d43bb 100644 --- a/tests/integration/targets/vm_list_group_by_clusters_info/vars.yml +++ b/tests/integration/targets/vm_list_group_by_clusters_info/vars.yml @@ -3,4 +3,5 @@ vcenter_username: "user" vcenter_password: "pass" vcenter_port: 1080 +run_on_simulator: true mock_file: "vm_list_group_by_clusters_info"