From 4b05c201db7126a8fda9bb4d796eea257e8816c2 Mon Sep 17 00:00:00 2001 From: Jiri Kucera Date: Fri, 31 Jan 2020 12:30:38 +0100 Subject: [PATCH] Support more Ansible versions Support running the molecule tests against more versions of Ansible. By typing LSR_ANSIBLE_DEP= LSR_MSCENARIO= tox -e molecule one can run molecule inside tox with version installed under scenario. For example LSR_ANSIBLE_DEP='ansible==2.7.*' LSR_MSCENARIO=foo tox -e molecule will run molecule under scenario 'foo' and the recent Ansible 2.7 installed. `tox -e molecule` run molecule under default scenario with the latest Ansible (from pypi) installed. Travis runs molecule tests for Ansible 2.6, 2.7, and 2.8 installed and under default scenario (can be overriden by user in config.sh). Additional changes: Remove useless comment from custom.sh. --- .travis.yml | 4 ++++ .travis/config.sh | 5 +++++ .travis/custom.sh | 1 - .travis/runtox | 45 +++++++++++++++++++++++++++++++++++++-------- tox.ini | 3 ++- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f9c4f7..45547d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ --- dist: xenial language: python +env: + global: + - LSR_ANSIBLES='ansible==2.6.* ansible==2.7.* ansible==2.8.*' + - LSR_MSCENARIOS='default' matrix: include: - python: 2.6 diff --git a/.travis/config.sh b/.travis/config.sh index 716397b..dc24337 100644 --- a/.travis/config.sh +++ b/.travis/config.sh @@ -7,6 +7,11 @@ # # - LSR_EXTRA_PACKAGES # +# * .travis/runtox: +# +# - LSR_ANSIBLES +# - LSR_MSCENARIOS +# # Environment variables that not start with LSR_* but have influence on CI # process: # diff --git a/.travis/custom.sh b/.travis/custom.sh index 115fc85..3c9cb78 100755 --- a/.travis/custom.sh +++ b/.travis/custom.sh @@ -13,7 +13,6 @@ ME=$(basename $0) SCRIPTDIR=$(readlink -f $(dirname $0)) TOPDIR=$(readlink -f ${SCRIPTDIR}/..) -# Include library and config: . ${SCRIPTDIR}/utils.sh . ${SCRIPTDIR}/config.sh diff --git a/.travis/runtox b/.travis/runtox index 1b1ec79..f017482 100755 --- a/.travis/runtox +++ b/.travis/runtox @@ -1,16 +1,45 @@ #!/bin/bash # SPDX-License-Identifier: MIT -set -ex +# Run tox. Additionally, if LSR_MSCENARIOS is defined, run `tox -e molecule` +# for every scenario from LSR_MSCENARIOS and for every Ansible version from +# LSR_ANSIBLES. +# +# LSR_MSCENARIOS is a space separated list of molecule scenarios. +# LSR_ANSIBLES is a space separated list of Ansible package names with versions +# in pip format, i.e 'ansible ansible==2.6 ansible==2.7 ansible=2.8'. +# +# LSR_MSCENARIOS and LSR_ANSIBLES can be set in .travis/config.sh or as +# environment variables. -SCRIPTDIR=$(dirname $0) -CONFIG=${SCRIPTDIR}/config.sh +ME=$(basename $0) +SCRIPTDIR=$(readlink -f $(dirname $0)) +BANNERSIZE=90 -if [[ -f ${CONFIG} ]]; then - . ${CONFIG} +. ${SCRIPTDIR}/utils.sh +. ${SCRIPTDIR}/config.sh + +lsr_banner "tox" ${BANNERSIZE} +(set -x; tox); error_code=$? + +# Exit prematurely if the environment is not suitable for running +# Molecule tests. +if ! lsr_venv_python_matches_system_python; then + exit $error_code fi -tox "$@" -for X in ${LSR_MSCENARIOS}; do - LSR_MSCENARIO=${X} tox -e molecule +for ansible_dependency in ${LSR_ANSIBLES}; do + for molecule_scenario in ${LSR_MSCENARIOS}; do + lsr_banner \ + "[${ansible_dependency}] tox -e molecule -- -s ${molecule_scenario}" \ + ${BANNERSIZE} + ( + set -x + LSR_ANSIBLE_DEP="${ansible_dependency}" \ + LSR_MSCENARIO=${molecule_scenario} \ + tox -e molecule + ) || error_code=$? + done done + +exit $error_code diff --git a/tox.ini b/tox.ini index b50ce40..23eedb5 100644 --- a/tox.ini +++ b/tox.ini @@ -174,6 +174,7 @@ commands = [molecule_common] deps = + {env:LSR_ANSIBLE_DEP:ansible} docker molecule selinux @@ -263,7 +264,7 @@ max-line-length = 88 python = 2.6: py26,custom 2.7: py27,flake8,pylint,custom - 3.5: coveralls,molecule,custom + 3.5: coveralls,custom 3.6: py36,black,custom 3.7: py37,custom 3.8: py38,custom