Merge "Implement centralised Ansible test scripts"
This commit is contained in:
commit
992cd157d1
@ -23,10 +23,18 @@
|
|||||||
# This script prepares the host with all the required Ansible
|
# This script prepares the host with all the required Ansible
|
||||||
# roles and plugins to execute the test playbook.
|
# roles and plugins to execute the test playbook.
|
||||||
|
|
||||||
|
## Shell Opts ----------------------------------------------------------------
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
export TESTING_HOME=${TESTING_HOME:-$HOME}
|
export TESTING_HOME=${TESTING_HOME:-$HOME}
|
||||||
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
export ROLE_NAME=${ROLE_NAME:-''}
|
export ROLE_NAME=${ROLE_NAME:-''}
|
||||||
|
export ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY:-$WORKING_DIR/tests/inventory}
|
||||||
|
|
||||||
|
export ANSIBLE_NOCOLOR=1
|
||||||
export ANSIBLE_ROLE_DIR="${TESTING_HOME}/.ansible/roles"
|
export ANSIBLE_ROLE_DIR="${TESTING_HOME}/.ansible/roles"
|
||||||
export ANSIBLE_PLUGIN_DIR="${TESTING_HOME}/.ansible/plugins"
|
export ANSIBLE_PLUGIN_DIR="${TESTING_HOME}/.ansible/plugins"
|
||||||
export ANSIBLE_CFG_PATH="${TESTING_HOME}/.ansible.cfg"
|
export ANSIBLE_CFG_PATH="${TESTING_HOME}/.ansible.cfg"
|
||||||
@ -36,6 +44,7 @@ export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
|
|||||||
echo "TESTING_HOME: ${TESTING_HOME}"
|
echo "TESTING_HOME: ${TESTING_HOME}"
|
||||||
echo "WORKING_DIR: ${WORKING_DIR}"
|
echo "WORKING_DIR: ${WORKING_DIR}"
|
||||||
echo "ROLE_NAME: ${ROLE_NAME}"
|
echo "ROLE_NAME: ${ROLE_NAME}"
|
||||||
|
echo "ANSIBLE_INVENTORY: ${ANSIBLE_INVENTORY}"
|
||||||
|
|
||||||
# Toggle the reset of all data cloned from other repositories.
|
# Toggle the reset of all data cloned from other repositories.
|
||||||
export TEST_RESET=${TEST_RESET:-false}
|
export TEST_RESET=${TEST_RESET:-false}
|
||||||
@ -44,6 +53,8 @@ export TEST_RESET=${TEST_RESET:-false}
|
|||||||
# console output is immediate.
|
# console output is immediate.
|
||||||
export PYTHONUNBUFFERED=1
|
export PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
# If the test reset toggle is set, destroy the existing cloned data.
|
# If the test reset toggle is set, destroy the existing cloned data.
|
||||||
if [ "${TEST_RESET}" == "true" ]; then
|
if [ "${TEST_RESET}" == "true" ]; then
|
||||||
echo "Resetting all cloned data."
|
echo "Resetting all cloned data."
|
||||||
|
108
test-ansible-functional.sh
Executable file
108
test-ansible-functional.sh
Executable file
@ -0,0 +1,108 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright 2016, Rackspace US, 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.
|
||||||
|
|
||||||
|
# WARNING:
|
||||||
|
# This file is use by all OpenStack-Ansible roles for testing purposes.
|
||||||
|
# Any changes here will affect all OpenStack-Ansible role repositories
|
||||||
|
# with immediate effect.
|
||||||
|
|
||||||
|
# PURPOSE:
|
||||||
|
# This script executes a test Ansible playbook for the purpose of
|
||||||
|
# functionally testing the role. It supports a convergence test,
|
||||||
|
# check mode and an idempotence test.
|
||||||
|
|
||||||
|
## Shell Opts ----------------------------------------------------------------
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
|
export ROLE_NAME=${ROLE_NAME:-''}
|
||||||
|
|
||||||
|
export ANSIBLE_OVERRIDES=${ANSIBLE_OVERRIDES:-$WORKING_DIR/tests/$ROLE_NAME-overrides.yml}
|
||||||
|
export ANSIBLE_PARAMETERS=${ANSIBLE_PARAMETERS:-"-vvv"}
|
||||||
|
export TEST_PLAYBOOK=${TEST_PLAYBOOK:-$WORKING_DIR/tests/test.yml}
|
||||||
|
export TEST_CHECK_MODE=${TEST_CHECK_MODE:-false}
|
||||||
|
export TEST_IDEMPOTENCE=${TEST_IDEMPOTENCE:-false}
|
||||||
|
|
||||||
|
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
|
||||||
|
|
||||||
|
echo "ANSIBLE_OVERRIDES: ${ANSIBLE_OVERRIDES}"
|
||||||
|
echo "ANSIBLE_PARAMETERS: ${ANSIBLE_PARAMETERS}"
|
||||||
|
echo "TEST_PLAYBOOK: ${TEST_PLAYBOOK}"
|
||||||
|
echo "TEST_CHECK_MODE: ${TEST_CHECK_MODE}"
|
||||||
|
echo "TEST_IDEMPOTENCE: ${TEST_IDEMPOTENCE}"
|
||||||
|
|
||||||
|
## Functions -----------------------------------------------------------------
|
||||||
|
|
||||||
|
function set_ansible_parameters {
|
||||||
|
if [ -f "${ANSIBLE_OVERRIDES}" ]; then
|
||||||
|
ANSIBLE_CLI_PARAMETERS="${ANSIBLE_PARAMETERS} -e @${ANSIBLE_OVERRIDES}"
|
||||||
|
else
|
||||||
|
ANSIBLE_CLI_PARAMETERS="${ANSIBLE_PARAMETERS}"
|
||||||
|
fi
|
||||||
|
echo "ANSIBLE_CLI_PARAMETERS: ${ANSIBLE_CLI_PARAMETERS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function gate_job_exit_tasks {
|
||||||
|
source "${COMMON_TESTS_PATH}/test-log-collect.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Ensure that the Ansible environment is properly prepared
|
||||||
|
source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
|
||||||
|
|
||||||
|
# Set gate job exit traps, this is run regardless of exit state when the job finishes.
|
||||||
|
trap gate_job_exit_tasks EXIT
|
||||||
|
|
||||||
|
# Prepare the extra CLI parameters used in each execution
|
||||||
|
set_ansible_parameters
|
||||||
|
|
||||||
|
# If the test for check mode is enabled, then execute it
|
||||||
|
if [ "${TEST_CHECK_MODE}" == "true" ]; then
|
||||||
|
ansible-playbook --check \
|
||||||
|
${ANSIBLE_CLI_PARAMETERS} \
|
||||||
|
${TEST_PLAYBOOK}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute the test playbook
|
||||||
|
ansible-playbook ${ANSIBLE_CLI_PARAMETERS} \
|
||||||
|
${TEST_PLAYBOOK}
|
||||||
|
|
||||||
|
# If the idempotence test is enabled, then execute the
|
||||||
|
# playbook again and verify that nothing changed/failed
|
||||||
|
# in the output log.
|
||||||
|
|
||||||
|
if [ "${TEST_IDEMPOTENCE}" == "true" ]; then
|
||||||
|
|
||||||
|
# Set the path for the output log
|
||||||
|
ANSIBLE_LOG_PATH="/tmp/ansible.log"
|
||||||
|
|
||||||
|
# Execute the test playbook
|
||||||
|
ansible-playbook ${ANSIBLE_CLI_PARAMETERS} \
|
||||||
|
${TEST_PLAYBOOK}
|
||||||
|
|
||||||
|
# Check the output log for changed/failed tasks
|
||||||
|
if grep -q "changed=0.*failed=0" /tmp/idempotence_test_output.txt; then
|
||||||
|
echo "Idempotence test: pass"
|
||||||
|
else
|
||||||
|
echo "Idempotence test: fail"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
40
test-ansible-lint.sh
Executable file
40
test-ansible-lint.sh
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright 2016, Rackspace US, 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.
|
||||||
|
|
||||||
|
# WARNING:
|
||||||
|
# This file is use by all OpenStack-Ansible roles for testing purposes.
|
||||||
|
# Any changes here will affect all OpenStack-Ansible role repositories
|
||||||
|
# with immediate effect.
|
||||||
|
|
||||||
|
# PURPOSE:
|
||||||
|
# This script executes ansible-lint against the role directory.
|
||||||
|
|
||||||
|
## Shell Opts ----------------------------------------------------------------
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
|
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
|
||||||
|
|
||||||
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Ensure that the Ansible environment is properly prepared
|
||||||
|
source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
|
||||||
|
|
||||||
|
# Execute ansible-lint
|
||||||
|
ansible-lint ${WORKING_DIR}
|
43
test-ansible-syntax.sh
Executable file
43
test-ansible-syntax.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Copyright 2016, Rackspace US, 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.
|
||||||
|
|
||||||
|
# WARNING:
|
||||||
|
# This file is use by all OpenStack-Ansible roles for testing purposes.
|
||||||
|
# Any changes here will affect all OpenStack-Ansible role repositories
|
||||||
|
# with immediate effect.
|
||||||
|
|
||||||
|
# PURPOSE:
|
||||||
|
# This script executes ansible-syntax against the role test playbook.
|
||||||
|
|
||||||
|
## Shell Opts ----------------------------------------------------------------
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
|
export COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
|
||||||
|
export ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY:-$WORKING_DIR/tests/inventory}
|
||||||
|
|
||||||
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Ensure that the Ansible environment is properly prepared
|
||||||
|
source "${COMMON_TESTS_PATH}/test-ansible-env-prep.sh"
|
||||||
|
|
||||||
|
# Execute the Ansible syntax check
|
||||||
|
ansible-playbook --syntax-check \
|
||||||
|
--list-tasks \
|
||||||
|
${WORKING_DIR}/tests/test.yml
|
@ -35,8 +35,16 @@
|
|||||||
# use jinja templating, this will often fail and the syntax
|
# use jinja templating, this will often fail and the syntax
|
||||||
# error will be discovered in execution anyway)
|
# error will be discovered in execution anyway)
|
||||||
|
|
||||||
|
## Shell Opts ----------------------------------------------------------------
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
|
|
||||||
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
grep --recursive --binary-files=without-match \
|
grep --recursive --binary-files=without-match \
|
||||||
--files-with-match '^.!.*\(ba\)\?sh$' \
|
--files-with-match '^.!.*\(ba\)\?sh$' \
|
||||||
--exclude-dir .tox \
|
--exclude-dir .tox \
|
||||||
|
@ -23,9 +23,13 @@
|
|||||||
# This script collects, renames and compresses the logs produced in
|
# This script collects, renames and compresses the logs produced in
|
||||||
# a role test if the host is in OpenStack-CI.
|
# a role test if the host is in OpenStack-CI.
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
|
|
||||||
if [[ -d "/etc/nodepool" ]];then
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
if [[ -d "/etc/nodepool" ]]; then
|
||||||
mkdir -p "${WORKING_DIR}/logs/host" "${WORKING_DIR}/logs/openstack"
|
mkdir -p "${WORKING_DIR}/logs/host" "${WORKING_DIR}/logs/openstack"
|
||||||
rsync --archive --verbose --safe-links --ignore-errors /var/log/ "${WORKING_DIR}/logs/host" || true
|
rsync --archive --verbose --safe-links --ignore-errors /var/log/ "${WORKING_DIR}/logs/host" || true
|
||||||
rsync --archive --verbose --safe-links --ignore-errors /openstack/log/ "${WORKING_DIR}/logs/openstack" || true
|
rsync --archive --verbose --safe-links --ignore-errors /openstack/log/ "${WORKING_DIR}/logs/openstack" || true
|
||||||
|
@ -24,8 +24,16 @@
|
|||||||
# the search pattern. The search pattern is meant to find any python
|
# the search pattern. The search pattern is meant to find any python
|
||||||
# scripts present in the role.
|
# scripts present in the role.
|
||||||
|
|
||||||
|
## Shell Opts ----------------------------------------------------------------
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Vars ----------------------------------------------------------------------
|
||||||
|
|
||||||
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
export WORKING_DIR=${WORKING_DIR:-$(pwd)}
|
||||||
|
|
||||||
|
## Main ----------------------------------------------------------------------
|
||||||
|
|
||||||
grep --recursive --binary-files=without-match \
|
grep --recursive --binary-files=without-match \
|
||||||
--files-with-match '^.!.*python$' \
|
--files-with-match '^.!.*python$' \
|
||||||
--exclude-dir .eggs \
|
--exclude-dir .eggs \
|
||||||
|
33
tox.ini
33
tox.ini
@ -60,10 +60,11 @@ commands =
|
|||||||
# https://git.openstack.org/openstack/openstack-ansible-tests
|
# https://git.openstack.org/openstack/openstack-ansible-tests
|
||||||
# or for a stable branch:
|
# or for a stable branch:
|
||||||
# -b stable/mitaka https://git.openstack.org/openstack/openstack-ansible-tests
|
# -b stable/mitaka https://git.openstack.org/openstack/openstack-ansible-tests
|
||||||
|
#
|
||||||
[testenv:tests_clone]
|
[testenv:tests_clone]
|
||||||
commands =
|
commands =
|
||||||
bash -c "if [ ! -d "{toxinidir}/tests/common" ]; then \
|
bash -c "if [ ! -d "{toxinidir}/tests/common" ]; then \
|
||||||
git clone {toxinidir} {toxinidir}/tests/common; \
|
ln -s {toxinidir} {toxinidir}/tests/common; \
|
||||||
fi"
|
fi"
|
||||||
|
|
||||||
|
|
||||||
@ -100,28 +101,22 @@ commands =
|
|||||||
deps =
|
deps =
|
||||||
{[testenv]deps}
|
{[testenv]deps}
|
||||||
-r{toxinidir}/test-ansible-deps.txt
|
-r{toxinidir}/test-ansible-deps.txt
|
||||||
commands =
|
|
||||||
{[testenv:tests_clone]commands}
|
|
||||||
bash -c "{toxinidir}/tests/common/test-ansible-env-prep.sh"
|
|
||||||
|
|
||||||
|
|
||||||
[testenv:ansible-syntax]
|
[testenv:ansible-syntax]
|
||||||
deps =
|
deps =
|
||||||
{[testenv:ansible]deps}
|
{[testenv:ansible]deps}
|
||||||
commands =
|
commands =
|
||||||
{[testenv:ansible]commands}
|
{[testenv:tests_clone]commands}
|
||||||
ansible-playbook -i {toxinidir}/tests/inventory \
|
bash -c "{toxinidir}/tests/common/test-ansible-syntax.sh"
|
||||||
--syntax-check \
|
|
||||||
--list-tasks \
|
|
||||||
{toxinidir}/tests/test.yml
|
|
||||||
|
|
||||||
|
|
||||||
[testenv:ansible-lint]
|
[testenv:ansible-lint]
|
||||||
deps =
|
deps =
|
||||||
{[testenv:ansible]deps}
|
{[testenv:ansible]deps}
|
||||||
commands =
|
commands =
|
||||||
{[testenv:ansible]commands}
|
{[testenv:tests_clone]commands}
|
||||||
ansible-lint {toxinidir}
|
bash -c "{toxinidir}/tests/common/test-ansible-lint.sh"
|
||||||
|
|
||||||
|
|
||||||
[testenv:func_base]
|
[testenv:func_base]
|
||||||
@ -132,17 +127,7 @@ install_command =
|
|||||||
pip install -U --force-reinstall {opts} {packages}
|
pip install -U --force-reinstall {opts} {packages}
|
||||||
|
|
||||||
|
|
||||||
[testenv:func_logs]
|
|
||||||
commands =
|
|
||||||
bash -c "{toxinidir}/tests/common/test-log-collect.sh"
|
|
||||||
|
|
||||||
|
|
||||||
[testenv:functional]
|
[testenv:functional]
|
||||||
# Ignore_errors is set to true so that the logs are collected at the
|
|
||||||
# end of the run. This will not produce a false positive. Any
|
|
||||||
# exception will be mark the run as failed and exit 1 after all of
|
|
||||||
# the commands have been iterated through.
|
|
||||||
ignore_errors = True
|
|
||||||
# NOTE(odyssey4me): this target does not use constraints because
|
# NOTE(odyssey4me): this target does not use constraints because
|
||||||
# it doesn't work in OpenStack-CI yet. Once that's fixed, we can
|
# it doesn't work in OpenStack-CI yet. Once that's fixed, we can
|
||||||
# drop the install_command.
|
# drop the install_command.
|
||||||
@ -151,10 +136,8 @@ install_command =
|
|||||||
deps =
|
deps =
|
||||||
{[testenv:ansible]deps}
|
{[testenv:ansible]deps}
|
||||||
commands =
|
commands =
|
||||||
{[testenv:ansible]commands}
|
{[testenv:tests_clone]commands}
|
||||||
ansible-playbook -i {toxinidir}/tests/inventory \
|
bash -c "{toxinidir}/tests/common/test-ansible-functional.sh"
|
||||||
{toxinidir}/tests/test.yml -vvvv
|
|
||||||
{[testenv:func_logs]commands}
|
|
||||||
|
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
|
Loading…
Reference in New Issue
Block a user