2016-06-02 06:08:14 +02:00
|
|
|
#!/bin/bash -eux
|
|
|
|
|
|
|
|
source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))")
|
|
|
|
|
2016-09-22 22:25:04 +02:00
|
|
|
test_image="${IMAGE:-ansible/ansible:centos7}"
|
2016-06-02 06:08:14 +02:00
|
|
|
test_privileged="${PRIVILEGED:-false}"
|
|
|
|
test_flags="${TEST_FLAGS:-}"
|
2016-09-22 22:25:04 +02:00
|
|
|
test_target="${TARGET:-all}"
|
2016-06-02 06:08:14 +02:00
|
|
|
test_ansible_dir="${TEST_ANSIBLE_DIR:-/root/ansible}"
|
2016-08-24 08:08:11 +02:00
|
|
|
test_python3="${PYTHON3:-}"
|
2016-06-02 06:08:14 +02:00
|
|
|
|
|
|
|
http_image="${HTTP_IMAGE:-ansible/ansible:httptester}"
|
|
|
|
|
2016-09-23 07:28:55 +02:00
|
|
|
# Keep the docker containers after tests complete.
|
|
|
|
# The default behavior is to always remove the containers.
|
|
|
|
# Set to "onfailure" to keep the containers only on test failure.
|
|
|
|
# Any other non-empty value will always keep the containers.
|
2016-06-02 06:08:14 +02:00
|
|
|
keep_containers="${KEEP_CONTAINERS:-}"
|
2016-09-23 07:28:55 +02:00
|
|
|
|
|
|
|
# Run the tests directly from the source directory shared with the container.
|
|
|
|
# The default behavior is to run the tests on a copy of the source.
|
|
|
|
# Copying the source isolates changes to the source between host and container.
|
|
|
|
# Set to any non-empty value to share the source.
|
|
|
|
share_source="${SHARE_SOURCE:-}"
|
2016-06-02 06:08:14 +02:00
|
|
|
|
2016-07-25 23:07:15 +02:00
|
|
|
# Force ansible color output by default.
|
|
|
|
# To disable color force mode use FORCE_COLOR=0
|
|
|
|
force_color="${FORCE_COLOR:-1}"
|
|
|
|
|
2016-06-02 06:08:14 +02:00
|
|
|
if [ "${SHIPPABLE_BUILD_DIR:-}" ]; then
|
|
|
|
host_shared_dir="/home/shippable/cache/build-${BUILD_NUMBER}"
|
|
|
|
controller_shared_dir="/home/shippable/cache/build-${BUILD_NUMBER}"
|
2016-09-23 07:28:55 +02:00
|
|
|
share_source=1
|
2016-06-02 06:08:14 +02:00
|
|
|
else
|
|
|
|
host_shared_dir="${source_root}"
|
|
|
|
controller_shared_dir=""
|
|
|
|
fi
|
|
|
|
|
2016-09-23 07:28:55 +02:00
|
|
|
if [ -z "${share_source}" ]; then
|
2016-06-30 00:09:40 +02:00
|
|
|
test_shared_dir="/shared"
|
2016-06-02 06:08:14 +02:00
|
|
|
else
|
|
|
|
test_shared_dir="${test_ansible_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
container_id=
|
|
|
|
httptester_id=
|
2016-09-22 21:42:55 +02:00
|
|
|
tests_completed=
|
2016-06-02 06:08:14 +02:00
|
|
|
|
|
|
|
function show_environment
|
|
|
|
{
|
|
|
|
docker ps
|
|
|
|
|
|
|
|
if [ -d /home/shippable/cache ]; then
|
|
|
|
ls -l /home/shippable/cache
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup
|
|
|
|
{
|
|
|
|
if [ "${controller_shared_dir}" ]; then
|
|
|
|
cp -av "${controller_shared_dir}/shippable" "${SHIPPABLE_BUILD_DIR}"
|
|
|
|
rm -rf "${controller_shared_dir}"
|
|
|
|
fi
|
|
|
|
|
2016-09-22 21:42:55 +02:00
|
|
|
if [ "${keep_containers}" == "onfailure" ] && [ "${tests_completed}" != "" ]; then
|
|
|
|
keep_containers=
|
|
|
|
fi
|
|
|
|
|
2016-06-02 06:08:14 +02:00
|
|
|
if [ "${keep_containers}" == "" ]; then
|
|
|
|
if [ "${container_id}" ]; then
|
|
|
|
docker rm -f "${container_id}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${httptester_id}" ]; then
|
|
|
|
docker rm -f "${httptester_id}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
show_environment
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT INT TERM
|
2016-06-14 03:06:55 +02:00
|
|
|
docker images ansible/ansible
|
2016-06-02 06:08:14 +02:00
|
|
|
show_environment
|
|
|
|
|
|
|
|
if [ "${controller_shared_dir}" ]; then
|
|
|
|
cp -a "${SHIPPABLE_BUILD_DIR}" "${controller_shared_dir}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
httptester_id=$(docker run -d "${http_image}")
|
|
|
|
container_id=$(docker run -d \
|
2016-07-25 23:07:15 +02:00
|
|
|
--env "ANSIBLE_FORCE_COLOR=${force_color}" \
|
2016-06-02 06:08:14 +02:00
|
|
|
-v "/sys/fs/cgroup:/sys/fs/cgroup:ro" \
|
|
|
|
-v "${host_shared_dir}:${test_shared_dir}" \
|
|
|
|
--link="${httptester_id}:ansible.http.tests" \
|
|
|
|
--link="${httptester_id}:sni1.ansible.http.tests" \
|
|
|
|
--link="${httptester_id}:sni2.ansible.http.tests" \
|
|
|
|
--link="${httptester_id}:fail.ansible.http.tests" \
|
|
|
|
--privileged="${test_privileged}" \
|
|
|
|
"${test_image}")
|
|
|
|
|
|
|
|
show_environment
|
|
|
|
|
2016-08-24 08:08:11 +02:00
|
|
|
if [ "${test_python3}" ]; then
|
|
|
|
docker exec "${container_id}" ln -s /usr/bin/python3 /usr/bin/python
|
|
|
|
docker exec "${container_id}" ln -s /usr/bin/pip3 /usr/bin/pip
|
|
|
|
|
|
|
|
skip_tags=$(tr '\n' ',' < "${source_root}/test/utils/shippable/python3-test-tag-blacklist.txt")
|
|
|
|
test_flags="--skip-tags ${skip_tags} ${test_flags}"
|
|
|
|
fi
|
|
|
|
|
2016-09-23 07:28:55 +02:00
|
|
|
if [ -z "${share_source}" ]; then
|
2016-06-02 06:08:14 +02:00
|
|
|
docker exec "${container_id}" cp -a "${test_shared_dir}" "${test_ansible_dir}"
|
|
|
|
fi
|
|
|
|
|
2016-09-01 00:16:15 +02:00
|
|
|
docker exec "${container_id}" \
|
|
|
|
pip install -r "${test_ansible_dir}/test/utils/shippable/integration-requirements.txt" --upgrade
|
|
|
|
|
2016-08-24 08:08:11 +02:00
|
|
|
if [ "${test_python3}" ]; then
|
|
|
|
docker exec "${container_id}" sed -i -f \
|
|
|
|
"${test_ansible_dir}/test/utils/shippable/python3-test-target-blacklist.txt" \
|
|
|
|
"${test_ansible_dir}/test/integration/Makefile"
|
|
|
|
fi
|
|
|
|
|
2016-06-02 06:08:14 +02:00
|
|
|
docker exec "${container_id}" mkdir -p "${test_shared_dir}/shippable/testresults"
|
|
|
|
docker exec "${container_id}" /bin/sh -c "cd '${test_ansible_dir}' && . hacking/env-setup && cd test/integration && \
|
|
|
|
JUNIT_OUTPUT_DIR='${test_shared_dir}/shippable/testresults' ANSIBLE_CALLBACK_WHITELIST=junit \
|
|
|
|
HTTPTESTER=1 TEST_FLAGS='${test_flags}' LC_ALL=en_US.utf-8 make ${test_target}"
|
2016-09-22 21:42:55 +02:00
|
|
|
|
|
|
|
tests_completed=1
|