Skip to content

Commit 03269f5

Browse files
author
Shreyas-Microsoft
committed
remove the quota check validation
1 parent b5d5989 commit 03269f5

4 files changed

Lines changed: 182 additions & 495 deletions

File tree

scripts/validate_model_deployment_quota.ps1

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,58 @@ param (
44
[string]$ModelsParameter
55
)
66

7-
$AiFoundryName = $env:AZURE_AIFOUNDRY_NAME
8-
$ResourceGroup = $env:AZURE_RESOURCE_GROUP
9-
10-
# Validate required parameters
7+
# Verify all required parameters are provided
118
$MissingParams = @()
12-
if (-not $SubscriptionId) { $MissingParams += "SubscriptionId" }
13-
if (-not $Location) { $MissingParams += "Location" }
14-
if (-not $ModelsParameter) { $MissingParams += "ModelsParameter" }
159

16-
if ($MissingParams.Count -gt 0) {
17-
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
18-
Write-Host "Usage: validate_model_deployment_quota.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
19-
exit 1
10+
if (-not $SubscriptionId) {
11+
$MissingParams += "subscription"
2012
}
2113

22-
# Load model deployments from parameter file
23-
$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json
24-
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value
25-
if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable])) {
26-
Write-Error "❌ ERROR: Failed to parse main.parameters.json or missing '$ModelsParameter'"
27-
exit 1
14+
if (-not $Location) {
15+
$MissingParams += "location"
2816
}
2917

30-
# Try to discover AI Foundry name if not set
31-
if (-not $AiFoundryName -and $ResourceGroup) {
32-
$AiFoundryName = az cognitiveservices account list `
33-
--resource-group $ResourceGroup `
34-
--query "sort_by([?kind=='AIServices'], &name)[0].name" `
35-
-o tsv 2>$null
18+
if (-not $ModelsParameter) {
19+
$MissingParams += "models-parameter"
3620
}
3721

38-
# Check if AI Foundry exists
39-
if ($AiFoundryName -and $ResourceGroup) {
40-
$existing = az cognitiveservices account show `
41-
--name $AiFoundryName `
42-
--resource-group $ResourceGroup `
43-
--query "name" --output tsv 2>$null
44-
45-
if ($existing) {
46-
# adding into .env
47-
azd env set AZURE_AIFOUNDRY_NAME $existing | Out-Null
22+
if ($MissingParams.Count -gt 0) {
23+
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
24+
Write-Host "Usage: .\validate_model_deployment_quotas.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
25+
exit 1
26+
}
4827

49-
$deployedModelsOutput = az cognitiveservices account deployment list `
50-
--name $AiFoundryName `
51-
--resource-group $ResourceGroup `
52-
--query "[].name" --output tsv 2>$null
28+
$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json
5329

54-
$deployedModels = @()
55-
if ($deployedModelsOutput -is [string]) {
56-
$deployedModels += $deployedModelsOutput
57-
} elseif ($deployedModelsOutput) {
58-
$deployedModels = $deployedModelsOutput -split "`r?`n"
59-
}
30+
if (-not $JsonContent) {
31+
Write-Error "❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
32+
exit 1
33+
}
6034

61-
$requiredDeployments = $aiModelDeployments | ForEach-Object { $_.name }
62-
$missingDeployments = $requiredDeployments | Where-Object { $_ -notin $deployedModels }
35+
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value
6336

64-
if ($missingDeployments.Count -eq 0) {
65-
Write-Host "ℹ️ AI Foundry '$AiFoundryName' exists and all required model deployments are already provisioned."
66-
Write-Host "⏭️ Skipping quota validation."
67-
exit 0
68-
} else {
69-
Write-Host "🔍 AI Foundry exists, but the following model deployments are missing: $($missingDeployments -join ', ')"
70-
Write-Host "➡️ Proceeding with quota validation for missing models..."
71-
}
72-
}
37+
if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable])) {
38+
Write-Error "❌ ERROR: The specified property $ModelsParameter does not exist or is not an array."
39+
exit 1
7340
}
7441

75-
# Run quota validation
7642
az account set --subscription $SubscriptionId
7743
Write-Host "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
7844

7945
$QuotaAvailable = $true
80-
8146
foreach ($deployment in $aiModelDeployments) {
8247
$name = if ($env:AZURE_ENV_MODEL_NAME) { $env:AZURE_ENV_MODEL_NAME } else { $deployment.name }
8348
$model = if ($env:AZURE_ENV_MODEL_NAME) { $env:AZURE_ENV_MODEL_NAME } else { $deployment.model.name }
8449
$type = if ($env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE) { $env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $deployment.sku.name }
8550
$capacity = if ($env:AZURE_ENV_MODEL_CAPACITY) { $env:AZURE_ENV_MODEL_CAPACITY } else { $deployment.sku.capacity }
8651

87-
Write-Host ""
88-
Write-Host "🔍 Validating model deployment: $name ..."
52+
Write-Host "`n🔍 Validating model deployment: $name ..."
8953
& .\scripts\validate_model_quota.ps1 -Location $Location -Model $model -Capacity $capacity -DeploymentType $type
9054
$exitCode = $LASTEXITCODE
9155

9256
if ($exitCode -ne 0) {
9357
if ($exitCode -eq 2) {
58+
# Quota error already printed inside the script, exit gracefully without reprinting
9459
exit 1
9560
}
9661
Write-Error "❌ ERROR: Quota validation failed for model deployment: $name"
@@ -99,9 +64,9 @@ foreach ($deployment in $aiModelDeployments) {
9964
}
10065

10166
if (-not $QuotaAvailable) {
102-
Write-Error "❌ ERROR: One or more model deployments failed quota validation."
67+
Write-Error "❌ ERROR: One or more model deployments failed validation."
10368
exit 1
10469
} else {
10570
Write-Host "✅ All model deployments passed quota validation successfully."
10671
exit 0
107-
}
72+
}
Lines changed: 40 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,87 @@
11
#!/bin/bash
2-
32
SUBSCRIPTION_ID=""
43
LOCATION=""
54
MODELS_PARAMETER=""
65

76
while [[ $# -gt 0 ]]; do
87
case "$1" in
9-
--SubscriptionId)
8+
--subscription)
109
SUBSCRIPTION_ID="$2"
1110
shift 2
1211
;;
13-
--Location)
12+
--location)
1413
LOCATION="$2"
1514
shift 2
1615
;;
17-
--ModelsParameter)
16+
--models-parameter)
1817
MODELS_PARAMETER="$2"
1918
shift 2
2019
;;
2120
*)
22-
echo "❌ ERROR: Unknown option: $1"
21+
echo "Unknown option: $1"
2322
exit 1
2423
;;
2524
esac
2625
done
2726

