Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefajers authored Jun 12, 2024
1 parent f3fdd4d commit 2b2da13
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/tests/integration/Repository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Describe "Repository" {
$script:resourceGroupParallelDeploy = (Get-AzResourceGroup | Where-Object ResourceGroupName -eq "ParallelDeploy-azopsrg")
$script:roleAssignments = (Get-AzRoleAssignment -ObjectId "023e7c1c-1fa4-4818-bb78-0a9c5e8b0217" | Where-Object { $_.Scope -eq "/subscriptions/$script:subscriptionId" -and $_.RoleDefinitionId -eq "acdd72a7-3385-48ef-bd42-f606fba81ae7" })
$script:policyExemptions = Get-AzPolicyExemption -Name "PolicyExemptionTest" -Scope "/subscriptions/$script:subscriptionId"
$script:routeTable = (Get-AzResource -Name "RouteTable" -ResourceGroupName $($script:resourceGroup).ResourceGroupName)
$script:routeTable = (Get-AzResource -Name "RouteTable" -ResourceGroupName $script:resourceGroup.ResourceGroupName)
$script:policyAssignmentsDeletion = Get-AzPolicyAssignment -Name "TestPolicyAssignmentDeletion" -Scope "/subscriptions/$script:subscriptionId/resourceGroups/$($script:resourceGroupCustomDeletion.ResourceGroupName)"
$script:ruleCollectionGroups = (Get-AzResource -ExpandProperties -Name "TestPolicy" -ResourceGroupName $($script:resourceGroup).ResourceGroupName).Properties.ruleCollectionGroups.id.split("/")[-1]
$script:logAnalyticsWorkspace = (Get-AzResource -Name "thisisalongloganalyticsworkspacename123456789011121314151617181" -ResourceGroupName $($script:resourceGroup).ResourceGroupName)
Expand Down Expand Up @@ -1162,7 +1162,7 @@ Describe "Repository" {
)
{Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw
Start-Sleep -Seconds 5
$script:bicepMultiParamPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroup).ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "rtmultibasex*"}
$script:bicepMultiParamPathDeployment = Get-AzResource -ResourceGroupName $script:resourceGroup.ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "rtmultibasex*"}
$script:bicepMultiParamPathDeployment.Count | Should -Be 2
}
#endregion
Expand All @@ -1178,7 +1178,7 @@ Describe "Repository" {
)
{Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw
Start-Sleep -Seconds 5
$script:bicepRepeatSuffixPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroup).ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "rtsuffix*"}
$script:bicepRepeatSuffixPathDeployment = Get-AzResource -ResourceGroupName $script:resourceGroup.ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "rtsuffix*"}
$script:bicepRepeatSuffixPathDeployment.Count | Should -Be 2
Set-PSFConfig -FullName AzOps.Core.MultipleTemplateParameterFileSuffix -Value ".x"
}
Expand Down Expand Up @@ -1214,11 +1214,31 @@ Describe "Repository" {
)
{Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw
Start-Sleep -Seconds 5
$script:deployAllRtParamPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroup).ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "deployallrtbasex*"}
$script:deployAllRtParamPathDeployment = Get-AzResource -ResourceGroupName $script:resourceGroup.ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "deployallrtbasex*"}
$script:deployAllRtParamPathDeployment.Count | Should -Be 2
}
#endregion

