#!/bin/bash -eu SCRIPTDIR="$(readlink -f "$(dirname "$0")")" TOPDIR="$(readlink -f "${SCRIPTDIR}/..")" # shellcheck source=utils/shfun . "${SCRIPTDIR}/shfun" # shellcheck source=utils/shcontainer . "${SCRIPTDIR}/shcontainer" # shellcheck source=utils/shansible . "${SCRIPTDIR}/shansible" usage() { local prog="${0##*/}" cat </dev/null 2>&1 then [ ${SPLITS} -ne 0 ] && die -u "Can't define tests and use '-A'" ENABLED_TESTS+=($(basename "${test}" .yml)) else log error "Test not found: ${test}" fi done [ ${SPLITS} -eq 0 ] && [ ${#ENABLED_MODULES[@]} -eq 0 ] && [ ${#ENABLED_TESTS[@]} -eq 0 ] && die -u "No test defined." export STOP_CONTAINER FORCE_ENV STOP_VIRTUALENV ansible_interpreter # Ensure $python is set [ -z "${python}" ] && python="python3" log info "Controller Python executable: ${python}" ${python} --version # Prepare virtual environment start_virtual_environment log info "Installing dependencies from 'requirements-tests.txt'" pip install --upgrade -r "${TOPDIR}/requirements-tests.txt" [ -z "${SKIP_ANSIBLE}" ] && install_ansible "${ANSIBLE_VERSION:-"ansible-core"}" # 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}" -p "${ansible_interpreter}" -i "${IMAGE_TAG}" -n "${IPA_HOSTNAME}" -a "${scenario}" || die "Failed to setup test container" # run tests RESULT=0 export RUN_TESTS_IN_DOCKER=${engine} export IPA_SERVER_HOST="${scenario}" # Ensure proper ansible_python_interpreter is used by pytest. export IPA_PYTHON_PATH="${ansible_interpreter}" if [ ${SPLITS} -ne 0 ] then EXTRA_OPTIONS="${EXTRA_OPTIONS} --splits=${SPLITS} --group=${GROUP} --randomly-seed=${SEED}" log info "Running tests for group ${GROUP} of ${SPLITS} with seed ${SEED}" else # shellcheck disable=SC2086 joined="$(printf "%s," "${ENABLED_MODULES[@]}")" # shelcheck disable=SC2178 IPA_ENABLED_MODULES="${joined%,}" joined="$(printf "%s," "${ENABLED_TESTS[@]}")" # shelcheck disable=SC2178 IPA_ENABLED_TESTS="${joined%,}" export IPA_ENABLED_MODULES IPA_ENABLED_TESTS [ -n "${IPA_ENABLED_MODULES}" ] && log info "Test suites: ${IPA_ENABLED_MODULES}" [ -n "${IPA_ENABLED_TESTS}" ] && log info "Individual tests: ${IPA_ENABLED_TESTS}" fi IPA_VERBOSITY="${verbose}" [ -n "${IPA_VERBOSITY}" ] && export IPA_VERBOSITY # shellcheck disable=SC2086 if ! pytest -m "playbook" --verbose --color=yes --suppress-no-test-exit-code --junit-xml=TEST-results-group-${GROUP:-1}.xml ${EXTRA_OPTIONS} then RESULT=2 log error "Container not stopped for verification: ${scenario}" log info "Container: $(${engine} ps -f "name=${scenario}" --format "{{.Names}} - {{.ID}}")" fi [ -z "${CONTINUE_ON_ERROR}" ] && [ $RESULT -ne 0 ] && die "Stopping on test failure." # cleanup environment cleanup "${scenario}" "${engine}"