From 73138475dce0116b6e4811045ea6d4fb91f47df9 Mon Sep 17 00:00:00 2001 From: Charles Short Date: Thu, 21 Nov 2019 06:28:03 -0500 Subject: [PATCH] Add molecule infrastructure - Add molecule support to test ansible roles. - Also fix flake8 failures. - Also drop python36 from the templates Change-Id: Ib647d93144a02a6be7340991c31f65842fdf3f29 Signed-off-by: Charles Short --- .gitignore | 8 ++++++++ .zuul.yaml | 4 +++- ansible/README.testing.rst | 17 +++++++++++++++++ ci-scripts/molecule/test-molecule.sh | 27 +++++++++++++++++++++++++++ test-requirements.txt | 5 ++++- tox.ini | 5 ++++- 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 ansible/README.testing.rst create mode 100755 ci-scripts/molecule/test-molecule.sh diff --git a/.gitignore b/.gitignore index c42c18d44..cf87361e3 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,11 @@ log/* # Containers browbeat-containers/collectd-openstack/config/* ansible-errors.json + +# Molecule +.molecule/ + +# Pytest +.cache/ +.pytest_cache/ +.pytestdebug.log diff --git a/.zuul.yaml b/.zuul.yaml index 45142cd8e..406356036 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -3,17 +3,19 @@ templates: - docs-on-readthedocs - openstack-python37-jobs - - openstack-python36-jobs + - openstack-tox-molecule vars: rtd_webhook_id: '51626' check: jobs: - openstack-tox-linters - openstack-tox-py27 + - openstack-tox-molecule gate: jobs: - openstack-tox-linters - openstack-tox-py27 + - openstack-tox-molecule post: jobs: - browbeat-upload-git-mirror diff --git a/ansible/README.testing.rst b/ansible/README.testing.rst new file mode 100644 index 000000000..6daf9add6 --- /dev/null +++ b/ansible/README.testing.rst @@ -0,0 +1,17 @@ +Running browebat ansible unit tests +=================================== + +Running ansible molecule unit tests +----------------------------------- + +- Ensure that you have docker installed: + + https://docs.docker.com/install/ + +- Run tox -e molecule + +Adding ansible molecue unit test +-------------------------------- + +- cd ansible/install/roles/ + molecule init scenario --role-name --driver-name docker diff --git a/ci-scripts/molecule/test-molecule.sh b/ci-scripts/molecule/test-molecule.sh new file mode 100755 index 000000000..903be1b09 --- /dev/null +++ b/ci-scripts/molecule/test-molecule.sh @@ -0,0 +1,27 @@ +#!/bin/bash + + +# Run molecule tests. Any arguments passed to this script will be passed onto +# molecule. + +set -e + +molecules="$(find ansible/install/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/test-requirements.txt b/test-requirements.txt index 68521ef13..d001e8e3b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking<0.11,>=0.10.0 +hacking>=1.1.0,<1.2.0 # Apache-2.0 pykwalify coverage>=3.6 @@ -21,3 +21,6 @@ testscenarios>=0.4 testtools>=1.4.0 twine wheel +docker<3 # Apache-2.0 +molecule<3 # MIT +selinux>=0.1.5rc1 diff --git a/tox.ini b/tox.ini index f8f7a893f..d639bd45e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.1.1 -envlist = py27,py37,linters,dist,insights +envlist = py27,py37,linters,dist,insights,molecule skipsdist = True [testenv] @@ -78,6 +78,9 @@ commands = python setup.py sdist bdist_wheel twine upload dist/* +[testenv:molecule] +commands = {toxinidir}/ci-scripts/molecule/test-molecule.sh + [flake8] # E123, E125 skipped as they are invalid PEP-8. show-source = True