From ed906130290ea3793c7603adf926d69c4b16acee Mon Sep 17 00:00:00 2001 From: Alper Date: Tue, 22 Oct 2024 13:13:18 +0200 Subject: [PATCH] fixes for osb validation --- code/test/alper-test.sh | 43 ------------------------------- code/test/subscription-test.sh | 46 ++++++++++++++-------------------- 2 files changed, 19 insertions(+), 70 deletions(-) delete mode 100644 code/test/alper-test.sh diff --git a/code/test/alper-test.sh b/code/test/alper-test.sh deleted file mode 100644 index acc70cd..0000000 --- a/code/test/alper-test.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -validate_osb_registration() { - local BROKER_NAME="susaas-api-$CF_SPACE-$CF_ORG" - local MAX_ATTEMPTS=3 - local ATTEMPT=0 - local INTERVAL=5 # Time in seconds between attempts - local TIMEOUT=30 # Total timeout in seconds - local START_TIME=$(date +%s) - - echo "Validating OSB registration for $CF_APP_NAME..." - - while (( ATTEMPT < MAX_ATTEMPTS )); do - RESPONSE=$(btp --format json list services/offering --subaccount "$SUBACCOUNT_GUID" --fields-filter "name eq 'susaas-api-$CF_SPACE-$CF_ORG'") - - # Check if the response contains a valid offering - SERVICE_OFFERING_ID=$(echo "$RESPONSE" | jq -r '.[0].id') - IS_READY=$(echo "$RESPONSE" | jq -r '.[0].ready') - SERVICE_OFFERING_NAME=$(echo "$RESPONSE" | jq -r '.[0].metadata.displayName') - - if [[ "$SERVICE_OFFERING_ID" != "null" && "$IS_READY" == "true" ]]; then - echo "Service broker registration is successful. Offering Name: $SERVICE_OFFERING_NAME" - return 0 # Exit function on success - fi - - # Calculate elapsed time - local CURRENT_TIME=$(date +%s) - local ELAPSED_TIME=$(( CURRENT_TIME - START_TIME )) - - if (( ELAPSED_TIME >= TIMEOUT )); then - echo "Error: OSB registration validation timed out after $TIMEOUT seconds." - exit 1 - fi - - echo "Attempt $(( ATTEMPT + 1 )) failed. Retrying in $INTERVAL seconds..." - sleep "$INTERVAL" - (( ATTEMPT++ )) - done - - echo "Error: Service broker registration failed after $MAX_ATTEMPTS attempts." - exit 1 -} -validate_osb_registration \ No newline at end of file diff --git a/code/test/subscription-test.sh b/code/test/subscription-test.sh index 80bd7dc..edf89dd 100644 --- a/code/test/subscription-test.sh +++ b/code/test/subscription-test.sh @@ -193,44 +193,33 @@ check_subaccount_removal() { # Function to validate if the service broker registration is successful, with retry logic validate_osb_registration() { local BROKER_NAME="susaas-api-$CF_SPACE-$CF_ORG" - local MAX_ATTEMPTS=6 - local ATTEMPT=0 - local INTERVAL=5 # Time in seconds between attempts - local TIMEOUT=30 # Total timeout in seconds local START_TIME=$(date +%s) echo "Validating OSB registration for $BROKER_NAME..." - while (( ATTEMPT < MAX_ATTEMPTS )); do + while true; do + local CURRENT_TIME=$(date +%s) + local ELAPSED_TIME=$(( CURRENT_TIME - START_TIME )) + + if (( ELAPSED_TIME >= TIMEOUT )); then + echo "Error: Service Broker registration check timed out after $TIMEOUT seconds." + exit 1 + fi + RESPONSE=$(btp --format json list services/offering --subaccount "$SUBACCOUNT_GUID" --fields-filter "name eq 'susaas-api-$CF_SPACE-$CF_ORG'") - - # Check if the response contains a valid offering + # Check if the response contains a valid offering SERVICE_OFFERING_ID=$(echo "$RESPONSE" | jq -r '.[0].id') IS_READY=$(echo "$RESPONSE" | jq -r '.[0].ready') SERVICE_OFFERING_NAME=$(echo "$RESPONSE" | jq -r '.[0].metadata.displayName') - echo "Service Offering Name $SERVICE_OFFERING_NAME" - echo "Is ready:$IS_READY" + if [[ "$SERVICE_OFFERING_ID" != "null" && "$IS_READY" == "true" ]]; then - echo "Service broker registration is successful. Offering Name: $SERVICE_OFFERING_NAME" + echo "Service broker registration is successful. Offering ID: $SERVICE_OFFERING_ID" return 0 # Exit function on success fi - # Calculate elapsed time - local CURRENT_TIME=$(date +%s) - local ELAPSED_TIME=$(( CURRENT_TIME - START_TIME )) - - if (( ELAPSED_TIME >= TIMEOUT )); then - echo "Error: OSB registration validation timed out after $TIMEOUT seconds." - exit 1 - fi - - echo "Attempt $(( ATTEMPT + 1 )) failed. Retrying in $INTERVAL seconds..." - sleep "$INTERVAL" - (( ATTEMPT++ )) + echo "Service Broker is not yet registered. Checking again in $POLL_INTERVAL seconds..." + sleep "$POLL_INTERVAL" done - - echo "Error: Service broker registration failed after $MAX_ATTEMPTS attempts." - exit 1 } #!/bin/bash @@ -250,9 +239,11 @@ validate_common_db_entity() { exit 1 fi +echo "Service key GUID:$SERVICE_KEY_GUID" + echo "Fetching subdomain for subaccount GUID $SUBACCOUNT_GUID..." -SUBDOMAIN=$(btp --format json get accounts/subaccount $SUBACCOUNT_GUID | jq '.subdomain') +SUBDOMAIN=$(btp --format json get accounts/subaccount $SUBACCOUNT_GUID | jq -r '.subdomain') if [[ -z "$SUBDOMAIN" || "$SUBDOMAIN" == "null" ]]; then echo "Error: Failed to retrieve subdomain." @@ -271,7 +262,8 @@ if [[ -z "$CLIENT_ID" || -z "$CLIENT_SECRET" || -z "$OAUTH_URL" ]]; then exit 1 fi -echo "OAuth URL: $OAUTH_URL" +OAUTH_URL="https://$OAUTH_URL" +echo "Token URL:$OAUTH_URL" echo "Credentials for service key retrieved successfully." # Fetch the OAuth token