diff options
author | Matt Clay <matt@mystile.com> | 2016-08-01 22:46:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-01 22:46:37 +0200 |
commit | e2602e9be001a6e20712b7d64028236ea91ccc2d (patch) | |
tree | 5941fd55e03d4d402fcadc15532d85a00078c0fc /test/utils/shippable/remote.sh | |
parent | Download files from S3 to improve reliability. (#16891) (diff) | |
download | ansible-e2602e9be001a6e20712b7d64028236ea91ccc2d.tar.xz ansible-e2602e9be001a6e20712b7d64028236ea91ccc2d.zip |
Add FreeBSD to Shippable CI. (#16883)
Diffstat (limited to 'test/utils/shippable/remote.sh')
-rwxr-xr-x | test/utils/shippable/remote.sh | 138 |
1 files changed, 121 insertions, 17 deletions
diff --git a/test/utils/shippable/remote.sh b/test/utils/shippable/remote.sh index 4926906a8e..d21642b707 100755 --- a/test/utils/shippable/remote.sh +++ b/test/utils/shippable/remote.sh @@ -1,5 +1,7 @@ #!/bin/bash -eux +set -o pipefail + source_root=$(python -c "from os import path; print(path.abspath(path.join(path.dirname('$0'), '../../..')))") test_flags="${TEST_FLAGS:-}" @@ -8,50 +10,152 @@ test_version="${VERSION}" test_target=(${TARGET}) +instance_id="${INSTANCE_ID:-}" +start_instance= + +if [ "${instance_id}" == "" ]; then + instance_id=$(python -c 'import uuid; print(uuid.uuid4())') + start_instance=1 +fi + +# Set this to a non-empty value to skip immediate termination of the remote instance after tests finish. +# The remote instance will still be auto-terminated when the remote time limit is reached. +keep_instance="${KEEP_INSTANCE:-}" + # Force ansible color output by default. # To disable color force mode use FORCE_COLOR=0 force_color="${FORCE_COLOR:-1}" +if [ "${SHIPPABLE:-}" = "true" ]; then + test_auth="shippable" +else + test_auth="remote" +fi + env -instance_id=$("${source_root}/test/utils/shippable/ansible-core-ci" -v \ - start shippable "${test_platform}" "${test_version}") +case "${test_platform}" in + "windows") + args="" + ;; + *) + ssh_key="${HOME}/.ssh/id_rsa" + args="--public-key=${ssh_key}.pub" + if [ ! -f "${ssh_key}.pub" ]; then + ssh-keygen -q -t rsa -N '' -f "${ssh_key}" + fi + ;; +esac -pip install -r "${source_root}/test/utils/shippable/remote-requirements.txt" --upgrade -pip list +pre_cleanup= function cleanup { - "${source_root}/test/utils/shippable/ansible-core-ci" -v stop "${instance_id}" + if [ "${pre_cleanup}" != '' ]; then + "${pre_cleanup}" + fi + + if [ "${keep_instance}" = '' ]; then + "${source_root}/test/utils/shippable/ansible-core-ci" -v stop "${instance_id}" + fi + + echo "instance_id: ${instance_id}" } trap cleanup EXIT INT TERM +if [ ${start_instance} ]; then + # shellcheck disable=SC2086 + "${source_root}/test/utils/shippable/ansible-core-ci" -v \ + start --id "${instance_id}" "${test_auth}" "${test_platform}" "${test_version}" ${args} +fi + +pip install -r "${source_root}/test/utils/shippable/remote-requirements.txt" --upgrade +pip list + cd "${source_root}" source hacking/env-setup cd test/integration -inventory_template="${source_root}/test/integration/inventory.winrm.template" -inventory_file="${source_root}/test/integration/inventory.winrm" +case "${test_platform}" in + "windows") + inventory_template="${source_root}/test/integration/inventory.winrm.template" + inventory_file="${source_root}/test/integration/inventory.winrm" + ping_module="win_ping" + ping_host="windows" + test_function="test_windows" + ;; + *) + inventory_template="${source_root}/test/integration/inventory.remote.template" + inventory_file="${source_root}/test/integration/inventory.remote" + ping_module="ping" + ping_host="remote" + test_function="test_remote" + ;; +esac "${source_root}/test/utils/shippable/ansible-core-ci" -v \ get "${instance_id}" \ --template "${inventory_template}" \ > "${inventory_file}" \ -# hack to make sure windows instance is responding before beginning tests -n=20 +# hack to make sure instance is responding before beginning tests +n=60 for i in $(seq 1 ${n}); do echo "Verifying host is responding ($i of $n)" - if ANSIBLE_FORCE_COLOR="${force_color}" ansible -m win_ping -i "${inventory_file}" windows; then + if \ + ANSIBLE_SSH_ARGS='' \ + ANSIBLE_HOST_KEY_CHECKING=False \ + ANSIBLE_FORCE_COLOR="${force_color}" \ + ansible -m "${ping_module}" -i "${inventory_file}" "${ping_host}"; then break fi - sleep 3 + sleep 5 done -JUNIT_OUTPUT_DIR="${source_root}/shippable/testresults" \ - ANSIBLE_FORCE_COLOR="${force_color}" \ - ANSIBLE_CALLBACK_WHITELIST=junit \ - TEST_FLAGS="${test_flags}" \ - LC_ALL=en_US.utf-8 \ - make "${test_target[@]}" +test_windows() { + JUNIT_OUTPUT_DIR="${source_root}/shippable/testresults" \ + ANSIBLE_FORCE_COLOR="${force_color}" \ + ANSIBLE_CALLBACK_WHITELIST=junit \ + TEST_FLAGS="${test_flags}" \ + LC_ALL=en_US.utf-8 \ + make "${test_target[@]}" +} + +test_remote() { + endpoint=$("${source_root}/test/utils/shippable/ansible-core-ci" get \ + "${instance_id}" \ + --template <(echo "@ansible_user@@ansible_host")) + +( +cat <<EOF +env \ +REPOSITORY_URL='${REPOSITORY_URL:-}' \ +PULL_REQUEST='${PULL_REQUEST:-}' \ +BRANCH='${BRANCH:-}' \ +COMMIT='${COMMIT:-}' \ +FORCE_COLOR='${force_color}' \ +TARGET='${test_target[*]}' \ +TEST_FLAGS='${test_flags}' \ +/bin/sh -e /tmp/remote-integration.sh +EOF +) > /tmp/remote-script.sh + +( +cat <<EOF +put "${source_root}/test/utils/shippable/remote-integration.sh" "/tmp/remote-integration.sh" +put "/tmp/remote-script.sh" "/tmp/remote-script.sh" +EOF +) | sftp -b - -o StrictHostKeyChecking=no "${endpoint}" + + pre_cleanup=test_remote_cleanup + + ssh "${endpoint}" \ + "su -l root -c 'chmod +x /tmp/remote-script.sh; /tmp/remote-script.sh'" +} + +test_remote_cleanup() { + scp -r "${endpoint}:/tmp/shippable" "${source_root}" +} + +"${test_function}" |