From b9f16d5015b6fccb4b4eb146dc49d08b7ab751bd Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Sun, 3 May 2020 22:40:12 -0400 Subject: [PATCH] Add a 600s timeout when creating enable-ssh-admin workflow If enable-ssh-admin.sh workflow fails, the script was looping forever, because it only checks if the workflow is SUCCESSFUL. Now, we have a timeout of 500 seconds and when it reaches it, it'll stop and print a debug message. Note: we're using ENABLE_SSH_ADMIN_TIMEOUT variable which can be overriden when calling the script; the default value was taken from tripleoclient/constants. Change-Id: Ie183321bc23164745237d7036885f6e6dcfef859 Closes-Bug: #1876646 (cherry picked from commit b3127ac3f17d61e8bf6cfd43b05a4a2f31f7939f) --- deployed-server/scripts/enable-ssh-admin.sh | 30 ++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/deployed-server/scripts/enable-ssh-admin.sh b/deployed-server/scripts/enable-ssh-admin.sh index 772ee83cae..bfc663576b 100755 --- a/deployed-server/scripts/enable-ssh-admin.sh +++ b/deployed-server/scripts/enable-ssh-admin.sh @@ -13,6 +13,8 @@ SSH_TIMEOUT_OPTIONS=${SSH_TIMEOUT_OPTIONS:-"-o ConnectionAttempts=6 -o ConnectTi SSH_HOSTKEY_OPTIONS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" SHORT_TERM_KEY_COMMENT="TripleO split stack short term key" SLEEP_TIME=5 +# The default is defined in tripleoclient/constants.py +ENABLE_SSH_ADMIN_TIMEOUT=${ENABLE_SSH_ADMIN_TIMEOUT:-"600"} # needed to handle where python lives function get_python() { @@ -34,8 +36,24 @@ function overcloud_ssh_key_json { function workflow_finished { local execution_id="$1" - openstack workflow execution show -f shell $execution_id | grep 'state="SUCCESS"' > /dev/null -} + counter=$(( $ENABLE_SSH_ADMIN_TIMEOUT / $SLEEP_TIME )) + + while [ $counter -gt 0 ] + do + RESULT=$(openstack workflow execution show -f value -c state $execution_id) + if [ "$RESULT" == "ERROR" ]; then + echo "Workflow $execution_id finished with error. Check mistral logs." + return 1 + elif [ "$RESULT" == "SUCCESS" ]; then + echo "Workflow $execution_id finished with success." + return 0 + else + sleep $SLEEP_TIME + fi + counter=$(( $counter - 1 )) + done + echo "Workflow $execution_id did not finish after $ENABLE_SSH_ADMIN_TIMEOUT seconds." + return 1 function generate_short_term_keys { local tmpdir=$(mktemp -d) @@ -78,10 +96,10 @@ if [ -z "$EXECUTION_ID" ]; then fi echo -n "Waiting for the workflow execution to finish (id $EXECUTION_ID)." -while ! workflow_finished $EXECUTION_ID; do - sleep $SLEEP_TIME - echo -n . -done +if ! workflow_finished $EXECUTION_ID; then + exit 1 +fi + echo # newline after the previous dots for HOST in $OVERCLOUD_HOSTS; do