Skip to content

Commit

Permalink
Added lookup plugin integration test (ansible-collections#549)
Browse files Browse the repository at this point in the history
Added lookup plugin integration test

Reviewed-by: Polina Rabinovich
Reviewed-by: mikemorency
  • Loading branch information
anna-savina authored Nov 25, 2024
1 parent 1efb395 commit 7cc48d2
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ NC=\033[0m # No Color
prepare_symlinks:
ansible-playbook tools/prepare_symlinks.yml

.PHONY: install-ansible-collections
install-ansible-collections:
ansible-galaxy collection install --upgrade -r tests/integration/requirements.yml

.PHONY: remove_aliases
remove_aliases:
@find tests/integration/targets/ -name "aliases" -exec rm -f {} +

.PHONY: eco-vcenter-ci
eco-vcenter-ci: prepare_symlinks remove_aliases
eco-vcenter-ci: install-ansible-collections prepare_symlinks remove_aliases
@[ -f /tmp/vmware_rest_tests_report.txt ] && rm /tmp/vmware_rest_tests_report.txt || true; \
@failed=0; \
total=0; \
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collections:
- name: vmware.vmware
13 changes: 13 additions & 0 deletions tests/integration/targets/group_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# vcenter specific vars
# please edit according to your vcenter configs
vcenter_cluster_name: "Eco-Cluster"
vcenter_datacenter: "Eco-Datacenter"
vcenter_port: 443
rhel_9_3_iso_path: "[eco-nfs-datastore-iso] rhel-9.3-x86_64-dvd.iso"
vm_network_name: "VM Network"
test_network_name: "TestNetwork"
shared_storage_01: "eco-iscsi-ds1"
eco_nfs_datastore_iso: "eco-nfs-datastore-iso"
vcenter_vm_folder: "e2e-qe"
vcenter_resource_pool: "Resources"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
vcenter_datastore: "{{ shared_storage_01 }}"
test_cluster: "test-cluster"
14 changes: 14 additions & 0 deletions tests/integration/targets/vmware_rest_lookup_plugin/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- hosts: localhost
gather_facts: no

tasks:
- name: Import eco-vcenter credentials
ansible.builtin.include_vars:
file: ../../integration_config.yml
tags: eco-vcenter-ci

- name: Import vmware_rest_lookup_plugin test
ansible.builtin.import_role:
name: vmware_rest_lookup_plugin
tags:
- eco-vcenter-ci
46 changes: 46 additions & 0 deletions tests/integration/targets/vmware_rest_lookup_plugin/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- name: Test lookup plugin
block:
- name: Import common vars
ansible.builtin.include_vars:
file: ../group_vars.yml

- name: Create test cluster
vmware.vmware.cluster:
hostname: "{{ VMWARE_HOST }}"
username: "{{ VMWARE_USER }}"
password: "{{ VMWARE_PASSWORD }}"
validate_certs: "{{ VMWARE_VALIDATE_CERTS }}"
datacenter: "{{ vcenter_datacenter }}"
port: "{{ vcenter_port }}"
cluster_name: "{{ test_cluster }}"

- name: Get random host info
vmware.vmware_rest.vcenter_host_info:
hosts: "{{ lookup('vmware.vmware_rest.host_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/')[0] }}"
register: vcenter_host_info

- name: Set host name for tests
ansible.builtin.set_fact:
vcenter_host_name: "{{ vcenter_host_info.value[0].name }}"

- import_tasks: test_datacenter_moid.yml
- import_tasks: test_cluster_moid.yml
- import_tasks: test_host_moid.yml
- import_tasks: test_datastore_moid.yml
- import_tasks: test_folder_moid.yml
- import_tasks: test_network_moid.yml
- import_tasks: test_vm_moid.yml
- import_tasks: test_resource_pool_moid.yml

always:
- name: Destroy test cluster
vmware.vmware.cluster:
hostname: "{{ VMWARE_HOST }}"
username: "{{ VMWARE_USER }}"
password: "{{ VMWARE_PASSWORD }}"
validate_certs: "{{ VMWARE_VALIDATE_CERTS }}"
datacenter: "{{ vcenter_datacenter }}"
port: "{{ vcenter_port }}"
cluster_name: "{{ test_cluster }}"
state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: Verify number of clusters in datacenter
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/') | length > 1

- name: Lookup clusters in datacenter
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + item)
loop:
- ""
- "{{ vcenter_cluster_name }}"
- "{{ test_cluster }}"

- name: verify no inner clusters
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/') | length == 0

- name: Get specific cluster info
vmware.vmware_rest.vcenter_cluster_info:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name) }}"
register: cluster_info

