diff --git a/utils/run-tests.sh b/infra/image/run-tests.sh similarity index 57% rename from utils/run-tests.sh rename to infra/image/run-tests.sh index 140998be5..1527de7e4 100755 --- a/utils/run-tests.sh +++ b/infra/image/run-tests.sh @@ -1,20 +1,44 @@ #!/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 + exit 1 +} + +trap cleanup ERR EXIT SIGABRT SIGTERM SIGQUIT + +# shellcheck disable=SC2120 +cleanup() { + trap - ERR EXIT SIGABRT SIGTERM SIGQUIT + log info "Cleaning up environment" + if [ "${STOP_VIRTUALENV:-"N"}" == "Y" ] + then + echo "Deactivating virtual environment" + run_if_exists deactivate + fi +} usage() { local prog="${0##*/}" cat </dev/null 2>&1 + "$@" >/dev/null 2>/dev/null } diff --git a/infra/image/start.sh b/infra/image/start.sh index 0f17189d3..203a375d6 100755 --- a/infra/image/start.sh +++ b/infra/image/start.sh @@ -1,12 +1,11 @@ #!/bin/bash -eu BASEDIR="$(readlink -f "$(dirname "$0")")" -TOPDIR="$(readlink -f "${BASEDIR}/../..")" # shellcheck disable=SC1091 . "${BASEDIR}/shcontainer" # shellcheck disable=SC1091 -. "${TOPDIR}/utils/shfun" +. "${BASEDIR}/shfun" usage() { local prog="${0##*/}" @@ -36,17 +35,6 @@ NOTE: EOF } -list_images() { - local quay_api="https://quay.io/api/v1/repository/ansible-freeipa/upstream-tests/tag" - log info "Available images on quay:" - curl --silent -L "${quay_api}" | jq '.tags[]|.name' | tr -d '"'| sort | uniq | sed "s/.*/ &/" - echo - log info "Local images (use -l):" - local_image=$(container_image_list "${repo}:") - echo "${local_image}" | sed -e "s/.*://" | sed "s/.*/ &/" - echo -} - repo="quay.io/ansible-freeipa/upstream-tests" name="ansible-freeipa-tests" hostname="ipaserver.test.local" diff --git a/utils/setup_test_container.sh b/utils/setup_test_container.sh deleted file mode 100755 index 0916c27f5..000000000 --- a/utils/setup_test_container.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/bash -eu - -SCRIPTDIR="$(readlink -f "$(dirname "$0")")" - -# shellcheck source=utils/shcontainer -. "${SCRIPTDIR}/shcontainer" -# shellcheck source=utils/shansible -. "${SCRIPTDIR}/shansible" - -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" <