Skip to content

Commit 240561c

Browse files
Merge pull request #143 from microsoft/psl-drop-quota-check-validation
chore: Drop quota check validation
2 parents b5d5989 + 1d1aa94 commit 240561c

File tree

5 files changed

+211
-398
lines changed

5 files changed

+211
-398
lines changed

azure.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ hooks:
2727
shell: sh
2828
run: >
2929
chmod u+r+x ./scripts/validate_model_deployment_quota.sh; chmod u+r+x ./scripts/validate_model_quota.sh; ./scripts/validate_model_deployment_quota.sh --SubscriptionId "$AZURE_SUBSCRIPTION_ID" --Location "${AZURE_AISERVICE_LOCATION:-japaneast}" --ModelsParameter "aiModelDeployments"
30-
interactive: true
30+
interactive: false
3131
continueOnError: false
3232

3333
windows:
3434
shell: pwsh
3535
run: >
3636
$location = if ($env:AZURE_AISERVICE_LOCATION) { $env:AZURE_AISERVICE_LOCATION } else { "japaneast" };
3737
./scripts/validate_model_deployment_quota.ps1 -SubscriptionId $env:AZURE_SUBSCRIPTION_ID -Location $location -ModelsParameter "aiModelDeployments"
38-
interactive: true
38+
interactive: false
3939
continueOnError: false

scripts/validate_model_deployment_quota.ps1

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,73 @@ param (
44
[string]$ModelsParameter
55
)
66

7-
$AiFoundryName = $env:AZURE_AIFOUNDRY_NAME
7+
# Read from environment variables (do not pass in azure.yaml)
8+
$AiServiceName = $env:AZURE_AISERVICE_NAME
89
$ResourceGroup = $env:AZURE_RESOURCE_GROUP
910

1011
# Validate required parameters
1112
$MissingParams = @()
13+
1214
if (-not $SubscriptionId) { $MissingParams += "SubscriptionId" }
1315
if (-not $Location) { $MissingParams += "Location" }
1416
if (-not $ModelsParameter) { $MissingParams += "ModelsParameter" }
1517

1618
if ($MissingParams.Count -gt 0) {
1719
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>"
20+
Write-Host "Usage: .\validate_model_deployment_quotas.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
1921
exit 1
2022
}
2123

22-
# Load model deployments from parameter file
24+
# Load main.parameters.json
2325
$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'"
26+
if (-not $JsonContent) {
27+
Write-Error "❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
2728
exit 1
2829
}
2930

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
31+
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value
32+
if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable])) {
33+
Write-Error "❌ ERROR: The specified property '$ModelsParameter' does not exist or is not an array."
34+
exit 1
3635
}
3736

38-
# Check if AI Foundry exists
39-
if ($AiFoundryName -and $ResourceGroup) {
37+
# Check if AI resource + all deployments already exist
38+
if ($AiServiceName -and $ResourceGroup) {
4039
$existing = az cognitiveservices account show `
41-
--name $AiFoundryName `
40+
--name $AiServiceName `
4241
--resource-group $ResourceGroup `
4342
--query "name" --output tsv 2>$null
4443

4544
if ($existing) {
46-
# adding into .env
47-
azd env set AZURE_AIFOUNDRY_NAME $existing | Out-Null
48-
49-
$deployedModelsOutput = az cognitiveservices account deployment list `
50-
--name $AiFoundryName `
45+
$deployedModels = az cognitiveservices account deployment list `
46+
--name $AiServiceName `
5147
--resource-group $ResourceGroup `
5248
--query "[].name" --output tsv 2>$null
5349

54-
$deployedModels = @()
55-
if ($deployedModelsOutput -is [string]) {
56-
$deployedModels += $deployedModelsOutput
57-
} elseif ($deployedModelsOutput) {
58-
$deployedModels = $deployedModelsOutput -split "`r?`n"
50+
$requiredDeployments = @()
51+
foreach ($deployment in $aiModelDeployments) {
52+
$requiredDeployments += $deployment.name
5953
}
6054

61-
$requiredDeployments = $aiModelDeployments | ForEach-Object { $_.name }
62-
$missingDeployments = $requiredDeployments | Where-Object { $_ -notin $deployedModels }
55+
$missingDeployments = @()
56+
foreach ($required in $requiredDeployments) {
57+
if ($deployedModels -notcontains $required) {
58+
$missingDeployments += $required
59+
}
60+
}
6361

6462
if ($missingDeployments.Count -eq 0) {
65-
Write-Host "ℹ️ AI Foundry '$AiFoundryName' exists and all required model deployments are already provisioned."
63+
Write-Host "ℹ️ Azure AI service '$AiServiceName' exists and all required model deployments are provisioned."
6664
Write-Host "⏭️ Skipping quota validation."
6765
exit 0
6866
} else {
69-
Write-Host "🔍 AI Foundry exists, but the following model deployments are missing: $($missingDeployments -join ', ')"
67+
Write-Host "🔍 AI service exists, but the following model deployments are missing: $($missingDeployments -join ', ')"
7068
Write-Host "➡️ Proceeding with quota validation for missing models..."
7169
}
7270
}
7371
}
7472

75-
# Run quota validation
73+
# Start quota validation
7674
az account set --subscription $SubscriptionId
7775
Write-Host "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
7876

@@ -84,24 +82,23 @@ foreach ($deployment in $aiModelDeployments) {
8482
$type = if ($env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE) { $env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $deployment.sku.name }
8583
$capacity = if ($env:AZURE_ENV_MODEL_CAPACITY) { $env:AZURE_ENV_MODEL_CAPACITY } else { $deployment.sku.capacity }
8684

87-
Write-Host ""
88-
Write-Host "🔍 Validating model deployment: $name ..."
85+
Write-Host "`n🔍 Validating model deployment: $name ..."
8986
& .\scripts\validate_model_quota.ps1 -Location $Location -Model $model -Capacity $capacity -DeploymentType $type
9087
$exitCode = $LASTEXITCODE
9188

9289
if ($exitCode -ne 0) {
9390
if ($exitCode -eq 2) {
94-
exit 1
91+
exit 1 # already printed, graceful
9592
}
9693
Write-Error "❌ ERROR: Quota validation failed for model deployment: $name"
9794
$QuotaAvailable = $false
9895
}
9996
}
10097

10198
if (-not $QuotaAvailable) {
102-
Write-Error "❌ ERROR: One or more model deployments failed quota validation."
99+
Write-Error "❌ ERROR: One or more model deployments failed validation."
103100
exit 1
104101
} else {
105102
Write-Host "✅ All model deployments passed quota validation successfully."
106103
exit 0
107-
}
104+
}

scripts/validate_model_deployment_quota.sh

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ while [[ $# -gt 0 ]]; do
2525
esac
2626
done
2727

28-
AIFOUNDRY_NAME="${AZURE_AIFOUNDRY_NAME}"
29-
RESOURCE_GROUP="${AZURE_RESOURCE_GROUP}"
30-
3128
# Validate required parameters
3229
MISSING_PARAMS=()
3330
[[ -z "$SUBSCRIPTION_ID" ]] && MISSING_PARAMS+=("SubscriptionId")
@@ -40,55 +37,51 @@ if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then
4037
exit 1
4138
fi
4239

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
49-
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)
54-
fi
55-
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)
40+
# Read from environment
41+
AISERVICE_NAME="${AZURE_AISERVICE_NAME}"
42+
RESOURCE_GROUP="${AZURE_RESOURCE_GROUP}"
6043

44+
# Check service and deployment existence
45+
if [[ -n "$AISERVICE_NAME" && -n "$RESOURCE_GROUP" ]]; then
46+
existing=$(az cognitiveservices account show --name "$AISERVICE_NAME" --resource-group "$RESOURCE_GROUP" --query "name" --output tsv 2>/dev/null)
6147
if [[ -n "$existing" ]]; then
62-
# adding into .env
63-
azd env set AZURE_AIFOUNDRY_NAME "$existing" > /dev/null
48+
echo "ℹ️ Found Azure AI service: $AISERVICE_NAME"
6449

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)
50+
existing_deployments=$(az cognitiveservices account deployment list --name "$AISERVICE_NAME" --resource-group "$RESOURCE_GROUP" --query "[].name" --output tsv 2>/dev/null)
7051

