mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-27 05:43:05 +00:00
To modify Azure tests and depend on shell scripts and pytest instead
of molecule, the run-tests.sh script has been rewritten to depend on
bash functions and on a bash script that prepare and start a testing
container.
This patch adds a new script, 'utils/setup_test_container.sh' that
can be used to start a new container, using either podman or docker,
based on the available ansible-freeipa images. The new container can
then be used to run ansible-freeipa tests against it.
Also the following files with bash functions were added, and are
used by both scripts:
utils/shansible: Functions to run playbooks in the container
utils/shcontainer: Functions to setup/run a container
utils/shfun: Generic shell helper functions (e.g.: log)
50 lines
1.6 KiB
Bash
50 lines
1.6 KiB
Bash
#!/bin/bash -eu
|
|
# This file shoud be source'd (. set_test_modules) rather than executed.
|
|
|
|
#
|
|
# Set "BASE_BRANCH" to a different branch to compare.
|
|
#
|
|
|
|
RED="\033[31;1m"
|
|
RST="\033[0m"
|
|
|
|
die() {
|
|
echo -e "${RED}${*}${RST}" >&2
|
|
}
|
|
|
|
TOPDIR="$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
[ -n "$(command -v python3)" ] && python="$(command -v python3)" || python="$(command -v python2)"
|
|
|
|
pushd "${TOPDIR}" >/dev/null 2>&1 || die "Failed to change directory."
|
|
|
|
files_list=$(mktemp)
|
|
|
|
remote="$(basename $(mktemp -u remote_XXXXXX))"
|
|
git remote add ${remote} https://github.com/freeipa/ansible-freeipa
|
|
git fetch --prune --no-tags --quiet ${remote}
|
|
git diff "${remote}/master" --name-only > "${files_list}"
|
|
git remote remove ${remote}
|
|
|
|
# Get all modules that should have tests executed
|
|
enabled_modules="$(${python} utils/get_test_modules.py $(cat "${files_list}"))"
|
|
[ -z "${enabled_modules}" ] && enabled_modules="None"
|
|
|
|
# Get individual tests that should be executed
|
|
mapfile -t tests < <(sed -n "s#.*/\(test_[^/]*\).yml#\1#p" "${files_list}" | tr -d " ")
|
|
[ ${#tests[@]} -gt 0 ] && enabled_tests=$(IFS=, ; echo "${tests[*]}")
|
|
[ -z "${enabled_tests}" ] && enabled_tests="None"
|
|
|
|
[ -n "${enabled_tests}" ] && IPA_ENABLED_TESTS="${enabled_tests},${IPA_ENABLED_TESTS}"
|
|
[ -n "${enabled_modules}" ] && IPA_ENABLED_MODULES="${enabled_modules},${IPA_ENABLED_MODULES}"
|
|
|
|
rm -f "${files_list}"
|
|
|
|
export IPA_ENABLED_MODULES
|
|
export IPA_ENABLED_TESTS
|
|
|
|
echo "IPA_ENABLED_MODULES = [${IPA_ENABLED_MODULES}]"
|
|
echo "IPA_ENABLED_TESTS = [${IPA_ENABLED_TESTS}]"
|
|
|
|
popd >/dev/null 2>&1 || die "Failed to change back to original directory."
|