#region Bicep template with change, AzOps set to resolve corresponding parameter files and create multiple deployments [3] and avoid [1] decoy
It "Deploy Bicep template with change, AzOps set to resolve corresponding parameter files and create multiple deployments [3] and avoid [1] decoy" {
Set-PSFConfig -FullName AzOps.Core.AllowMultipleTemplateParameterFiles -Value $true
Set-PSFConfig -FullName AzOps.Core.DeployAllMultipleTemplateParameterFiles -Value $true
$script:deployAllRtFilesPath = Get-ChildItem -Path "$($global:testRoot)/templates/deployallrt.westeurope*" | Copy-Item -Destination $script:resourceGroupDirectory -PassThru -Force
$script:deployAllRt2FilesPath = Get-ChildItem -Path "$($global:testRoot)/templates/deployallrt2.westeurope.bicep" | Copy-Item -Destination $script:resourceGroupDirectory -PassThru -Force
$script:decoyRtFilesPath = Get-ChildItem -Path "$($global:testRoot)/templates/decoy.westeurope*" | Copy-Item -Destination $script:resourceGroupDirectory -PassThru -Force
$changeSet = @(
"A`t$($script:deployAllRtFilesPath.FullName[0])",
"A`t$($script:deployAllRt2FilesPath.FullName)"
)
$testFiles = Invoke-AzOpsPush -ChangeSet $changeSet
$? | Should -Be $true
$testFiles.Count | Should -Be 3
Start-Sleep -Seconds 5
$script:deployAllRtDeployment = Get-AzResource -ResourceGroupName $script:resourceGroup.ResourceGroupName -ResourceType 'Microsoft.Network/routeTables' | Where-Object {$_.name -like "deployallrtwex*" -or $_.name -like "deployallrt2wex*"}
$script:deployAllRtDeployment.Count | Should -Be 3
}
#endregion

#region Multiple deployments to test parallel deployment logic
It "Deploy parallel storage accounts and compare to serial timing" {
Set-PSFConfig -FullName AzOps.Core.AllowMultipleTemplateParameterFiles -Value $true
Expand All @@ -1232,7 +1252,7 @@ Describe "Repository" {
)
{Invoke-AzOpsPush -ChangeSet $changeSet} | Should -Not -Throw
Start-Sleep -Seconds 30
$script:deployAllStaParamPathDeployment = Get-AzResource -ResourceGroupName $($script:resourceGroupParallelDeploy).ResourceGroupName -ResourceType 'Microsoft.Storage/storageAccounts'
$script:deployAllStaParamPathDeployment = Get-AzResource -ResourceGroupName $script:resourceGroupParallelDeploy.ResourceGroupName -ResourceType 'Microsoft.Storage/storageAccounts'
$script:deployAllStaParamPathDeployment.Count | Should -Be 4
$query = "resourcechanges | where resourceGroup =~ '$($($script:resourceGroupParallelDeploy).ResourceGroupName)' and properties.targetResourceType == 'microsoft.storage/storageaccounts' and properties.changeType == 'Create' | extend changeTime=todatetime(properties.changeAttributes.timestamp), targetResourceId=tostring(properties.targetResourceId) | summarize arg_max(changeTime, *) by targetResourceId | project changeTime, targetResourceId, properties.changeType, properties.targetResourceType | order by changeTime asc"
$createTime = Search-AzGraph -Query $query -Subscription $script:subscriptionId
Expand Down
12 changes: 12 additions & 0 deletions src/tests/templates/decoy.westeurope.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param name string
param location string = resourceGroup().location

resource symbolicname 'Microsoft.Network/routeTables@2023-04-01' = {
name: name
location: location
properties: {
disableBgpRoutePropagation: false
routes: [
]
}
}
9 changes: 9 additions & 0 deletions src/tests/templates/decoy.westeurope.x123.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "decoywex123"
}
}
}
12 changes: 12 additions & 0 deletions src/tests/templates/deployallrt.westeurope.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param name string
param location string = resourceGroup().location

resource symbolicname 'Microsoft.Network/routeTables@2023-04-01' = {
name: name
location: location
properties: {
disableBgpRoutePropagation: false
routes: [
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "deployallrtwex123"
}
}
}
3 changes: 3 additions & 0 deletions src/tests/templates/deployallrt.westeurope.xabc.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using './deployallrt.westeurope.bicep'

param name = toLower('deployallrtwexabc')
12 changes: 12 additions & 0 deletions src/tests/templates/deployallrt2.westeurope.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param name string = 'deployallrt2wex123'
param location string = resourceGroup().location

resource symbolicname 'Microsoft.Network/routeTables@2023-04-01' = {
name: name
location: location
properties: {
disableBgpRoutePropagation: false
routes: [
]
}
}

0 comments on commit 2b2da13

Please sign in to comment.