From 905acd7c9ebf151b19d3f48186ad758b93ec97a0 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sat, 22 Sep 2018 12:08:20 +0530 Subject: [PATCH] VMware: vmware_inventory contrib testing (#42879) * VMware: vmware_inventory contrib testing * Use python.py to run inventory script during test. Signed-off-by: Abhijeet Kasurde --- .../targets/vmware_inventory/aliases | 4 ++ .../targets/vmware_inventory/runme.sh | 62 +++++++++++++++++++ .../test_vmware_inventory.yml | 21 +++++++ .../vmware_inventory/vmware_inventory.sh | 3 + 4 files changed, 90 insertions(+) create mode 100644 test/integration/targets/vmware_inventory/aliases create mode 100755 test/integration/targets/vmware_inventory/runme.sh create mode 100644 test/integration/targets/vmware_inventory/test_vmware_inventory.yml create mode 100755 test/integration/targets/vmware_inventory/vmware_inventory.sh diff --git a/test/integration/targets/vmware_inventory/aliases b/test/integration/targets/vmware_inventory/aliases new file mode 100644 index 0000000000..98bb69376d --- /dev/null +++ b/test/integration/targets/vmware_inventory/aliases @@ -0,0 +1,4 @@ +shippable/vcenter/group1 +cloud/vcenter +skip/python3 +destructive diff --git a/test/integration/targets/vmware_inventory/runme.sh b/test/integration/targets/vmware_inventory/runme.sh new file mode 100755 index 0000000000..ce43650c72 --- /dev/null +++ b/test/integration/targets/vmware_inventory/runme.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x + +set -euo pipefail + +# Get Current test directory +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +contrib_dir=$(pwd)/../../../../contrib/inventory + +echo "DEBUG: using ${contrib_dir}" + +export ANSIBLE_CONFIG=ansible.cfg +export vcenter_host="${vcenter_host:-0.0.0.0}" +export VMWARE_SERVER="${vcenter_host}" +export VMWARE_USERNAME="${VMWARE_USERNAME:-user}" +export VMWARE_PASSWORD="${VMWARE_PASSWORD:-pass}" + +VMWARE_CONFIG=${contrib_dir}/vmware_inventory.ini + + +trap cleanup INT TERM EXIT + +# Remove default inventory config file +if [ -f "${VMWARE_CONFIG}" ]; +then + echo "DEBUG: Creating backup of ${VMWARE_CONFIG}" + cp "${VMWARE_CONFIG}" "${VMWARE_CONFIG}.bk" +fi + +cat > "${VMWARE_CONFIG}" < /dev/null 2>&1 + +echo "Start new VCSIM server" +curl "http://${vcenter_host}:5000/spawn?datacenter=1&cluster=1&folder=0" > /dev/null 2>&1 + +echo "Debugging new instances" +curl "http://${vcenter_host}:5000/govc_find" + +# Get inventory +ansible-playbook -i ./vmware_inventory.sh "${DIR}/test_vmware_inventory.yml" --connection=local "$@" + +echo "DEBUG: Done" diff --git a/test/integration/targets/vmware_inventory/test_vmware_inventory.yml b/test/integration/targets/vmware_inventory/test_vmware_inventory.yml new file mode 100644 index 0000000000..9cd8ff8917 --- /dev/null +++ b/test/integration/targets/vmware_inventory/test_vmware_inventory.yml @@ -0,0 +1,21 @@ +# Test code for the vmware guest contrib inventory +# Copyright: (c) 2018, Abhijeet Kasurde +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +--- +- name: Test VMware guest contrib inventroy script + hosts: localhost + tasks: + - name: store the vcenter container ip + set_fact: + vcsim: "{{ lookup('env', 'vcenter_host') }}" + + - debug: + var: vcsim + + - name: Check that groups present in inventory + assert: + that: + - "'{{item}}' in groups" + with_items: + - all diff --git a/test/integration/targets/vmware_inventory/vmware_inventory.sh b/test/integration/targets/vmware_inventory/vmware_inventory.sh new file mode 100755 index 0000000000..5ec1972e3f --- /dev/null +++ b/test/integration/targets/vmware_inventory/vmware_inventory.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +python.py "../../../../contrib/inventory/vmware_inventory.py" "$@"