From 902f28e16e9b8a83ee085529a1fa12c7551378f8 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Wed, 5 Oct 2016 12:16:38 +0100 Subject: [PATCH] Use centralised Ansible test scripts This patch consumes the centralised Ansible test scripts implemented in https://review.openstack.org/381853 Change-Id: Icf49b6e72f6355903225b1163802967865ee587d --- ...s-MR-A.yml => os_swift-overrides-MR-A.yml} | 0 ...s-MR-B.yml => os_swift-overrides-MR-B.yml} | 0 ...t-overrides.yml => os_swift-overrides.yml} | 0 tests/test-swift-multi_reg.sh | 115 ++++++++++++++++++ tox.ini | 108 ++++------------ 5 files changed, 140 insertions(+), 83 deletions(-) rename tests/{swift-overrides-MR-A.yml => os_swift-overrides-MR-A.yml} (100%) rename tests/{swift-overrides-MR-B.yml => os_swift-overrides-MR-B.yml} (100%) rename tests/{swift-overrides.yml => os_swift-overrides.yml} (100%) create mode 100755 tests/test-swift-multi_reg.sh diff --git a/tests/swift-overrides-MR-A.yml b/tests/os_swift-overrides-MR-A.yml similarity index 100% rename from tests/swift-overrides-MR-A.yml rename to tests/os_swift-overrides-MR-A.yml diff --git a/tests/swift-overrides-MR-B.yml b/tests/os_swift-overrides-MR-B.yml similarity index 100% rename from tests/swift-overrides-MR-B.yml rename to tests/os_swift-overrides-MR-B.yml diff --git a/tests/swift-overrides.yml b/tests/os_swift-overrides.yml similarity index 100% rename from tests/swift-overrides.yml rename to tests/os_swift-overrides.yml diff --git a/tests/test-swift-multi_reg.sh b/tests/test-swift-multi_reg.sh new file mode 100755 index 00000000..4ca77aa6 --- /dev/null +++ b/tests/test-swift-multi_reg.sh @@ -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 diff --git a/tox.ini b/tox.ini index 947f5654..8ce4ab4e 100644 --- a/tox.ini +++ b/tox.ini @@ -25,12 +25,14 @@ whitelist_externals = setenv = PYTHONUNBUFFERED=1 ROLE_NAME=os_swift + TEST_IDEMPOTENCE=false + TEST_PLAYBOOK={toxinidir}/tests/test.yml {toxinidir}/tests/test-swift-functional.yml VIRTUAL_ENV={envdir} WORKING_DIR={toxinidir} [testenv:docs] -commands = +commands= bash -c "rm -rf doc/build" doc8 doc python setup.py build_sphinx @@ -71,9 +73,6 @@ commands = # unable to detect undefined names # H303 No wildcard (*) import. 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] @@ -86,28 +85,22 @@ commands = deps = {[testenv]deps} -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] deps = {[testenv:ansible]deps} commands = - {[testenv:ansible]commands} - ansible-playbook -i {toxinidir}/tests/inventory \ - --syntax-check \ - --list-tasks \ - {toxinidir}/tests/test.yml + {[testenv:tests_clone]commands} + bash -c "{toxinidir}/tests/common/test-ansible-syntax.sh" [testenv:ansible-lint] deps = {[testenv:ansible]deps} commands = - {[testenv:ansible]commands} - ansible-lint {toxinidir} + {[testenv:tests_clone]commands} + bash -c "{toxinidir}/tests/common/test-ansible-lint.sh" [testenv:func_base] @@ -118,97 +111,46 @@ install_command = pip install -U --force-reinstall {opts} {packages} -[testenv:func_logs] -commands = - bash -c "{toxinidir}/tests/common/test-log-collect.sh" - - [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(andymccr): this will test standard Swift install. +# NOTE(odyssey4me): this target does not use constraints because +# it doesn't work in OpenStack-CI yet. Once that's fixed, we can +# drop the install_command. install_command = {[testenv:func_base]install_command} deps = {[testenv:ansible]deps} commands = - {[testenv:ansible]commands} - ansible-playbook -i {toxinidir}/tests/inventory \ - -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} + {[testenv:tests_clone]commands} + bash -c "{toxinidir}/tests/common/test-ansible-functional.sh" -# NOTE(andymccr): this will test Swift running in pypy. [testenv:func_pypy] -# 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 +# it doesn't work in OpenStack-CI yet. Once that's fixed, we can +# drop the install_command. install_command = {[testenv:func_base]install_command} deps = {[testenv:ansible]deps} +setenv = + {[testenv]setenv} + ANSIBLE_PARAMETERS=-vvv -e swift_pypy_enabled=True commands = - {[testenv:ansible]commands} - ansible-playbook -i {toxinidir}/tests/inventory \ - -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} + {[testenv:tests_clone]commands} + bash -c "{toxinidir}/tests/common/test-ansible-functional.sh" -# NOTE(andmccr): this will test a MR Swift deploy. [testenv:multi_reg] -# 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 +# it doesn't work in OpenStack-CI yet. Once that's fixed, we can +# drop the install_command. install_command = {[testenv:func_base]install_command} deps = {[testenv:ansible]deps} commands = - {[testenv:ansible]commands} - # Setup the host and Region A - # 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:tests_clone]commands} + bash -c "{toxinidir}/tests/test-swift-multi_reg.sh" [testenv:linters]