From af5d489db06d36a41b1e891875027d2348cc0de1 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Thu, 31 Oct 2024 18:47:51 -0300 Subject: [PATCH] run-tests.sh: Update to current CI procedures The objective of the 'run-tests.sh' script is to provide for a developer a similar environment as the one used by the Azure CI to test the modules and roles. This patch updates the script to use the same tools as are being used after the latest change in the Azure CI. --- {utils => infra/image}/run-tests.sh | 138 +++++++++++++++++++++------- infra/image/shcontainer | 13 ++- {utils => infra/image}/shfun | 36 -------- {utils => infra/image}/shlog | 0 infra/image/start.sh | 14 +-- utils/setup_test_container.sh | 119 ------------------------ utils/shansible | 88 ------------------ utils/shcontainer | 61 ------------ 8 files changed, 120 insertions(+), 349 deletions(-) rename {utils => infra/image}/run-tests.sh (58%) rename {utils => infra/image}/shfun (67%) rename {utils => infra/image}/shlog (100%) delete mode 100755 utils/setup_test_container.sh delete mode 100644 utils/shansible delete mode 100644 utils/shcontainer diff --git a/utils/run-tests.sh b/infra/image/run-tests.sh similarity index 58% rename from utils/run-tests.sh rename to infra/image/run-tests.sh index 140998be56..e384bb9173 100755 --- a/utils/run-tests.sh +++ b/infra/image/run-tests.sh @@ -1,20 +1,56 @@ #!/bin/bash -eu SCRIPTDIR="$(readlink -f "$(dirname "$0")")" -TOPDIR="$(readlink -f "${SCRIPTDIR}/..")" +TOPDIR="$(readlink -f "${SCRIPTDIR}/../..")" +UTILSDIR="${SCRIPTDIR}" -# shellcheck source=utils/shfun -. "${SCRIPTDIR}/shfun" -# shellcheck source=utils/shcontainer -. "${SCRIPTDIR}/shcontainer" -# shellcheck source=utils/shansible -. "${SCRIPTDIR}/shansible" +# shellcheck source=infra/image/shfun +. "${UTILSDIR}/shfun" +# shellcheck source=infra/image/shcontainer +. "${UTILSDIR}/shcontainer" + +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 SIGABRT SIGTERM SIGQUIT + +# shellcheck disable=SC2120 +cleanup() { + trap - ERR EXIT 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" <