-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SUMMARY Including a playbook that can be used to test the lookup plugins. Its designed to be run manually and needs inputs from a specific environment. Once automated testing is set up, this test can be modified to require less inputs from the user Also included a bugfix which was found while testing. Lookng up the contents of a datacenter would raise an exception instead of returning the correct results ISSUE TYPE Bugfix Pull Request COMPONENT NAME Lookup plugins Reviewed-by: Anna Savina Reviewed-by: Danielle Barda
- Loading branch information
1 parent
1887490
commit fab0aff
Showing
10 changed files
with
158 additions
and
15 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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
trivial: | ||
- tests - added manual test playbook for lookup plugins | ||
|
||
bugfixes: | ||
- lookup - fixed issue where searching for datacenter contents would throw an exception instead of returning expected results |
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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2155,SC2086 | ||
|
||
export DEFAULT_COLLECTIONS_PATH="$ANSIBLE_COLLECTIONS_PATH/ansible_collections" | ||
|
||
# Check if the variable is already set (e.g., in CI) | ||
if [ -z "$ANSIBLE_COLLECTIONS_PATH" ]; then | ||
# If not, use base collections path | ||
ANSIBLE_COLLECTIONS_PATH="$DEFAULT_COLLECTIONS_PATH" | ||
fi | ||
|
||
echo "ANSIBLE_COLLECTIONS_PATH: $ANSIBLE_COLLECTIONS_PATH" | ||
BASE_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") | ||
export ANSIBLE_ROLES_PATH=${BASE_DIR} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This test is temporary until automated testing can be put in place. | ||
|
||
To run: | ||
|
||
1. Create a `vars.yml` in this directory with variables specific to your environment. Possible variables to set can be found in `vmware_lookup/defaults/main.yml`, plus `vcenter_hostname`, `vcenter_username`, `vcenter_password`. Alternatively, you can set the authentication variables as env vars. For example, `VCENTER_HOSTNAME`, `VCENTER_USERNAME`, `VCENTER_PASSWORD` | ||
2. Run `./runme.sh` |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
vcenter_cluster: MyCluster | ||
vcenter_datacenter: MyDatacenter | ||
vcenter_resource_pool: MyResourcePool | ||
vcenter_esxi_host: MyESXiHost | ||
vcenter_vm: MyVM | ||
vcenter_datastore: MyDatastore | ||
vcenter_vm_folder: MyVmFolder | ||
vcenter_nested_network: MyNetworkFolder/MyNetwork | ||
|
||
connection_args: | ||
vcenter_hostname: "{{ vcenter_hostname | default(lookup('ansible.builtin.env', 'VCENTER_HOSTNAME')) }}" | ||
vcenter_username: "{{ vcenter_username | default(lookup('ansible.builtin.env', 'VCENTER_USERNAME')) }}" | ||
vcenter_password: "{{ vcenter_password | default(lookup('ansible.builtin.env', 'VCENTER_PASSWORD')) }}" | ||
vcenter_validate_certs: false |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
- hosts: localhost | ||
gather_facts: no | ||
|
||
tasks: | ||
- name: Import Custom Vars If Found | ||
ansible.builtin.include_vars: | ||
file: "{{ playbook_dir }}/vars.yml" | ||
failed_when: false | ||
tags: | ||
- eco-vcenter-ci | ||
|
||
- name: Import vmware_lookup role | ||
ansible.builtin.import_role: | ||
name: vmware_lookup | ||
tags: | ||
- eco-vcenter-ci |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
source ../init.sh | ||
|
||
# Generates a string starting with 'test-' followed by 4 random lowercase characters | ||
TINY_PREFIX="test-$(uuidgen | tr -d '-' | cut -c1-4 | tr '[:upper:]' '[:lower:]')" | ||
|
||
# Extract the ansible_tags from integration_config.yml | ||
# ANSIBLE_TAGS=$(awk '/ansible_tags/ {print $2}' ../../integration_config.yml) | ||
ANSIBLE_TAGS="eco-vcenter-ci" | ||
|
||
# Check if the ANSIBLE_TAGS variable is set | ||
if [[ -n "$ANSIBLE_TAGS" ]]; then | ||
echo "ANSIBLE_TAGS is set to: $ANSIBLE_TAGS" | ||
exec ansible-playbook run.yml --tags "$ANSIBLE_TAGS" --extra-vars "tiny_prefix=$TINY_PREFIX" | ||
else | ||
echo "ANSIBLE_TAGS is not set for Eco vCenter. Running on simulator." | ||
exec ansible-playbook run.yml --tags integration-ci | ||
fi |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
- name: Lookup Datacenter | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.datacenter_moid', '/' + vcenter_datacenter, **connection_args) | ||
|
||
- name: Lookup Clusters In Datacenter | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/', **connection_args) | ||
|
||
- name: Lookup Datastores In Datacenter | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/', **connection_args) | ||
|
||
- name: Lookup Cluster | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster, **connection_args) | ||
|
||
- name: Lookup Datastores | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/' + item, **connection_args) | ||
loop: | ||
- "{{ vcenter_datastore }}" | ||
- "{{ vcenter_esxi_host }}/{{ vcenter_datastore }}" | ||
- "{{ vcenter_esxi_host }}/" | ||
|
||
- name: Lookup Folders | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/' + item, **connection_args) | ||
loop: | ||
- vm/{{ vcenter_vm_folder }} | ||
- "{{ vcenter_vm_folder }}" | ||
|
||
- name: Lookup Networks | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.network_moid', '/' + vcenter_datacenter + '/' + item, **connection_args) | ||
loop: | ||
- Management Network | ||
- vMotion | ||
- "{{ vcenter_nested_network | dirname }}/" | ||
- "{{ vcenter_nested_network }}" | ||
|
||
- name: Lookup Hosts | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.host_moid', '/' + vcenter_datacenter + '/' + item, **connection_args) | ||
loop: | ||
- "{{ vcenter_esxi_host }}" | ||
- "{{ vcenter_cluster }}/" | ||
- "{{ vcenter_cluster }}/{{ vcenter_esxi_host }}" | ||
|
||
- name: Lookup VMs | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + item, **connection_args) | ||
loop: | ||
- "{{ vcenter_esxi_host }}/" | ||
- vCLS/ | ||
- "{{ vcenter_vm }}" | ||
- "{{ vcenter_resource_pool }}/" | ||
|
||
- name: Lookup Resource Pools | ||
ansible.builtin.assert: | ||
that: lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + item, **connection_args) | ||
loop: | ||
- "{{ vcenter_resource_pool }}" | ||
- "{{ vcenter_resource_pool }}/" | ||
- "{{ vcenter_cluster }}/" |