From 8646a909b9551fa8e55abacf7602fea2df6cb070 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 | 137 ++++++++++++++++++---------- infra/image/shcontainer | 15 ++- {utils => infra/image}/shfun | 51 ++++------- {utils => infra/image}/shlog | 2 +- infra/image/start.sh | 14 +-- utils/setup_test_container.sh | 119 ------------------------ utils/shansible | 88 ------------------ utils/shcontainer | 61 ------------- 8 files changed, 123 insertions(+), 364 deletions(-) rename {utils => infra/image}/run-tests.sh (57%) rename {utils => infra/image}/shfun (65%) rename {utils => infra/image}/shlog (97%) 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 57% rename from utils/run-tests.sh rename to infra/image/run-tests.sh index 140998be56..df72c337f7 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 0f17189d36..203a375d6b 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 0916c27f53..0000000000 --- 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" <