28-
AIFOUNDRY_NAME="${AZURE_AIFOUNDRY_NAME}"
29-
RESOURCE_GROUP="${AZURE_RESOURCE_GROUP}"
30-
31-
# Validate required parameters
27+
# Verify all required parameters are provided and echo missing ones
3228
MISSING_PARAMS=()
33-
[[ -z "$SUBSCRIPTION_ID" ]] && MISSING_PARAMS+=("SubscriptionId")
34-
[[ -z "$LOCATION" ]] && MISSING_PARAMS+=("Location")
35-
[[ -z "$MODELS_PARAMETER" ]] && MISSING_PARAMS+=("ModelsParameter")
3629

37-
if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then
38-
echo "❌ ERROR: Missing required parameters: ${MISSING_PARAMS[*]}"
39-
echo "Usage: $0 --SubscriptionId <SUBSCRIPTION_ID> --Location <LOCATION> --ModelsParameter <MODELS_PARAMETER>"
40-
exit 1
30+
if [[ -z "$SUBSCRIPTION_ID" ]]; then
31+
MISSING_PARAMS+=("subscription")
4132
fi
4233

43-
# Load model definitions
44-
aiModelDeployments=$(jq -c ".parameters.$MODELS_PARAMETER.value[]" ./infra/main.parameters.json 2>/dev/null)
45-
if [[ $? -ne 0 || -z "$aiModelDeployments" ]]; then
46-
echo "❌ ERROR: Failed to parse main.parameters.json or missing '$MODELS_PARAMETER'"
47-
exit 1
34+
if [[ -z "$LOCATION" ]]; then
35+
MISSING_PARAMS+=("location")
4836
fi
4937

50-
# Try to discover AI Foundry name if not set
51-
if [[ -z "$AIFOUNDRY_NAME" && -n "$RESOURCE_GROUP" ]]; then
52-
AIFOUNDRY_NAME=$(az cognitiveservices account list --resource-group "$RESOURCE_GROUP" \
53-
--query "sort_by([?kind=='AIServices'], &name)[0].name" -o tsv 2>/dev/null)
38+
if [[ -z "$MODELS_PARAMETER" ]]; then
39+
MISSING_PARAMS+=("models-parameter")
5440
fi
5541

