From 29d50bbf09a685617b2405d4c7015fd7481b7b94 Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Tue, 31 Jan 2017 17:10:32 +0000 Subject: [PATCH] Globally redirect stdout to stderr, except when echo'ing "export HOSTS=...". This should make development easier by allowing developers to set HOSTS in their calling shell, and re-use the value for this env. var. when calling individual test scripts, e.g.: ``` cd test eval $(./run-integration-tests.sh setup) ./200_dns_test.sh ``` --- test/run-integration-tests.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index 8d9a19e9..c4c65a72 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -310,7 +310,24 @@ function end() { echo "> Build took $(date -u -d @$(($(date +%s) - begin)) +"%T")." } +function echo_export_hosts() { + exec 1>&111 + # Print a command to set HOSTS in the calling script, so that subsequent calls to + # test scripts can point to the right testing machines while developing: + echo "export HOSTS=\"$HOSTS\"" + exec 1>&2 +} + function main() { + # Keep a reference to stdout in another file descriptor (FD #111), and then globally redirect all stdout to stderr. + # This is so that HOSTS can be eval'ed in the calling script using: + # $ eval $(./run-integration-tests.sh [provision|configure|setup]) + # and ultimately subsequent calls to test scripts can point to the right testing machines during development. + if [ "$1" == "provision" ] || [ "$1" == "configure" ] || [ "$1" == "setup" ]; then + exec 111>&1 # 111 ought to match the file descriptor used in echo_export_hosts. + exec 1>&2 + fi + begin=$(date +%s) trap end EXIT @@ -330,16 +347,19 @@ function main() { provision) provision on "$PROVIDER" + echo_export_hosts ;; configure) provision on "$PROVIDER" # Vagrant and Terraform do not provision twice if VMs are already provisioned, so we just set environment variables. configure "$ssh_user" "$ssh_hosts" "${ssh_port:-22}" "$ssh_id_file" + echo_export_hosts ;; setup) provision on "$PROVIDER" # Vagrant and Terraform do not provision twice if VMs are already provisioned, so we just set environment variables. "$DIR/setup.sh" + echo_export_hosts ;; test)