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 9da9f15
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
12 changes: 7 additions & 5 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,15 +138,15 @@ 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"
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
Expand Down
10 changes: 7 additions & 3 deletions utils/setup_test_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)"
}
Expand All @@ -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 ;;
Expand All @@ -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
Expand All @@ -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}"

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 9da9f15

Please sign in to comment.