56-
# Check if AI Foundry exists
57-
if [[ -n "$AIFOUNDRY_NAME" && -n "$RESOURCE_GROUP" ]]; then
58-
existing=$(az cognitiveservices account show --name "$AIFOUNDRY_NAME" \
59-
--resource-group "$RESOURCE_GROUP" --query "name" --output tsv 2>/dev/null)
60-
61-
if [[ -n "$existing" ]]; then
62-
# adding into .env
63-
azd env set AZURE_AIFOUNDRY_NAME "$existing" > /dev/null
64-
65-
# Check model deployments
66-
existing_deployments=$(az cognitiveservices account deployment list \
67-
--name "$AIFOUNDRY_NAME" \
68-
--resource-group "$RESOURCE_GROUP" \
69-
--query "[].name" --output tsv 2>/dev/null)
42+
if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then
43+
echo "❌ ERROR: Missing required parameters: ${MISSING_PARAMS[*]}"
44+
echo "Usage: $0 --subscription <SUBSCRIPTION_ID> --location <LOCATION> --models-parameter <MODELS_PARAMETER>"
45+
exit 1
46+
fi
7047

71-
required_models=$(jq -r ".parameters.$MODELS_PARAMETER.value[].name" ./infra/main.parameters.json)
48+
aiModelDeployments=$(jq -c ".parameters.$MODELS_PARAMETER.value[]" ./infra/main.parameters.json)
7249

73-
missing_models=()
74-
for model in $required_models; do
75-
if ! grep -q -w "$model" <<< "$existing_deployments"; then
76-
missing_models+=("$model")
77-
fi
78-
done
79-
80-
if [[ ${#missing_models[@]} -eq 0 ]]; then
81-
echo "ℹ️ AI Foundry '$AIFOUNDRY_NAME' exists and all required model deployments are already provisioned."
82-
echo "⏭️ Skipping quota validation."
83-
exit 0
84-
else
85-
echo "🔍 AI Foundry exists, but the following model deployments are missing: ${missing_models[*]}"
86-
echo "➡️ Proceeding with quota validation for missing models..."
87-
fi
88-
fi
50+
if [ $? -ne 0 ]; then
51+
echo "Error: Failed to parse main.parameters.json. Ensure jq is installed and the JSON file is valid."
52+
exit 1
8953
fi
9054

91-
# Run quota validation
9255
az account set --subscription "$SUBSCRIPTION_ID"
9356
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
9457

9558
quotaAvailable=true
9659

9760
while IFS= read -r deployment; do
98-
name=${AZURE_ENV_MODEL_NAME:-$(echo "$deployment" | jq -r '.name')}
99-
model=${AZURE_ENV_MODEL_NAME:-$(echo "$deployment" | jq -r '.model.name')}
100-
type=${AZURE_ENV_MODEL_DEPLOYMENT_TYPE:-$(echo "$deployment" | jq -r '.sku.name')}
101-
capacity=${AZURE_ENV_MODEL_CAPACITY:-$(echo "$deployment" | jq -r '.sku.capacity')}
61+
name=${AZURE_ENV_MODEL_NAME:-$(echo "$deployment" | jq -r '.name')}
62+
model=${AZURE_ENV_MODEL_NAME:-$(echo "$deployment" | jq -r '.model.name')}
63+
type=${AZURE_ENV_MODEL_DEPLOYMENT_TYPE:-$(echo "$deployment" | jq -r '.sku.name')}
64+
capacity=${AZURE_ENV_MODEL_CAPACITY:-$(echo "$deployment" | jq -r '.sku.capacity')}
10265

103-
echo ""
10466
echo "🔍 Validating model deployment: $name ..."
105-
./scripts/validate_model_quota.sh --location "$LOCATION" --model "$model" --capacity "$capacity" --deployment-type "$type"
106-
exit_code=$?
67+
./scripts/validate_model_quota.sh --location "$LOCATION" --model "$model" --capacity $capacity --deployment-type $type
10768

108-
if [[ $exit_code -ne 0 ]]; then
109-
if [[ $exit_code -eq 2 ]]; then
110-
exit 1
111-
fi
112-
echo "❌ ERROR: Quota validation failed for model deployment: $name"
113-
quotaAvailable=false
69+
# Check if the script failed
70+
exit_code=$?
71+
if [ $exit_code -ne 0 ]; then
72+
if [ $exit_code -eq 2 ]; then
73+
# Skip printing any quota validation error — already handled inside the validation script
74+
exit 1
75+
fi
76+
echo "❌ ERROR: Quota validation failed for model deployment: $name"
77+
quotaAvailable=false
11478
fi
11579
done <<< "$(echo "$aiModelDeployments")"
11680

117-
if [[ "$quotaAvailable" = false ]]; then
118-
echo "❌ ERROR: One or more model deployments failed quota validation."
119-
exit 1
81+
if [ "$quotaAvailable" = false ]; then
82+
echo "❌ ERROR: One or more model deployments failed validation."
83+
exit 1
12084
else
121-
echo "✅ All model deployments passed quota validation successfully."
122-
exit 0
123-
fi
85+
echo "✅ All model deployments passed quota validation successfully."
86+
exit 0
87+
fi

0 commit comments

Comments
 (0)