Skip to content

Commit 823f5db

Browse files
authored
Merge pull request #54 from KirtiWandhare/patch-4
#52 - Adding continue on Failure flag; #53 - Fixing RP registration loop
2 parents 40ea363 + ea4bcc5 commit 823f5db

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

CanaryValidator/Canary.Tests.ps1

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ param (
4343
[Parameter(ParameterSetName="default", Mandatory=$false)]
4444
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
4545
[ValidateNotNullOrEmpty()]
46-
[string]$ResourceLocation = "local"
46+
[string]$ResourceLocation = "local",
47+
[parameter(HelpMessage="Flag to cleanup resources after exception")]
48+
[Parameter(ParameterSetName="default", Mandatory=$false)]
49+
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
50+
[bool] $ContinueOnFailure = $false
4751
)
4852

4953
#Requires -Modules AzureRM
@@ -69,7 +73,7 @@ New-Item -Path $canaryUtilPath -ItemType Directory
6973
# Start Canary
7074
#
7175
$CanaryLogFile = $CanaryLogPath + "\Canary-Basic$((Get-Date).ToString("-yyMMdd-hhmmss")).log"
72-
Start-Scenario -Name 'Canary' -Type 'Basic' -LogFilename $CanaryLogFile
76+
Start-Scenario -Name 'Canary' -Type 'Basic' -LogFilename $CanaryLogFile -ContinueOnFailure $ContinueOnFailure
7377

7478
Invoke-Usecase -Name 'CreateAzureStackEnv' -Description "Create Azure Stack environment $EnvironmentName" -UsecaseBlock `
7579
{
@@ -161,7 +165,29 @@ if ($TenantAdminCredentials)
161165
}
162166
}
163167

164-
RegisterResourceProviders
168+
Invoke-Usecase -Name 'RegisterResourceProviders' -Description "Register resource providers" -UsecaseBlock `
169+
{
170+
Get-AzureRmResourceProvider -ListAvailable | Register-AzureRmResourceProvider -Force
171+
$sleepTime = 0
172+
while($true)
173+
{
174+
$sleepTime += 10
175+
Start-Sleep 10
176+
$requiredRPs = Get-AzureRmResourceProvider -ListAvailable | ? {$_.ProviderNamespace -in ("Microsoft.Storage", "Microsoft.Compute", "Microsoft.Network", "Microsoft.KeyVault")}
177+
$notRegistered = $requiredRPs | ? {$_.RegistrationState -ne "Registered"}
178+
$registered = $requiredRPs | ? {$_.RegistrationState -eq "Registered"}
179+
if (($sleepTime -ge 120) -and $notRegistered)
180+
{
181+
Get-AzureRmResourceProvider | Format-Table
182+
throw [System.Exception] "Resource providers did not get registered in time."
183+
}
184+
elseif ($registered.Count -eq $requiredRPs.Count)
185+
{
186+
break
187+
}
188+
}
189+
Get-AzureRmResourceProvider | Format-Table
190+
}
165191
}
166192

167193
Invoke-Usecase -Name 'CreateResourceGroupForUtilities' -Description "Create a resource group $CanaryUtilitiesRG for the placing the utility files" -UsecaseBlock `

CanaryValidator/Canary.Utilities.psm1

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
$Global:ContinueOnFailure = $false
12
$Global:JSONLogFile = "Run-Canary.JSON"
23
$Global:TxtLogFile = "AzureStackCanaryLog.Log"
34
$UseCase = @{}
@@ -107,7 +108,9 @@ function Start-Scenario
107108
[string]$Type,
108109
[parameter(Mandatory=$false)]
109110
[ValidateNotNullOrEmpty()]
110-
[string]$LogFilename
111+
[string]$LogFilename,
112+
[parameter(Mandatory=$false)]
113+
[bool] $ContinueOnFailure = $false
111114
)
112115

113116
if ($LogFileName)
@@ -130,6 +133,7 @@ function Start-Scenario
130133
"UseCases" = @()
131134
}
132135
$jsonReport | ConvertTo-Json -Depth 10 | Out-File -FilePath $Global:JSONLogFile
136+
$Global:ContinueOnFailure = $ContinueOnFailure
133137
}
134138

135139
function End-Scenario
@@ -171,7 +175,10 @@ function Invoke-Usecase
171175
{
172176
Log-Exception ($_.Exception)
173177
Log-Error ("###### [END] Usecase: $Name ###### [RESULT = FAIL] ######`n")
174-
throw $_.Exception
178+
if (-not $Global:ContinueOnFailure)
179+
{
180+
throw $_.Exception
181+
}
175182
}
176183
}
177184

@@ -454,20 +461,6 @@ function NewAzureStackDefaultQuotas
454461
$serviceQuotas
455462
}
456463

457-
function RegisterResourceProviders
458-
{
459-
Get-AzureRmResourceProvider -ListAvailable | Register-AzureRmResourceProvider -Force
460-
$requiredRPs = ("Microsoft.Storage", "Microsoft.Compute", "Microsoft.Network", "Microsoft.KeyVault")
461-
foreach ($rp in $requiredRPs)
462-
{
463-
while ((Get-AzureRmResourceProvider | Where-Object ProviderNamespace -eq $rp).RegistrationState -ne "Registered")
464-
{
465-
Start-Sleep -Seconds 10
466-
}
467-
}
468-
Get-AzureRmResourceProvider | Format-Table
469-
}
470-
471464
function NewAzureStackDSCScriptResource
472465
{
473466
[CmdletBinding()]

0 commit comments

Comments
 (0)