diff --git a/utils/run-tests.sh b/infra/image/run-tests.sh similarity index 59% rename from utils/run-tests.sh rename to infra/image/run-tests.sh index 140998be56..c059563f33 100755 --- a/utils/run-tests.sh +++ b/infra/image/run-tests.sh @@ -1,20 +1,61 @@ #!/bin/bash -eu SCRIPTDIR="$(readlink -f "$(dirname "$0")")" -TOPDIR="$(readlink -f "${SCRIPTDIR}/..")" +TOPDIR="$(readlink -f "${SCRIPTDIR}/../..")" +UTILSDIR="${SCRIPTDIR}" + +echo $SCRIPTDIR +echo $TOPDIR +echo ${UTILSDIR} # shellcheck source=utils/shfun -. "${SCRIPTDIR}/shfun" +. "${UTILSDIR}/shfun" # shellcheck source=utils/shcontainer -. "${SCRIPTDIR}/shcontainer" -# shellcheck source=utils/shansible -. "${SCRIPTDIR}/shansible" +. "${UTILSDIR}/shcontainer" + +set -o history -o histexpand +set -o errexit -o errtrace + +trap interrupt_exception SIGINT + +interrupt_exception() { + trap - ERR SIGINT + log warn "User interrupted test execution." + # shellcheck disable=SC2119 + cleanup "${scenario:+${scenario}}" + exit 1 +} + +trap cleanup ERR EXIT SIGKILL SIGABRT SIGTERM SIGQUIT + +# shellcheck disable=SC2120 +cleanup() { + trap - ERR EXIT SIGKILL SIGABRT SIGTERM SIGQUIT + local container + log info "Cleaning up environment" + container="${1:-${scenario:+${scenario}}}" + if [ "${STOP_CONTAINER:-"Y"}" == "Y" ] && [ -n "${container}" ] + then + run_if_exists container_stop "${container}" + [ -f "${inventory:-}" ] && rm "${inventory}" + else + if [ -n "${container}" ] + then + log info "Keeping container: $(podman ps --format "{{.Names}} - {{.ID}}" --filter "name=${container}")" + fi + fi + if [ "${STOP_VIRTUALENV:-"N"}" == "Y" ] + then + echo "Deactivating virtual environment" + run_if_exists deactivate + fi +} usage() { local prog="${0##*/}" cat </dev/null) - # In some configurations, it may not be possible to use another - # directory, so we store the playbook in the current one. - # [ -z "${playbook}" ] && playbook=$(mktemp "ansible-freeipa-test-playbook_ipa.XXXXXXXX") - - inventory="${inventory:-${test_env:-"."}/inventory}" - quiet mkdir -p "${playbookdir}" - cat - >"${playbook}" - # shellcheck disable=SC2086 - run_if_exists ansible-playbook ${ansible_options:-} -i "${inventory}" "${playbook}" - err=$? - rm -f "${playbook}" - return ${err} -} - -make_inventory() { - local scenario pod_engine ansible_interpreter - scenario=$1 - pod_engine="${engine:-${2:-podman}}" - ansible_interpreter="${3:-${ansible_interpreter:-"/usr/bin/python3"}}" - export inventory="${test_env:-"."}/inventory" - log info "Inventory file: ${inventory}" - cat << EOF > "${inventory}" -[ipaserver] -${scenario} ansible_connection=${pod_engine} ansible_python_interpreter=${ansible_interpreter} -[ipaserver:vars] -ipaserver_domain = test.local -ipaserver_realm = TEST.LOCAL -EOF -} - -query_container_installed_software() { - # check image software versions. - run_inline_playbook "${test_env:-"/tmp"}/playbooks" <