From 54d545a614f5c3e31b58d7d4713a400160b7bae4 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Tue, 7 Dec 2021 14:59:40 +0000 Subject: [PATCH] CI: run ansible-test sanity checks The script has been adapted from one in ansible-collections-openstack. Change-Id: I494b6d62c67ab66255f7a6a9e229f14021d48800 --- galaxy.yml | 3 +++ test-requirements.txt | 3 +++ tools/run-ansible-sanity.sh | 41 +++++++++++++++++++++++++++++++++++++ tox.ini | 6 ++++++ zuul.d/project.yaml | 1 + 5 files changed, 54 insertions(+) create mode 100755 tools/run-ansible-sanity.sh diff --git a/galaxy.yml b/galaxy.yml index 62cbb21..6e30cfb 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -18,10 +18,13 @@ homepage: https://opendev.org/openstack/ansible-collection-kolla issues: https://launchpad.net/ansible-collection-kolla build_ignore: - "*.tar.gz" + - doc + - releasenotes - requirements.txt - setup.cfg - setup.py - test-requirements.txt + - tools - tox.ini - zuul.d - .gitignore diff --git a/test-requirements.txt b/test-requirements.txt index 6af15c0..be168d4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -13,3 +13,6 @@ python-subunit>=0.0.18 # Apache-2.0/BSD oslotest>=1.10.0 # Apache-2.0 stestr>=1.0.0 # Apache-2.0 testtools>=1.4.0 # MIT + +# sanity testing +ansible-core diff --git a/tools/run-ansible-sanity.sh b/tools/run-ansible-sanity.sh new file mode 100755 index 0000000..c58ca9d --- /dev/null +++ b/tools/run-ansible-sanity.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Copyright 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Adapted from a script in ansible-collections-openstack: +# https://opendev.org/openstack/ansible-collections-openstack/src/commit/15f73aa72e79c57c422a41aa5876ff334a95c67e/tools/run-ansible-sanity.sh + +set -eu +set -o pipefail + +TOXDIR=${1:-.} +ANSIBLE_COLLECTIONS_PATH=$(mktemp -d) +echo "Executing ansible-test sanity checks in ${ANSIBLE_COLLECTIONS_PATH}" + +trap "rm -rf ${ANSIBLE_COLLECTIONS_PATH}" err exit + +PY_VER=$(python3 -c "from platform import python_version;print(python_version())" | cut -f 1,2 -d".") +echo "Running test with Python version ${PY_VER}" + +rm -rf "${ANSIBLE_COLLECTIONS_PATH}" +mkdir -p ${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/openstack/kolla +ansible-galaxy --version +ansible-galaxy collection build --force +ansible-galaxy collection install openstack-kolla-*.tar.gz --collections-path ${ANSIBLE_COLLECTIONS_PATH} --force +cd ${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/openstack/kolla/ +echo "Running ansible-test with version:" +ansible --version +ansible-test sanity -v \ + --venv \ + --python ${PY_VER} diff --git a/tox.ini b/tox.ini index bd3454d..52a21c8 100644 --- a/tox.ini +++ b/tox.ini @@ -76,6 +76,7 @@ commands = sphinx-build -n -W --keep-going -b html releasenotes/source releasenotes/build/html [testenv:linters] +passenv = HOME deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} -r{toxinidir}/test-requirements.txt @@ -87,6 +88,7 @@ commands = {[testenv:doc8]commands} {[testenv:bandit]commands} {[testenv:yamllint]commands} + {[testenv:ansible-sanity]commands} [testenv:pep8] deps = {[testenv:linters]deps} @@ -117,3 +119,7 @@ commands = bandit --skip B303 -r plugins tests [testenv:yamllint] deps = {[testenv:linters]deps} commands = yamllint -s . + +[testenv:ansible-sanity] +deps = {[testenv:linters]deps} +commands = {toxinidir}/tools/run-ansible-sanity.sh {toxinidir} diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index c5aed36..27f8a7a 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -1,6 +1,7 @@ --- - project: templates: + - ansible-role-jobs - publish-openstack-docs-pti gate: queue: kolla