Use centralised Ansible test scripts

This patch consumes the centralised Ansible test scripts
implemented in https://review.openstack.org/381853

Change-Id: Icf49b6e72f6355903225b1163802967865ee587d
This commit is contained in:
Jesse Pretorius 2016-10-05 12:16:38 +01:00 committed by Jesse Pretorius (odyssey4me)
parent 465bd050ab
commit 902f28e16e
5 changed files with 140 additions and 83 deletions

115
tests/test-swift-multi_reg.sh Executable file
View File

@ -0,0 +1,115 @@
#!/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 COMMON_TESTS_PATH="${WORKING_DIR}/tests/common"
## Functions -----------------------------------------------------------------
function execute_ansible_playbook {
export ANSIBLE_CLI_PARAMETERS="${ANSIBLE_PARAMETERS} -e @${ANSIBLE_OVERRIDES}"
CMD_TO_EXECUTE="ansible-playbook ${TEST_PLAYBOOK} $@ ${ANSIBLE_CLI_PARAMETERS}"
echo "Executing: ${CMD_TO_EXECUTE}"
echo "With:"
echo " ANSIBLE_INVENTORY: ${ANSIBLE_INVENTORY}"
echo " ANSIBLE_LOG_PATH: ${ANSIBLE_LOG_PATH}"
${CMD_TO_EXECUTE}
}
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 environment for the setup of Region A
# NB we run against swift_all only since region B hosts don't exist yet.
export ANSIBLE_INVENTORY="${WORKING_DIR}/tests/inventory_MR_A"
export ANSIBLE_LOG_PATH="${ANSIBLE_LOG_DIR}/ansible-execute-install-MR_A.log"
export ANSIBLE_OVERRIDES="${WORKING_DIR}/tests/${ROLE_NAME}-overrides-MR-A.yml"
export ANSIBLE_PARAMETERS="-vvv -e swift_do_setup=True -e swift_do_sync=False -e swift_groups=swift_all"
export TEST_PLAYBOOK="${WORKING_DIR}/tests/test.yml"
# Execute the setup of Region A
execute_ansible_playbook
# Prepare environment for the setup of Region B
export ANSIBLE_INVENTORY="${WORKING_DIR}/tests/inventory_MR_B"
export ANSIBLE_LOG_PATH="${ANSIBLE_LOG_DIR}/ansible-execute-install-MR_B.log"
export ANSIBLE_OVERRIDES="${WORKING_DIR}/tests/${ROLE_NAME}-overrides-MR-B.yml"
export ANSIBLE_PARAMETERS="-vvv"
export TEST_PLAYBOOK="${COMMON_TESTS_PATH}/test-install-swift.yml"
# Execute the setup of Region B
execute_ansible_playbook
# Prepare the environment for synchronising the rings from Region A
export ANSIBLE_INVENTORY="${WORKING_DIR}/tests/inventory_MR_A"
export ANSIBLE_LOG_PATH="${ANSIBLE_LOG_DIR}/ansible-execute-sync-MR_A.log"
export ANSIBLE_OVERRIDES="${WORKING_DIR}/tests/${ROLE_NAME}-overrides-MR-A.yml"
export ANSIBLE_PARAMETERS="-vvv -e swift_do_setup=False -e swift_do_sync=True"
export TEST_PLAYBOOK="${COMMON_TESTS_PATH}/test-install-swift.yml"
# Synchronise the rings from Region A
execute_ansible_playbook
# Prepare the environment for functionally testing Region A
export ANSIBLE_INVENTORY="${WORKING_DIR}/tests/inventory_MR_A"
export ANSIBLE_LOG_PATH="${ANSIBLE_LOG_DIR}/ansible-execute-test-MR_A.log"
export ANSIBLE_OVERRIDES="${WORKING_DIR}/tests/${ROLE_NAME}-overrides-MR-A.yml"
export ANSIBLE_PARAMETERS="-vvv"
export TEST_PLAYBOOK="${WORKING_DIR}/tests/test-swift-functional.yml"
# Functionally test Region A
execute_ansible_playbook
# Prepare the environment for functionally testing Region B
export ANSIBLE_INVENTORY="${WORKING_DIR}/tests/inventory_MR_B"
export ANSIBLE_LOG_PATH="${ANSIBLE_LOG_DIR}/ansible-execute-test-MR_B.log"
export ANSIBLE_OVERRIDES="${WORKING_DIR}/tests/${ROLE_NAME}-overrides-MR-B.yml"
export ANSIBLE_PARAMETERS="-vvv"
export TEST_PLAYBOOK="${WORKING_DIR}/tests/test-swift-functional.yml"
# Functionally test Region B
execute_ansible_playbook

108
tox.ini
View File