- name: Verify cluster info
ansible.builtin.assert:
that: cluster_info.value.name == vcenter_cluster_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Get datacenter info
vmware.vmware_rest.vcenter_datacenter_info:
datacenter: "{{ lookup('vmware.vmware_rest.datacenter_moid', '/' + vcenter_datacenter) }}"
register: datacenter_info

- name: Verify datacenter info
ansible.builtin.assert:
that: datacenter_info.value.name == vcenter_datacenter
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- name: Verify number of datastores in datacenter
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/') | length > 1

- name: Lookup datastores in datacenter
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/' + item)
loop:
- ""
- "{{ vcenter_host_name }}/"
- "{{ vcenter_host_name }}/{{ shared_storage_01 }}"
- "{{ shared_storage_01 }}"
- "{{ eco_nfs_datastore_iso }}"

- name: Get specific datastore info
vmware.vmware_rest.vcenter_datastore_info:
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/' + shared_storage_01) }}"
register: datastore_info

- name: Verify datastore info
ansible.builtin.assert:
that: datastore_info.value.name == shared_storage_01
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: Lookup folders
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/' + item)
loop:
- vm/{{ vcenter_vm_folder }}
- "{{ vcenter_vm_folder }}"

- name: Verify number of folders
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/') | length > 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Lookup hosts
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.host_moid', '/' + vcenter_datacenter + '/' + item)
loop:
- ""
- "{{ vcenter_host_name }}"
- "{{ vcenter_cluster_name }}/"
- "{{ vcenter_cluster_name }}/{{ vcenter_host_name }}"

- name: Verify number of hosts in cluster
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.host_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/') | length > 1

- name: Verify no hosts in cluster
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.host_moid', '/' + vcenter_datacenter + '/' + test_cluster + '/') | length == 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- name: Lookup networks
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.network_moid', '/' + vcenter_datacenter + '/' + item)
loop:
- ""
- "{{ vm_network_name }}"

- name: Verify number of networks in datacenter
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.network_moid', '/' + vcenter_datacenter + '/') | length > 1

- name: Get specific network info
vmware.vmware_rest.vcenter_network_info:
networks: "{{ lookup('vmware.vmware_rest.network_moid', '/' + vcenter_datacenter + '/' + vm_network_name) }}"
register: network_info

- name: Verify network info
ansible.builtin.assert:
that: network_info.value[0].name == vm_network_name
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- name: Verify number of resource pools in a cluster
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/') | length > 1

- name: Verify that just 1 resource pool in a cluster
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + test_cluster + '/') | length == 1

- name: Verify no resource pool found
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + vcenter_resource_pool + '/') | length == 0

- name: Verify resource pool doesn't exist
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + "no_resource_pool") is none

- name: Lookup resource pools
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + item)
loop:
- ""
- "{{ vcenter_resource_pool }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- name: Get random VM's info
vmware.vmware_rest.vcenter_vm_info:
vm: "{{ lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/')[0] }}"
register: vm_info

- name: Lookup VMs
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + item)
loop:
- "{{ vcenter_host_name }}/"
- "{{ vm_info.value.identity.name }}"
- "{{ vcenter_resource_pool }}/"

- name: Verify number of VMs in a cluster
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/') | length > 1

- name: Verify no VMs in a cluster
ansible.builtin.assert:
that: lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + test_cluster + '/') | length == 0

0 comments on commit 7cc48d2

Please sign in to comment.