diff --git a/utils/run-tests.sh b/utils/run-tests.sh index 042a47bc29..124fe42829 100755 --- a/utils/run-tests.sh +++ b/utils/run-tests.sh @@ -38,6 +38,7 @@ optional arguments: -e force recreation of the virtual environment -i IMAGE select image to run the tests (default: fedora-latest) -m MEMORY container memory, in GiB (default: 3) + -p INTERPRETER Python interpreter to use on target container -s TEST_SUITE run all playbooks for test suite, which is a directory under ${WHITE}tests${RST} -v Increase Ansible verbosity (can be used multiple times) @@ -66,12 +67,12 @@ GROUP=1 SPLITS=0 ANSIBLE_COLLECTIONS=${ANSIBLE_COLLECTIONS:-"${engine_collection}"} SKIP_ANSIBLE="" - +ansible_interpreter="/usr/bin/python3" EXTRA_OPTIONS="" # Process command options -while getopts ":haA:c:ei:Klm:s:vx" option +while getopts ":haA:c:ei:Klm:p:s:vx" option do case "$option" in h) help && exit 0 ;; @@ -92,6 +93,7 @@ do K) STOP_CONTAINER="N" ;; l) "${SCRIPTDIR}"/setup_test_container.sh -l && exit 0 || exit 1 ;; m) MEMORY="${OPTARG}" ;; + p) ansible_interpreter="$OPTARG" ;; s) [ ${SPLITS} -ne 0 ] && die -u "Can't use '-A' with '-s'" if [ -d "${TOPDIR}/tests/${OPTARG}" ] @@ -125,7 +127,7 @@ export STOP_CONTAINER FORCE_ENV STOP_VIRTUALENV [ ${SPLITS} -eq 0 ] && [ ${#ENABLED_MODULES[@]} -eq 0 ] && [ ${#ENABLED_TESTS[@]} -eq 0 ] && die -u "No test defined." # Ensure $python is set. -[ -z "${python}" ] && python="python3" +[ -z "${python}" ] && python="/usr/bin/python3" log info "Controller python executable: ${python}" ${python} --version @@ -136,7 +138,7 @@ log info "Installing dependencies from 'requirements-tests.txt'" pip install --upgrade -r "${TOPDIR}/requirements-tests.txt" # shellcheck disable=SC2119 -[ -z "SKIP_ANSIBLE" ] || install_ansible +[ -z "SKIP_ANSIBLE" ] && install_ansible # Ansible configuration export ANSIBLE_ROLES_PATH="${TOPDIR}/roles" @@ -144,7 +146,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}" -i "${IMAGE_TAG}" -n "${HOSTNAME}" "${scenario}" +"${SCRIPTDIR}/setup_test_container.sh" -e "${engine}" -m "${MEMORY}" -p "${ansible_interpreter}" -i "${IMAGE_TAG}" -n "${HOSTNAME}" "${scenario}" # run tests diff --git a/utils/setup_test_container.sh b/utils/setup_test_container.sh index 938e16bc61..20081fd8a7 100755 --- a/utils/setup_test_container.sh +++ b/utils/setup_test_container.sh @@ -33,6 +33,7 @@ Options: -m MEMORY set container memory, in GiB (default: 3) -n HOSTNAME set the hostname in the container (default: ipaserver.test.local) + -p INTERPRETER Python interpreter to use on target container EOF )" } @@ -48,8 +49,9 @@ IMAGE_TAG="fedora-latest" MEMORY="${MEMORY:-3}" HOSTNAME="${HOSTNAME:-ipaserver.test.local}" test_env="${test_env:-/tmp}" +ansible_interpreter="/usr/bin/python3" -while getopts ":he:i:lm:n:" option +while getopts ":he:i:lm:n:p:" option do case "$option" in h) help && exit 0 ;; @@ -58,6 +60,7 @@ do l) list_images && exit 0 || exit 1;; m) MEMORY="${OPTARG}" ;; n) HOSTNAME="${OPTARG}" ;; + p) ansible_interpreter="${OPTARG}" ;; *) die -u "Invalid option: ${OPTARG}" ;; esac done @@ -67,8 +70,9 @@ shift $((OPTIND - 1)) scenario="${1}" shift -make_inventory "${scenario}" "${engine:-podman}" - +make_inventory "${scenario}" "${engine:-podman}" "${ansible_interpreter:-"/usr/bin/python3"}" +log info "Inventory path: [${inventory}]" +log debug "$(cat "${inventory}")" prepare_container "${scenario}" "${IMAGE_TAG}" start_container "${scenario}" diff --git a/utils/shansible b/utils/shansible index 59bd620a2b..15ab95f5dd 100644 --- a/utils/shansible +++ b/utils/shansible @@ -37,13 +37,15 @@ run_inline_playbook() { } make_inventory() { - local scenario=$1 - local pod_engine="${engine:-${2:-"podman"}}" + local scenario pod_engine interpreter + scenario="$1" + pod_engine="${2:-${engine:-"podman"}}" + ansible_interpreter="${3:-${ansible_interpreter:-"/usr/bin/python3"}}" export inventory="${test_env:-"/tmp"}/inventory-${scenario}" log info "Inventory file: ${inventory}" cat << EOF > "${inventory}" [ipaserver] -${scenario} ansible_connection=${pod_engine} ansible_python_interpreter=/usr/bin/python3 +${scenario} ansible_connection=${pod_engine} ansible_python_interpreter=${ansible_interpreter} [ipaserver:vars] ipaserver_domain = test.local ipaserver_realm = TEST.LOCAL diff --git a/utils/shcontainer b/utils/shcontainer index 1ed23c797b..6112c9819c 100644 --- a/utils/shcontainer +++ b/utils/shcontainer @@ -37,15 +37,17 @@ prepare_container() { # shellcheck disable=SC2086 container_id=$(${engine} create ${CONFIG} "${img_id}" || die "Cannot create container") log none "CONTAINER: ${container_id}" + else + log warn "Using existing container: ${container_id}" fi export scenario="${scenario:-$(${engine} ps -q --format "{{.Names}}" --filter "id=${container_id}" "${container_status[@]}")}" - log debug "Prepared container: ${scenario}" + log debug "Container ready: ${scenario}" } start_container() { local scenario="${1:-${scenario}}" log info "Starting container for ${scenario}..." - quiet "${engine}" start "${scenario}" + "${engine}" start "${scenario}" >/dev/null || die "Failed to start container: ${scenario}" # With docker on Ubuntu, it might take a couple of seconds # for the container to be available. sleep 3