Skip to content

Commit 262fb56

Browse files
refactor the quota auto validation script
1 parent 0350fb4 commit 262fb56

3 files changed

Lines changed: 31 additions & 38 deletions

File tree

infra/main.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"sku": {
6565
"name": "GlobalStandard",
66-
"capacity": 200
66+
"capacity": 50
6767
}
6868
}
6969
]

scripts/validate_model_deployment_quota.ps1

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,40 @@ $MissingParams = @()
1212
if (-not $SubscriptionId) { $MissingParams += "SubscriptionId" }
1313
if (-not $Location) { $MissingParams += "Location" }
1414
if (-not $ModelsParameter) { $MissingParams += "ModelsParameter" }
15-
if (-not $AiFoundryName) { $MissingParams += "AZURE_AISERVICE_NAME" }
16-
if (-not $ResourceGroup) { $MissingParams += "AZURE_RESOURCE_GROUP" }
1715

1816
if ($MissingParams.Count -gt 0) {
1917
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
2018
exit 1
2119
}
2220

23-
# Load model deployment parameters
21+
# Load model deployments from parameter file
2422
$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json
2523
if (-not $JsonContent) {
2624
Write-Error "❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
2725
exit 1
2826
}
2927

3028
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value
31-
3229
if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable])) {
3330
Write-Error "❌ ERROR: The specified property '$ModelsParameter' does not exist or is not an array."
3431
exit 1
3532
}
3633

37-
# Check if AI Foundry and model deployments already exist
38-
$existing = az cognitiveservices account show `
39-
--name $AiFoundryName `
40-
--resource-group $ResourceGroup `
41-
--query "name" --output tsv 2>$null
34+
# Check if AI Foundry exists and has all required model deployments
35+
$existing = $null
36+
if ($AiFoundryName -and $ResourceGroup) {
37+
$existing = az cognitiveservices account show `
38+
--name $AiFoundryName `
39+
--resource-group $ResourceGroup `
40+
--query "name" --output tsv 2>$null
41+
}
4242

4343
if ($existing) {
4444
$deployedModelsOutput = az cognitiveservices account deployment list `
4545
--name $AiFoundryName `
4646
--resource-group $ResourceGroup `
4747
--query "[].name" --output tsv 2>$null
4848

49-
# Normalize output to array
5049
$deployedModels = @()
5150
if ($deployedModelsOutput -is [string]) {
5251
$deployedModels += $deployedModelsOutput
@@ -65,11 +64,9 @@ if ($existing) {
6564
Write-Host "🔍 AI Foundry exists, but the following model deployments are missing: $($missingDeployments -join ', ')"
6665
Write-Host "➡️ Proceeding with quota validation for missing models..."
6766
}
68-
} else {
69-
Write-Host "❌ AI Foundry '$AiFoundryName' not found. Proceeding with quota validation."
7067
}
7168

72-
# Run quota validation
69+
# Run quota validation for all models
7370
az account set --subscription $SubscriptionId
7471
Write-Host "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
7572

scripts/validate_model_deployment_quota.sh

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,33 @@ MISSING_PARAMS=()
3333
[[ -z "$SUBSCRIPTION_ID" ]] && MISSING_PARAMS+=("SubscriptionId")
3434
[[ -z "$LOCATION" ]] && MISSING_PARAMS+=("Location")
3535
[[ -z "$MODELS_PARAMETER" ]] && MISSING_PARAMS+=("ModelsParameter")
36-
[[ -z "$AIFOUNDRY_NAME" ]] && MISSING_PARAMS+=("AZURE_AIFOUNDRY_NAME")
37-
[[ -z "$RESOURCE_GROUP" ]] && MISSING_PARAMS+=("AZURE_RESOURCE_GROUP")
3836

3937
if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then
4038
echo "❌ ERROR: Missing required parameters: ${MISSING_PARAMS[*]}"
4139
echo "Usage: $0 --SubscriptionId <SUBSCRIPTION_ID> --Location <LOCATION> --ModelsParameter <MODELS_PARAMETER>"
4240
exit 1
4341
fi
4442

45-
# Check if AI Foundry exists and has required deployments
46-
existing=$(az cognitiveservices account show --name "$AIFOUNDRY_NAME" --resource-group "$RESOURCE_GROUP" --query "name" --output tsv 2>/dev/null)
47-
if [[ -n "$existing" ]]; then
48-
echo "ℹ️ Found AI Foundry: $AIFOUNDRY_NAME"
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
48+
fi
4949

50-
existing_deployments=$(az cognitiveservices account deployment list --name "$AIFOUNDRY_NAME" --resource-group "$RESOURCE_GROUP" --query "[].name" --output tsv 2>/dev/null)
50+
# Check if AI Foundry exists and has all required model deployments
51+
existing=""
52+
if [[ -n "$AIFOUNDRY_NAME" && -n "$RESOURCE_GROUP" ]]; then
53+
existing=$(az cognitiveservices account show --name "$AIFOUNDRY_NAME" --resource-group "$RESOURCE_GROUP" --query "name" --output tsv 2>/dev/null)
54+
fi
5155

52-
required_models=$(jq -r ".parameters.$MODELS_PARAMETER.value[].name" ./infra/main.parameters.json 2>/dev/null)
56+
if [[ -n "$existing" ]]; then
57+
existing_deployments=$(az cognitiveservices account deployment list \
58+
--name "$AIFOUNDRY_NAME" \
59+
--resource-group "$RESOURCE_GROUP" \
60+
--query "[].name" --output tsv 2>/dev/null)
5361

54-
if [[ -z "$required_models" ]]; then
55-
echo "❌ ERROR: Failed to extract required model names from main.parameters.json"
56-
exit 1
57-
fi
62+
required_models=$(jq -r ".parameters.$MODELS_PARAMETER.value[].name" ./infra/main.parameters.json)
5863

5964
all_present=true
6065
for model in $required_models; do
@@ -69,19 +74,11 @@ if [[ -n "$existing" ]]; then
6974
echo "⏭️ Skipping quota validation."
7075
exit 0
7176
else
72-
echo "🔍 AI Foundry exists, but some model deployments are missing — proceeding with quota validation."
77+
echo "🔍 Some model deployments are missing — proceeding with quota validation."
7378
fi
74-
else
75-
echo "❌ AI Foundry '$AIFOUNDRY_NAME' not found. Proceeding with quota validation."
76-
fi
77-
78-
# Load deployment definitions
79-
aiModelDeployments=$(jq -c ".parameters.$MODELS_PARAMETER.value[]" ./infra/main.parameters.json)
80-
if [[ $? -ne 0 ]]; then
81-
echo "❌ ERROR: Failed to parse main.parameters.json. Ensure jq is installed and the JSON is valid."
82-
exit 1
8379
fi
8480

81+
# Run quota validation
8582
az account set --subscription "$SUBSCRIPTION_ID"
8683
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
8784

@@ -95,11 +92,10 @@ while IFS= read -r deployment; do
9592

9693
echo "🔍 Validating model deployment: $name ..."
9794
./scripts/validate_model_quota.sh --location "$LOCATION" --model "$model" --capacity "$capacity" --deployment-type "$type"
98-
9995
exit_code=$?
96+
10097
if [[ $exit_code -ne 0 ]]; then
10198
if [[ $exit_code -eq 2 ]]; then
102-
# Quota validation handled inside script — stop immediately
10399
exit 1
104100
fi
105101
echo "❌ ERROR: Quota validation failed for model deployment: $name"

0 commit comments

Comments
 (0)