From fc0729ad7e27011f2d969eefa5ea0f2737d60ca8 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Sun, 30 Jun 2024 13:56:26 +0000 Subject: [PATCH] FIXUP: scripts --- utils/run-tests.sh | 10 ++++++---- utils/setup_test_container.sh | 2 +- utils/shansible | 8 +++++--- utils/shcontainer | 6 ++++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/utils/run-tests.sh b/utils/run-tests.sh index 042a47bc29..c899c982ef 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" diff --git a/utils/setup_test_container.sh b/utils/setup_test_container.sh index 938e16bc61..fde470ea5d 100755 --- a/utils/setup_test_container.sh +++ b/utils/setup_test_container.sh @@ -67,7 +67,7 @@ shift $((OPTIND - 1)) scenario="${1}" shift -make_inventory "${scenario}" "${engine:-podman}" +make_inventory "${scenario}" "${engine:-podman}" "${ansible_interpreter:-"/usr/bin/python3"}" 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