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: I0ce6a639931371bc714fb91c1afdc0d964d690ec
Signed-off-by: Major Hayden <major@mhtx.net>
This commit is contained in:
Major Hayden 2017-01-05 10:41:01 -06:00
parent a51f1ba6a1
commit 250c03c03d

View File

@ -13,43 +13,53 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -euov set -xeuo pipefail
FUNCTIONAL_TEST=${FUNCTIONAL_TEST:-true} FUNCTIONAL_TEST=${FUNCTIONAL_TEST:-true}
# Install pip # Install pip.
if [ ! "$(which pip)" ]; then if ! which pip; then
curl --silent --show-error --retry 5 \ curl --silent --show-error --retry 5 \
https://bootstrap.pypa.io/get-pip.py | sudo python2.7 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
fi fi
# Install bindep and tox # Install bindep and tox with pip.
sudo pip install bindep tox sudo pip install bindep tox
# CentOS 7 requires two additional packages: # CentOS 7 requires two additional packages:
# redhat-lsb-core - for bindep profile support # redhat-lsb-core - for bindep profile support
# epel-release - required to install python-ndg_httpsclient/python2-pyasn1 # 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 sudo yum -y install redhat-lsb-core epel-release
fi fi
# Install OS packages using bindep # Get a list of packages to install with bindep. If packages need to be
if apt-get -v >/dev/null 2>&1 ; then # 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 sudo apt-get update
DEBIAN_FRONTEND=noninteractive \ DEBIAN_FRONTEND=noninteractive \
sudo apt-get -q --option "Dpkg::Options::=--force-confold" \ sudo apt-get -q --option "Dpkg::Options::=--force-confold" \
--assume-yes install `bindep -b -f bindep.txt test` --assume-yes install $BINDEP_PKGS
else elif which yum; then
sudo yum install -y `bindep -b -f bindep.txt test` # 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 fi
# run through each tox env and execute the test # Loop through each tox environment and run tests.
for tox_env in $(awk -F= '/envlist/ {print $2}' tox.ini | sed 's/,/ /g'); do for tox_env in $(awk -F= '/envlist/ { gsub(",", " "); print $2 }' tox.ini); do
if [ "${tox_env}" != "ansible-functional" ]; then echo "Executing tox environment: ${tox_env}"
tox -e ${tox_env} if [[ ${tox_env} == ansible-functional ]]; then
elif [ "${tox_env}" == "ansible-functional" ]; then
if ${FUNCTIONAL_TEST}; then if ${FUNCTIONAL_TEST}; then
tox -e ${tox_env} tox -e ${tox_env}
fi fi
else
tox -e ${tox_env}
fi fi
done done