Skip to content

Commit

Permalink
add osb registration verification
Browse files Browse the repository at this point in the history
  • Loading branch information
alperdedeoglu committed Oct 19, 2024
1 parent e9fdd43 commit 9e42fd2
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions code/test/subscription-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,53 @@ check_subaccount_removal() {
done
}

# Function to validate if the service broker registration is successful, with retry logic
validate_osb_registration() {
local CF_APP_NAME="susaas-api-$CF_SPACE-$CF_ORG"
local MAX_ATTEMPTS=3
local ATTEMPT=0
local INTERVAL=5 # Time in seconds between attempts
local TIMEOUT=15 # 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 '$CF_APP_NAME'")

# 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
}

# Main script execution
btp_login
create_subaccount
check_subaccount_status
subscribe_to_application
validate_osb_registration
unsubscribe_from_application
delete_subaccount

delete_subaccount

0 comments on commit 9e42fd2

Please sign in to comment.