diff --git a/utils/run-tests.sh b/utils/run-tests.sh index 72915f80b4..7384dabded 100755 --- a/utils/run-tests.sh +++ b/utils/run-tests.sh @@ -61,7 +61,7 @@ read -r -a ENABLED_TESTS <<< "${IPA_ENABLED_MODULES:-""}" IMAGE_TAG="fedora-latest" scenario="freeipa-tests" MEMORY=3 -HOSTNAME="ipaserver.test.local" +IPA_HOSTNAME="ipaserver.test.local" SEED="$(date "+%Y%m%d")" GROUP=1 SPLITS=0 @@ -152,7 +152,7 @@ export ANSIBLE_LIBRARY="${TOPDIR}/plugins" export ANSIBLE_MODULE_UTILS="${TOPDIR}/plugins/module_utils" # Start container -"${SCRIPTDIR}/setup_test_container.sh" -e "${engine}" -m "${MEMORY}" -p "${ansible_interpreter}" -i "${IMAGE_TAG}" -n "${HOSTNAME}" "${scenario}" || die "Failed to setup test container" +"${SCRIPTDIR}/setup_test_container.sh" -e "${engine}" -m "${MEMORY}" -p "${ansible_interpreter}" -i "${IMAGE_TAG}" -n "${IPA_HOSTNAME}" -a "${scenario}" || die "Failed to setup test container" # run tests diff --git a/utils/setup_test_container.sh b/utils/setup_test_container.sh index 867bee67f4..c1c3d02fc4 100755 --- a/utils/setup_test_container.sh +++ b/utils/setup_test_container.sh @@ -10,7 +10,7 @@ SCRIPTDIR="$(readlink -f "$(dirname "$0")")" usage() { local prog="${0##*/}" cat < /etc/resolv.conf - become: true -EOF +log info "Setting container DNS nameserver to localhost." +"${engine}" exec "${scenario}" /bin/sh -c 'echo "nameserver 127.0.0.1" > /etc/resolv.conf' || die "Failed to set DNS nameserver to localhost." # wait for FreeIPA services to be available -run_inline_playbook "${test_env}/playbooks" </dev/null && break; sleep 20; done' || die "Failed to start IPA." + +# wait for KDC services to be available +log info "Restarting IPA services." +# shellcheck disable=SC2016 +"${engine}" exec "${scenario}" /bin/sh -c 'for i in $(seq 5); do systemctl restart krb5kdc >/dev/null && break; sleep 10; done' || die "Failed to start IPA KDC." + +# ensure we can get a TGT for admin +log info "Testing kinit with admin." +# shellcheck disable=SC2016 +"${engine}" exec "${scenario}" /bin/sh -c 'for i in $(seq 5); do echo "SomeADMINpassword" | kinit -c ansible_freeipa_cache admin && kdestroy -c ansible_freeipa_cache -A && break; sleep 10; done' || die "Failed to grant admin TGT." + +# shellcheck disable=SC2154 +log info "Creating inventory." +make_inventory "${scenario}" "${engine}" "${ansible_interpreter:-"/usr/bin/python3"}" +if [ -z "${inventory}" ] +then + log error "Could not create inventory file." +else + log info "Inventory path: [${inventory}]" + # shellcheck disable=SC2154 + log debug "$(cat "${inventory}")" + if [ "${ansible_test}" == "yes" ] + then + log info "Testing Asnible connection." + run_if_exists ansible_ping "${inventory}" + log info "Querying installed software" + run_if_exists query_container_installed_software + fi +fi diff --git a/utils/shansible b/utils/shansible index 493f441e64..7836775fef 100644 --- a/utils/shansible +++ b/utils/shansible @@ -36,7 +36,7 @@ run_inline_playbook() { quiet mkdir -p "${playbookdir}" cat - >"${playbook}" # shellcheck disable=SC2086 - ansible-playbook ${ansible_options:-} -i "${inventory}" "${playbook}" + run_if_exists ansible-playbook ${ansible_options:-} -i "${inventory}" "${playbook}" err=$? rm "${playbook}" return ${err} diff --git a/utils/shcontainer b/utils/shcontainer index f74cd31762..308621373c 100644 --- a/utils/shcontainer +++ b/utils/shcontainer @@ -22,7 +22,7 @@ prepare_container() { local IMAGE_TAG img_id CONFIG container_id="" container_status=("-f" "status=created" "-f" "status=running") - hostname="${HOSTNAME:-"ipaserver.test.local"}" + hostname="${IPA_HOSTNAME:-"ipaserver.test.local"}" scenario="${1:-${scenario:-"freeipa-tests"}}" IMAGE_TAG="${2:-${IMAGE_TAG:-fedora-latest}}" [ -n "${scenario}" ] && container_id="$(${engine} ps --all -q -f "name=${scenario}" "${container_status[@]}")" @@ -47,7 +47,6 @@ start_container() { local scenario="${1:-${scenario}}" log info "Starting container for ${scenario}..." "${engine}" start "${scenario}" - run_if_exists query_container_installed_software } if [ -z "$(command -v podman)" ] diff --git a/utils/shfun b/utils/shfun index 4b66c13edd..35d93b2465 100644 --- a/utils/shfun +++ b/utils/shfun @@ -45,7 +45,7 @@ interrupt_exception() { trap - SIGINT log warn "User interrupted test execution." # shellcheck disable=SC2119 - cleanup + cleanup "${scenario:-''}" exit 1 } @@ -57,12 +57,15 @@ run_if_exists() { # shellcheck disable=SC2120 cleanup() { + local container container_engine + container="${1:-${scenario:-"freeipa-tests"}}" + container_engine="${2:-${engine:-"podman"}}" if [ "${STOP_CONTAINER:-"Y"}" == "Y" ] then - run_if_exists stop_container "${1:-${scenario:-"freeipa-tests"}}" "${2:-${engine:-"podman"}}" + run_if_exists stop_container "${container}" "${container_engine}" [ -f "${inventory:-}" ] && rm "${inventory}" else - log info "Keeping container: $(${engine:-"podman"} ps --format "{{.Names}} - {{.ID}}" --filter "name=${1}")" + log info "Keeping container: $(${container_engine} ps --format "{{.Names}} - {{.ID}}" --filter "name=${container}")" fi if [ "${STOP_VIRTUALENV:-"N"}" == "Y" ] then @@ -106,7 +109,7 @@ start_virtual_environment() { fi log info "Starting virtual environment: ${envdirectory}" [ -f "${envdirectory}/bin/activate" ] || die "Failed to create virtual environment." - # shellcheck disable=SC1090 + # shellcheck disable=SC1091 . "${envdirectory}/bin/activate" || die "Cannot activate virtual environment." export STOP_VIRTUALENV="Y" log info "Installing required tools." @@ -145,7 +148,7 @@ die() { fi log error "${*}" STOP_CONTAINER="N" - run_if_exists cleanup + cleanup "${scenario:-''}" [ "${usg}" == "Y" ] && run_if_exists usage exit 1 }