Skip to content

Commit 00b1b37

Browse files
Copilotpsah434
andcommitted
Fix VMSizes-Must-Match-Template to support nested outputs
Co-authored-by: psah434 <114955590+psah434@users.noreply.github.com>
1 parent e79c367 commit 00b1b37

File tree

5 files changed

+156
-5
lines changed

5 files changed

+156
-5
lines changed

arm-ttk/testcases/CreateUIDefinition/VMSizes-Must-Match-Template.test.ps1

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,41 @@ $MainTemplateParameters
2121
#Write-Warning "Skipping Test..."
2222
#break
2323

24+
# Helper function to recursively search for a pattern in nested objects
25+
function Find-OutputProperty {
26+
param(
27+
[Parameter(Mandatory=$true)]
28+
[PSObject]$Object,
29+
30+
[Parameter(Mandatory=$true)]
31+
[string]$Pattern,
32+
33+
[Parameter(Mandatory=$false)]
34+
[string]$PropertyName = $null
35+
)
36+
37+
foreach ($prop in $Object.psobject.properties) {
38+
$currentName = if ($PropertyName) { $PropertyName } else { $prop.Name }
39+
40+
if ($prop.Value -is [string] -and $prop.Value -like $Pattern) {
41+
# Found a matching string value
42+
return [PSCustomObject]@{
43+
Name = $currentName
44+
Value = $prop.Value
45+
}
46+
}
47+
elseif ($prop.Value -is [PSCustomObject] -or $prop.Value -is [System.Collections.Specialized.OrderedDictionary]) {
48+
# Recursively search nested objects
49+
$result = Find-OutputProperty -Object $prop.Value -Pattern $Pattern -PropertyName $currentName
50+
if ($result) {
51+
return $result
52+
}
53+
}
54+
}
55+
56+
return $null
57+
}
58+
2459
# First, find all size selectors in CreateUIDefinition.
2560
$sizeSelectors = $CreateUIDefinitionObject |
2661
Find-JsonContent -Key type -Value Microsoft.Compute.SizeSelector
@@ -42,11 +77,9 @@ foreach ($selector in $sizeSelectors) { # Then walk each selector,
4277
} else {
4378
"*basics(*$($controlName)*"
4479
}
45-
$theOutput = foreach ($out in $CreateUIDefinitionObject.parameters.outputs.psobject.properties) {
46-
if ($out.Value -like $lookingFor) {
47-
$out; break
48-
}
49-
}
80+
81+
# Use the helper function to recursively search for the pattern in outputs
82+
$theOutput = Find-OutputProperty -Object $CreateUIDefinitionObject.parameters.outputs -Pattern $lookingFor
5083

5184
if (-not $theOutput) {
5285
Write-Error "Could not find VM SizeSelector '$($selector.Name)' in outputs" -TargetObject $selector
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"parameters": {
4+
"clusters": {
5+
"type": "object"
6+
}
7+
},
8+
"resources": []
9+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
3+
"handler": "Microsoft.Azure.CreateUIDef",
4+
"version": "0.1.2-preview",
5+
"parameters": {
6+
"basics": [],
7+
"steps": [
8+
{
9+
"label": "Scheduler",
10+
"name": "scheduler",
11+
"bladeTitle": "Scheduler",
12+
"bladeSubtitle": "Configure Scheduler",
13+
"subLabel": {
14+
"preValidation": "Configure Scheduler",
15+
"postValidation": "Done"
16+
},
17+
"elements": [
18+
{
19+
"label": "Scheduler Section",
20+
"name": "schedulerSection",
21+
"type": "Microsoft.Common.Section",
22+
"elements": [
23+
{
24+
"label": "VM Size",
25+
"name": "vmsize",
26+
"toolTip": "Scheduler VM size",
27+
"type": "Microsoft.Compute.SizeSelector",
28+
"osPlatform": "Linux",
29+
"count": 1,
30+
"recommendedSizes": [
31+
"Standard_B1s",
32+
"Standard_B1ms"
33+
]
34+
}
35+
]
36+
}
37+
]
38+
}
39+
],
40+
"outputs": {
41+
"location": "[location()]",
42+
"clusters": {
43+
"schedulerNode": {
44+
"sku": "[steps('scheduler').schedulerSection.vmsize]"
45+
}
46+
}
47+
}
48+
}
49+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"parameters": {
4+
"clusters": {
5+
"type": "object"
6+
}
7+
},
8+
"resources": []
9+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
3+
"handler": "Microsoft.Azure.CreateUIDef",
4+
"version": "0.1.2-preview",
5+
"parameters": {
6+
"basics": [],
7+
"steps": [
8+
{
9+
"label": "Scheduler",
10+
"name": "scheduler",
11+
"bladeTitle": "Scheduler",
12+
"bladeSubtitle": "Configure Scheduler",
13+
"subLabel": {
14+
"preValidation": "Configure Scheduler",
15+
"postValidation": "Done"
16+
},
17+
"elements": [
18+
{
19+
"label": "Scheduler Section",
20+
"name": "schedulerSection",
21+
"type": "Microsoft.Common.Section",
22+
"elements": [
23+
{
24+
"label": "VM Size",
25+
"name": "vmsize",
26+
"toolTip": "Scheduler VM size",
27+
"type": "Microsoft.Compute.SizeSelector",
28+
"osPlatform": "Linux",
29+
"count": 1,
30+
"recommendedSizes": [
31+
"Standard_B1s",
32+
"Standard_B1ms"
33+
]
34+
}
35+
]
36+
}
37+
]
38+
}
39+
],
40+
"outputs": {
41+
"location": "[location()]",
42+
"clusters": {
43+
"slurm": {
44+
"schedulerNode": {
45+
"sku": "[steps('scheduler').schedulerSection.vmsize]"
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)