From b81a47649e07c9eb1c3062a59bb61294d00e70ea Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 16 Apr 2018 16:19:37 +0100 Subject: [PATCH] tests: use non-root SSH user to connect to Docker image in ansible_test. --- .travis/ansible_tests.sh | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.travis/ansible_tests.sh b/.travis/ansible_tests.sh index 1f810469..5328b9e1 100755 --- a/.travis/ansible_tests.sh +++ b/.travis/ansible_tests.sh @@ -6,6 +6,12 @@ TMPDIR="/tmp/ansible-tests-$$" ANSIBLE_VERSION="${ANSIBLE_VERSION:-2.4.3.0}" MITOGEN_TEST_DISTRO="${MITOGEN_TEST_DISTRO:-debian}" +export PYTHONPATH="${PYTHONPATH}:${TRAVIS_BUILD_DIR}" + +# SSH passes these through to the container when run interactively, causing +# stdout to get messed up with libc warnings. +unset LANG LC_ALL + function on_exit() { rm -rf "$TMPDIR" @@ -17,7 +23,14 @@ mkdir "$TMPDIR" echo travis_fold:start:docker_setup -docker run --rm --detach --name=target d2mw/mitogen-${MITOGEN_TEST_DISTRO}-test /bin/sleep 86400 +DOCKER_HOSTNAME="$(python ${TRAVIS_BUILD_DIR}/tests/show_docker_hostname.py)" + +docker run \ + --rm \ + --detach \ + --publish 0.0.0.0:2201:22/tcp \ + --name=target \ + d2mw/mitogen-${MITOGEN_TEST_DISTRO}-test echo travis_fold:end:docker_setup @@ -25,9 +38,15 @@ echo travis_fold:start:job_setup pip install -U ansible=="${ANSIBLE_VERSION}" cd ${TRAVIS_BUILD_DIR}/tests/ansible -cat >> ${TMPDIR}/hosts <<-EOF -target ansible_connection=docker ansible_python_interpreter=/usr/bin/python2.7 -EOF +echo \ + target \ + ansible_host=$DOCKER_HOSTNAME \ + ansible_port=2201 \ + ansible_python_interpreter=/usr/bin/python2.7 \ + ansible_user=mitogen__has_sudo_pubkey \ + ansible_become_pass=has_sudo_pubkey_password \ + ansible_ssh_private_key_file=${TRAVIS_BUILD_DIR}/tests/data/docker/mitogen__has_sudo_pubkey.key \ + >> ${TMPDIR}/hosts echo travis_fold:end:job_setup