From b5c629b97729faf41b9825e7c259ac7477045893 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Thu, 5 Jan 2017 10:42:51 -0600 Subject: [PATCH] Update and clean up run_tests.sh The run_tests.sh script fails when it is run multiple times on CentOS. The `bindep` run returns an empty list of packages and then `yum` exits with an error since no packages were provided to install. This patch checks the length of the `bindep` output and skips the `yum` installation when the package list is empty. The patch also cleans up some of the old cruft left over from previous scripts and avoids repetition. Change-Id: I93ea2d53158eb736b8c6f89a0a70fb5507660126 Signed-off-by: Major Hayden --- run_tests.sh | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 482a3894..44b0404d 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -13,43 +13,53 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -euov +set -xeuo pipefail FUNCTIONAL_TEST=${FUNCTIONAL_TEST:-true} -# Install pip -if [ ! "$(which pip)" ]; then +# Install pip. +if ! which pip; then curl --silent --show-error --retry 5 \ https://bootstrap.pypa.io/get-pip.py | sudo python2.7 fi -# Install bindep and tox +# Install bindep and tox with pip. sudo pip install bindep tox # CentOS 7 requires two additional packages: # redhat-lsb-core - for bindep profile support # epel-release - required to install python-ndg_httpsclient/python2-pyasn1 -if [ "$(which yum)" ]; then +if which yum; then sudo yum -y install redhat-lsb-core epel-release fi -# Install OS packages using bindep -if apt-get -v >/dev/null 2>&1 ; then +# Get a list of packages to install with bindep. If packages need to be +# installed, bindep exits with an exit code of 1. +BINDEP_PKGS=$(bindep -b -f bindep.txt test || true) +echo "Packages to install: ${BINDEP_PKGS}" + +# Install a list of OS packages provided by bindep. +if which apt-get; then sudo apt-get update DEBIAN_FRONTEND=noninteractive \ sudo apt-get -q --option "Dpkg::Options::=--force-confold" \ - --assume-yes install `bindep -b -f bindep.txt test` -else - sudo yum install -y `bindep -b -f bindep.txt test` + --assume-yes install $BINDEP_PKGS +elif which yum; then + # Don't run yum with an empty list of packages. + # It will fail and cause the script to exit with an error. + if [[ ${#BINDEP_PKGS} > 0 ]]; then + sudo yum install -y $BINDEP_PKGS + fi fi -# run through each tox env and execute the test -for tox_env in $(awk -F= '/envlist/ {print $2}' tox.ini | sed 's/,/ /g'); do - if [ "${tox_env}" != "ansible-functional" ]; then - tox -e ${tox_env} - elif [ "${tox_env}" == "ansible-functional" ]; then +# Loop through each tox environment and run tests. +for tox_env in $(awk -F= '/envlist/ { gsub(",", " "); print $2 }' tox.ini); do + echo "Executing tox environment: ${tox_env}" + if [[ ${tox_env} == ansible-functional ]]; then if ${FUNCTIONAL_TEST}; then tox -e ${tox_env} fi + else + tox -e ${tox_env} fi done