From e7de79b5836a96b2e7e7fe4d93143333ee67f1e6 Mon Sep 17 00:00:00 2001 From: Gareth Clay Date: Thu, 5 Oct 2023 17:46:53 +0100 Subject: [PATCH] Retry CF API login * Sometimes cf login fails - this WIP will perform a retry * But sometimes login succeeds and then a later command fails. We might need to extract the retry into a function and use it on every cf command? --- ci/scripts/acceptance-tests.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ci/scripts/acceptance-tests.sh b/ci/scripts/acceptance-tests.sh index 43a4634..152be86 100755 --- a/ci/scripts/acceptance-tests.sh +++ b/ci/scripts/acceptance-tests.sh @@ -53,7 +53,22 @@ EOF prepare_cf() { local -r test_instances_org="$DEFAULT_ORG-instances" - cf login -a "$CF_API_HOST" -u "$CF_USERNAME" -p "$CF_PASSWORD" -o system --skip-ssl-validation + local api_available="false" + local max_attempts=5 + local attempts=1 + local sleep_seconds=30 + while [ "$api_available" == "false" ] && [ $attempts -le $max_attempts ]; do + echo "Attempting to log in ($attempts/$max_attempts)" + cf login -a "$CF_API_HOST" -u "$CF_USERNAME" -p "$CF_PASSWORD" -o system --skip-ssl-validation + + if [ $? ]; then + api_available="true" + else + echo "API not ready yet; sleeping for ${sleep_seconds}s..." + attempts=$((attempts + 1)) + sleep ${sleep_seconds} + fi + done cf create-org "$DEFAULT_ORG" cf create-space "$DEFAULT_SPACE" -o "$DEFAULT_ORG"