Enable color output from integration tests in Docker containers (#16660)

Enable color output from integration tests in Docker containers:

* In run_tests.sh when output is attached to a terminal.
* In shippable/integration.sh using force mode (can be disabled).

Also fix blocks tests to work with or without color output
This commit is contained in:
Gennady Trafimenkov 2016-07-26 01:07:15 +04:00 committed by Matt Clay
parent 7e54c9a468
commit ad24f2d206
3 changed files with 18 additions and 4 deletions

View file

@ -186,12 +186,14 @@ blocks: setup
rm -f block_test.out
# run the test and check to make sure the right number of completions was logged
ansible-playbook -vv -e outputdir=$(TEST_DIR) test_blocks/main.yml | tee block_test.out
[ "$$(grep 'TEST COMPLETE' block_test.out | wc -l)" = "$$(egrep '^[0-9]+ plays in' block_test.out | cut -f1 -d' ')" ]
sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' block_test.out >block_test_wo_colors.out
[ "$$(grep 'TEST COMPLETE' block_test.out | wc -l)" = "$$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
# cleanup the output log again, to make sure the test is clean
rm -f block_test.out
rm -f block_test.out block_test_wo_colors.out
# run test with free strategy and again count the completions
ansible-playbook -vv -e outputdir=$(TEST_DIR) test_blocks/main.yml -e test_strategy=free | tee block_test.out
[ "$$(grep 'TEST COMPLETE' block_test.out | wc -l)" = "$$(egrep '^[0-9]+ plays in' block_test.out | cut -f1 -d' ')" ]
sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' block_test.out >block_test_wo_colors.out
[ "$$(grep 'TEST COMPLETE' block_test.out | wc -l)" = "$$(egrep '^[0-9]+ plays in' block_test_wo_colors.out | cut -f1 -d' ')" ]
cloud: amazon rackspace azure

View file

@ -30,7 +30,14 @@ else
fi
export C_NAME="testAbull_$$_$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)"
docker pull ansible/ansible:${TARGET}
docker run -d --volume="${PWD}:/root/ansible:Z" $LINKS --name "${C_NAME}" --env HTTPTESTER=1 ${TARGET_OPTIONS:=''} ansible/ansible:${TARGET} > /tmp/cid_${TARGET}
# enable colors if output is going to a terminal
COLOR_SETTINGS=""
if [ -t 1 ]; then
COLOR_SETTINGS="--env TERM=$TERM"
fi
docker run -d --volume="${PWD}:/root/ansible:Z" $LINKS --name "${C_NAME}" $COLOR_SETTINGS --env HTTPTESTER=1 ${TARGET_OPTIONS:=''} ansible/ansible:${TARGET} > /tmp/cid_${TARGET}
docker exec -ti $(cat /tmp/cid_${TARGET}) /bin/sh -c "export TEST_FLAGS='${TEST_FLAGS:-''}'; cd /root/ansible; . hacking/env-setup; (cd test/integration; LC_ALL=en_US.utf-8 make ${MAKE_TARGET:-})"
docker kill $(cat /tmp/cid_${TARGET})

View file

@ -13,6 +13,10 @@ http_image="${HTTP_IMAGE:-ansible/ansible:httptester}"
keep_containers="${KEEP_CONTAINERS:-}"
copy_source="${COPY_SOURCE:-}"
# Force ansible color output by default.
# To disable color force mode use FORCE_COLOR=0
force_color="${FORCE_COLOR:-1}"
if [ "${SHIPPABLE_BUILD_DIR:-}" ]; then
host_shared_dir="/home/shippable/cache/build-${BUILD_NUMBER}"
controller_shared_dir="/home/shippable/cache/build-${BUILD_NUMBER}"
@ -69,6 +73,7 @@ fi
httptester_id=$(docker run -d "${http_image}")
container_id=$(docker run -d \
--env "ANSIBLE_FORCE_COLOR=${force_color}" \
-v "/sys/fs/cgroup:/sys/fs/cgroup:ro" \
-v "${host_shared_dir}:${test_shared_dir}" \
--link="${httptester_id}:ansible.http.tests" \