Skip to content

Commit

Permalink
FIXUP: scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rjeffman committed Jun 30, 2024
1 parent 1912f8d commit fc0729a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
10 changes: 6 additions & 4 deletions utils/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ;;
Expand All @@ -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}" ]
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion utils/setup_test_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
8 changes: 5 additions & 3 deletions utils/shansible
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions utils/shcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc0729a

Please sign in to comment.