71-
required_models=$(jq -r ".parameters.$MODELS_PARAMETER.value[].name" ./infra/main.parameters.json)
52+
# Extract required model names
53+
required_models=$(jq -r ".parameters.$MODELS_PARAMETER.value[].name" ./infra/main.parameters.json 2>/dev/null)
7254

73-
missing_models=()
55+
if [[ -z "$required_models" ]]; then
56+
echo "❌ ERROR: Failed to extract required model names from main.parameters.json"
57+
exit 1
58+
fi
59+
60+
all_present=true
7461
for model in $required_models; do
7562
if ! grep -q -w "$model" <<< "$existing_deployments"; then
76-
missing_models+=("$model")
63+
all_present=false
64+
break
7765
fi
7866
done
7967

80-
if [[ ${#missing_models[@]} -eq 0 ]]; then
81-
echo "ℹ️ AI Foundry '$AIFOUNDRY_NAME' exists and all required model deployments are already provisioned."
68+
if [[ "$all_present" == "true" ]]; then
69+
echo "✅ All required model deployments already exist in AI service '$AISERVICE_NAME'."
8270
echo "⏭️ Skipping quota validation."
8371
exit 0
8472
else
85-
echo "🔍 AI Foundry exists, but the following model deployments are missing: ${missing_models[*]}"
86-
echo "➡️ Proceeding with quota validation for missing models..."
73+
echo "🔍 AI service exists but some model deployments are missing — proceeding with quota validation."
8774
fi
8875
fi
8976
fi
9077

91-
# Run quota validation
78+
# If we reach here, continue with normal quota checks
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
83+
fi
84+
9285
az account set --subscription "$SUBSCRIPTION_ID"
9386
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
9487

@@ -100,13 +93,13 @@ while IFS= read -r deployment; do
10093
type=${AZURE_ENV_MODEL_DEPLOYMENT_TYPE:-$(echo "$deployment" | jq -r '.sku.name')}
10194
capacity=${AZURE_ENV_MODEL_CAPACITY:-$(echo "$deployment" | jq -r '.sku.capacity')}
10295

103-
echo ""
10496
echo "🔍 Validating model deployment: $name ..."
10597
./scripts/validate_model_quota.sh --location "$LOCATION" --model "$model" --capacity "$capacity" --deployment-type "$type"
106-
exit_code=$?
10798

99+
exit_code=$?
108100
if [[ $exit_code -ne 0 ]]; then
109101
if [[ $exit_code -eq 2 ]]; then
102+
# Quota validation handled inside script — stop immediately
110103
exit 1
111104
fi
112105
echo "❌ ERROR: Quota validation failed for model deployment: $name"
@@ -115,9 +108,9 @@ while IFS= read -r deployment; do
115108
done <<< "$(echo "$aiModelDeployments")"
116109

117110
if [[ "$quotaAvailable" = false ]]; then
118-
echo "❌ ERROR: One or more model deployments failed quota validation."
111+
echo "❌ ERROR: One or more model deployments failed validation."
119112
exit 1
120113
else
121114
echo "✅ All model deployments passed quota validation successfully."
122115
exit 0
123-
fi
116+
fi

0 commit comments

Comments
 (0)