From 9d7229f65b9862e27c58490921b04d7d4c388e02 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Fri, 20 Nov 2015 10:10:43 -0500 Subject: [PATCH] Allow specifying cloud name to ansible tests It would be *really* cool and useful and stuff to be able to run the Ansible playbooks against more than just devstack. This change allows that. Now you can send the -c option to the tox command line: tox -e ansible -- -c coolcloud Or, specific tests: tox -e ansible -- -c coolcloud auth network Going against devstack is still: tox -e ansible tox -e ansible auth network Change-Id: I666a09aee3d283865c3813d67edfb75123057c22 --- extras/run-ansible-tests.sh | 50 +++++++++++++++++++++++++++---------- tox.ini | 2 +- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/extras/run-ansible-tests.sh b/extras/run-ansible-tests.sh index 7797cc349..816eb53fe 100755 --- a/extras/run-ansible-tests.sh +++ b/extras/run-ansible-tests.sh @@ -5,27 +5,50 @@ # Script used to setup a tox environment for running Ansible. This is meant # to be called by tox (via tox.ini). To run the Ansible tests, use: # -# tox -e ansible [TAG] +# tox -e ansible [TAG ...] +# or +# tox -e ansible -- -c cloudX [TAG ...] # # USAGE: -# run-ansible-tests.sh [TAG] +# run-ansible-tests.sh -e ENVDIR [-c CLOUD] [TAG ...] # # PARAMETERS: -# Directory of the tox environment to use for testing. -# [TAG] Optional list of space-separated tags to control which -# modules are tested. +# -e ENVDIR Directory of the tox environment to use for testing. +# -c CLOUD Name of the cloud to use for testing. +# Defaults to "devstack-admin". +# [TAG ...] Optional list of space-separated tags to control which +# modules are tested. # # EXAMPLES: # # Run all Ansible tests -# run-ansible-tests.sh ansible +# run-ansible-tests.sh -e ansible # -# # Run auth, keypair, and network tests -# run-ansible-tests.sh ansible auth keypair network +# # Run auth, keypair, and network tests against cloudX +# run-ansible-tests.sh -e ansible -c cloudX auth keypair network ############################################################################# -ENVDIR=$1 -shift -TAGS=$( echo "$@" | tr ' ' , ) + +CLOUD="devstack-admin" +ENVDIR= + +while getopts "c:e:" opt +do + case $opt in + c) CLOUD=${OPTARG} ;; + e) ENVDIR=${OPTARG} ;; + ?) echo "Invalid option: -${OPTARG}" + exit 1;; + esac +done + +if [ -z ${ENVDIR} ] +then + echo "Option -e is required" + exit 1 +fi + +shift $((OPTIND-1)) +TAGS=$( echo "$*" | tr ' ' , ) if [ -d ${ENVDIR}/ansible ] then @@ -44,8 +67,9 @@ source $ENVDIR/ansible/hacking/env-setup # Run the shade Ansible tests tag_opt="" -if [ "${TAGS}" != "" ] +if [ ! -z ${TAGS} ] then tag_opt="--tags ${TAGS}" fi -ansible-playbook -vvv ./shade/tests/ansible/run.yml -e "cloud=devstack-admin" ${tag_opt} + +ansible-playbook -vvv ./shade/tests/ansible/run.yml -e "cloud=${CLOUD}" ${tag_opt} diff --git a/tox.ini b/tox.ini index 586ede98a..2ca4fefd5 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' [testenv:ansible] # Need to pass some env vars for the Ansible playbooks passenv = HOME USER -commands = {toxinidir}/extras/run-ansible-tests.sh {envdir} {posargs} +commands = {toxinidir}/extras/run-ansible-tests.sh -e {envdir} {posargs} [flake8] # Infra does not follow hacking, nor the broken E12* things