@ -25,12 +25,14 @@ whitelist_externals =
setenv = setenv =
PYTHONUNBUFFERED=1 PYTHONUNBUFFERED=1
ROLE_NAME=os_swift ROLE_NAME=os_swift
TEST_IDEMPOTENCE=false
TEST_PLAYBOOK={toxinidir}/tests/test.yml {toxinidir}/tests/test-swift-functional.yml
VIRTUAL_ENV={envdir} VIRTUAL_ENV={envdir}
WORKING_DIR={toxinidir} WORKING_DIR={toxinidir}
[testenv:docs] [testenv:docs]
commands = commands=
bash -c "rm -rf doc/build" bash -c "rm -rf doc/build"
doc8 doc doc8 doc
python setup.py build_sphinx python setup.py build_sphinx
@ -71,9 +73,6 @@ commands =
# unable to detect undefined names # unable to detect undefined names
# H303 No wildcard (*) import. # H303 No wildcard (*) import.
ignore=F403,H303 ignore=F403,H303
# The max-line-length is being set at a greater width in order to accommodate
# jinja templating in python files, especially in the shebang.
max-line-length = 120
[testenv:bashate] [testenv:bashate]
@ -86,28 +85,22 @@ commands =
deps = deps =
{[testenv]deps} {[testenv]deps}
-rhttp://git.openstack.org/cgit/openstack/openstack-ansible-tests/plain/test-ansible-deps.txt -rhttp://git.openstack.org/cgit/openstack/openstack-ansible-tests/plain/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]
@ -118,97 +111,46 @@ 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 # NOTE(odyssey4me): this target does not use constraints because
# end of the run. This will not produce a false positive. Any # it doesn't work in OpenStack-CI yet. Once that's fixed, we can
# exception will be mark the run as failed and exit 1 after all of # drop the install_command.
# the commands have been iterated through.
ignore_errors = True
# NOTE(andymccr): this will test standard Swift install.
install_command = install_command =
{[testenv:func_base]install_command} {[testenv:func_base]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"
-e @{toxinidir}/tests/swift-overrides.yml \
{toxinidir}/tests/test.yml -vvvv
ansible-playbook -i {toxinidir}/tests/inventory \
-e @{toxinidir}/tests/swift-overrides.yml \
{toxinidir}/tests/test-swift-functional.yml -vvvv
{[testenv:func_logs]commands}
# NOTE(andymccr): this will test Swift running in pypy.
[testenv:func_pypy] [testenv:func_pypy]
# Ignore_errors is set to true so that the logs are collected at the # NOTE(odyssey4me): this target does not use constraints because
# end of the run. This will not produce a false positive. Any # it doesn't work in OpenStack-CI yet. Once that's fixed, we can
# exception will be mark the run as failed and exit 1 after all of # drop the install_command.
# the commands have been iterated through.
ignore_errors = True
install_command = install_command =
{[testenv:func_base]install_command} {[testenv:func_base]install_command}
deps = deps =
{[testenv:ansible]deps} {[testenv:ansible]deps}
setenv =
{[testenv]setenv}
ANSIBLE_PARAMETERS=-vvv -e swift_pypy_enabled=True
commands = commands =
{[testenv:ansible]commands} {[testenv:tests_clone]commands}
ansible-playbook -i {toxinidir}/tests/inventory \ bash -c "{toxinidir}/tests/common/test-ansible-functional.sh"
-e @{toxinidir}/tests/swift-overrides.yml \
-e "swift_pypy_enabled=True" \
{toxinidir}/tests/test.yml -vvvv
ansible-playbook -i {toxinidir}/tests/inventory \
-e @{toxinidir}/tests/swift-overrides.yml \
-e "swift_pypy_enabled=True" \
{toxinidir}/tests/test-swift-functional.yml -vvvv
{[testenv:func_logs]commands}
# NOTE(andmccr): this will test a MR Swift deploy.
[testenv:multi_reg] [testenv:multi_reg]
# Ignore_errors is set to true so that the logs are collected at the # NOTE(odyssey4me): this target does not use constraints because
# end of the run. This will not produce a false positive. Any # it doesn't work in OpenStack-CI yet. Once that's fixed, we can
# exception will be mark the run as failed and exit 1 after all of # drop the install_command.
# the commands have been iterated through.
ignore_errors = True
install_command = install_command =
{[testenv:func_base]install_command} {[testenv:func_base]install_command}
deps = deps =
{[testenv:ansible]deps} {[testenv:ansible]deps}
commands = commands =
{[testenv:ansible]commands} {[testenv:tests_clone]commands}
# Setup the host and Region A bash -c "{toxinidir}/tests/test-swift-multi_reg.sh"
# NB we run against swift_all only since region B hosts don't exist yet.
ansible-playbook -i {toxinidir}/tests/inventory_MR_A \
-e "swift_do_setup=True" \
-e "swift_do_sync=False" \
-e "swift_groups='swift_all'" \
-e @{toxinidir}/tests/swift-overrides-MR-A.yml \
{toxinidir}/tests/test.yml -vvvv
# Setup region B Swift only and sync rings.
ansible-playbook -i {toxinidir}/tests/inventory_MR_B \
-e @{toxinidir}/tests/swift-overrides-MR-B.yml \
{toxinidir}/tests/common/test-install-swift.yml -vvvv
# Sync rings from region A
ansible-playbook -i {toxinidir}/tests/inventory_MR_A \
-e "swift_do_setup=False" \
-e "swift_do_sync=True" \
-e @{toxinidir}/tests/swift-overrides-MR-A.yml \
{toxinidir}/tests/common/test-install-swift.yml -vvvv
# Run functional tests against region A
ansible-playbook -i {toxinidir}/tests/inventory_MR_A \
-e @{toxinidir}/tests/swift-overrides-MR-A.yml \
{toxinidir}/tests/test-swift-functional.yml -vvvv
# Run functional tests against region B
ansible-playbook -i {toxinidir}/tests/inventory_MR_B \
-e @{toxinidir}/tests/swift-overrides-MR-B.yml \
{toxinidir}/tests/test-swift-functional.yml -vvvv
{[testenv:func_logs]commands}
[testenv:linters] [testenv:linters]