From 318f73cc52b22490ab6d030aa21809649e88d65b Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 8 Feb 2018 11:56:11 +0000 Subject: [PATCH] Add a tox environment & dependencies for running molecule tests --- .gitignore | 8 ++++++++ .travis.yml | 2 ++ test-requirements.txt | 9 +++++---- tools/test-molecule.sh | 25 +++++++++++++++++++++++++ tox.ini | 9 +++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100755 tools/test-molecule.sh diff --git a/.gitignore b/.gitignore index 1b29441a0..e79f26ab4 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,11 @@ ansible/kolla-venv/ # Vagrant .vagrant + +# Molecule +.molecule/ + +# Pytest +.cache/ +.pytest_cache/ +pytestdebug.log diff --git a/.travis.yml b/.travis.yml index c0efc10c1..af890d3e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,8 @@ env: - TOX_ENV=ansible-syntax # Run ansible tests. - TOX_ENV=ansible + # Run molecule tests. + - TOX_ENV=molecule install: # Install tox in a virtualenv to ensure we have an up to date version. diff --git a/test-requirements.txt b/test-requirements.txt index 8b4242490..56b561557 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,11 +2,12 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking>=0.12.0,<0.13 # Apache-2.0 - +ansible-lint>=3.0.0 # MIT bashate>=0.2 # Apache-2.0 coverage>=4.0 # Apache-2.0 doc8 # Apache-2.0 -sphinx>=1.5.1 # BSD +docker<3 # Apache-2.0 +hacking>=0.12.0,<0.13 # Apache-2.0 +molecule<3 # MIT oslotest>=1.10.0 # Apache-2.0 -ansible-lint>=3.0.0 # MIT +sphinx>=1.5.1 # BSD diff --git a/tools/test-molecule.sh b/tools/test-molecule.sh new file mode 100755 index 000000000..77923f661 --- /dev/null +++ b/tools/test-molecule.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Run molecule tests. Any arguments passed to this script will be passed onto +# molecule. + +set -e + +molecules="$(find ansible/roles/ -name molecule -type d)" + +failed=0 +ran=0 +for molecule in $molecules; do + pushd $(dirname $molecule) + if ! molecule test --all $*; then + failed=$((failed + 1)) + fi + ran=$((ran + 1)) + popd +done + +if [[ $failed -ne 0 ]]; then + echo "Failed $failed / $ran molecule tests" + exit 1 +fi +echo "Ran $ran molecule tests successfully" diff --git a/tox.ini b/tox.ini index 2c7ed96f7..267fca970 100644 --- a/tox.ini +++ b/tox.ini @@ -52,6 +52,15 @@ commands = {toxinidir}/ansible/roles/*/tests/main.yml \ {posargs}" +[testenv:molecule] +install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/pike} {opts} {packages} +commands = + # Install ansible role dependencies from Galaxy. + ansible-galaxy install \ + -r {toxinidir}/requirements.yml \ + -p {toxinidir}/ansible/roles + {toxinidir}/tools/test-molecule.sh {posargs} + [testenv:alint] commands = ansible-lint ansible/*.yaml