#!/usr/bin/env bash # Copyright 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 ---------------------------------------------------------------------- PROJECT_DIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/../" ROLE_DIR=$1 USE_VENV=${USE_VENV:-yes} MOLECULE_CONFIG=${MOLECULE_CONFIG:-.config/molecule/config_podman.yml} TEST_ALL_ROLES=${TEST_ALL_ROLES:-no} TEST_VERBOSITY=${TEST_VERBOSITY:-'--debug'} # Run local test (test -d "${ROLE_DIR}" || (echo "No such directory: ${ROLE_DIR}" && exit 1) ) || exit 1 pushd "${ROLE_DIR}" local_roledir=$(echo $ROLE_DIR | sed 's|\.\?\./||g') if [[ ${TEST_ALL_ROLES} == 'yes' ]]; then ROLES_LIST=$(ls -1) elif [[ -n ${TEST_SINGLE_ROLE} ]]; then (test -d "${TEST_SINGLE_ROLE}" || (echo "No such directory: ${TEST_SINGLE_ROLE}" && exit 1) ) || exit 1 ROLES_LIST=${TEST_SINGLE_ROLE} fi # Find what roles were modified if [[ -z ${ROLES_LIST} ]]; then ROLES_LIST=$(git diff --dirstat=files,0,cumulative HEAD^..HEAD | sed "s|^[ 0-9.]\+% \(${local_roledir}\)\?||g" | cut -d/ -f1 | sort -u ) fi git clone https://github.com/openstack-k8s-operators/install_yamls /root/src/github.com/openstack-k8s-operators/install_yamls || true export ANSIBLE_ACTION_PLUGINS=./plugins/action:~/.ansible/plugins/action:/usr/share/ansible/plugins/actions for rolepath in ${ROLES_LIST}; do role=$(echo $rolepath|sed "s|${local_roledir}||" | cut -f1 -d /) test -d ${role} || continue echo "Running molecule against: ${role}" pushd $role case ${USE_VENV} in y|yes|true) ${HOME}/test-python/bin/molecule -c "${PROJECT_DIR}${MOLECULE_CONFIG}" ${TEST_VERBOSITY} test --all ;; *) molecule -c "${PROJECT_DIR}${MOLECULE_CONFIG}" ${TEST_VERBOSITY} test --all ;; esac popd done popd