tripleo-ansible/scripts/run-local-test
Kevin Carter 09b1805e5f Convert tox to native zuul
This change converts the TripleO-Ansible test process to using native zuul.
After a long discussion about the current test process [0] it has been
determined that most folks using tox do so on a local workstation and
would not expect the local system to be modified when envoked.

To ensure we're not creating a situation where a developer runs tox with a
job that may require modifications of the system the current test
structure has been replaced with a native zuul `base` job.

> This change opens the door for us to add tox jobs later which may be
  added in support of the native jobs we're running now.

> The test_json_error role was updated to set required configuration
  for that specific role, which was being passed in via tox before.

Documentation has been added to the contributing section to highlight
the role development process and how folks can test things locally using
a script which will mimic the zuul job runtime.

[0] - http://eavesdrop.openstack.org/irclogs/%23tripleo/latest.log.html#t2019-06-27T14:01:13

Change-Id: Ia1f3d479f3ac447d125169d08c78aaccfeacea3a
Signed-off-by: Kevin Carter <kecarter@redhat.com>
2019-07-06 02:31:06 +00:00

65 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
## Shell Opts ----------------------------------------------------------------
set -o pipefail
set -xeuo
## Vars ----------------------------------------------------------------------
export PROJECT_DIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/../"
export ROLE_NAME="${ROLE_NAME:-$1}"
## Main ----------------------------------------------------------------------
# Source distribution information
source /etc/os-release || source /usr/lib/os-release
RHT_PKG_MGR=$(command -v dnf || command -v yum)
PYTHON_EXEC=$(command -v python3 || command -v python)
# Install the one requirement we need to run any local test
case "${ID,,}" in
amzn|rhel|centos|fedora)
sudo "${RHT_PKG_MGR}" install -y python*-virtualenv
;;
esac
# Create a virtual env
"${PYTHON_EXEC}" -m virtualenv --system-site-packages "${HOME}/test-python"
# Install local requirements
"${HOME}/test-python/bin/pip" install \
-r "${PROJECT_DIR}/requirements.txt" \
-r "${PROJECT_DIR}/test-requirements.txt" \
-r "${PROJECT_DIR}/molecule-requirements.txt"
# Run bindep
PS1="[\u@\h \W]\$" source "${HOME}/test-python/bin/activate"
"${PROJECT_DIR}/scripts/bindep-install"
# Run local test
source "${PROJECT_DIR}/ansible-test-env.rc"
export ANSIBLE_ROLES_PATH="${ANSIBLE_ROLES_PATH}:${HOME}/zuul-jobs/roles"
ansible-playbook -i "${PROJECT_DIR}/tests/hosts.ini" \
-e "tripleo_src=$(realpath --relative-to="${HOME}" "${PROJECT_DIR}")" \
-e "tripleo_role_name=${ROLE_NAME}" \
-e "ansible_user=${USER}" \
-e "ansible_user_dir=${HOME}" \
"${PROJECT_DIR}/tripleo_ansible/playbooks/prepare-test-host.yml" \
"${PROJECT_DIR}/zuul.d/playbooks/run-local.yml"