Skip to content

Commit 779c460

Browse files
authored
Adding capabilities to list the available Canary use cases and also provide an exclusion list (#185)
* Add capability to list available usecases, and also provide an exclusion list of usecases during execution * bug fixes for listavailable * Readme updates with listavailable and exclusionlist parameters details * Update README
1 parent 839f537 commit 779c460

3 files changed

Lines changed: 144 additions & 21 deletions

File tree

CanaryValidator/Canary.Tests.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ param (
9595
[Parameter(ParameterSetName="default", Mandatory=$false)]
9696
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
9797
[ValidateNotNullOrEmpty()]
98-
[string]$CanaryLogFileName = "Canary-Basic-$((Get-Date).Ticks).log"
98+
[string]$CanaryLogFileName = "Canary-Basic-$((Get-Date).Ticks).log",
99+
[parameter(HelpMessage="List of usecases to be excluded from execution")]
100+
[Parameter(ParameterSetName="default", Mandatory=$false)]
101+
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
102+
[string[]]$ExclusionList = @(),
103+
[parameter(HelpMessage="Lists the available usecases in Canary")]
104+
[Parameter(ParameterSetName="listavl", Mandatory=$true)]
105+
[ValidateNotNullOrEmpty()]
106+
[switch]$ListAvailable
99107
)
100108

101109
#Requires -Modules AzureRM
102110
#Requires -RunAsAdministrator
103-
Import-Module -Name $PSScriptRoot\Canary.Utilities.psm1 -Force
111+
Import-Module -Name $PSScriptRoot\Canary.Utilities.psm1 -Force -DisableNameChecking
104112
Import-Module -Name $PSScriptRoot\..\Connect\AzureStack.Connect.psm1 -Force
105113
Import-Module -Name $PSScriptRoot\..\Infrastructure\AzureStack.Infra.psm1 -Force
106114
Import-Module -Name $PSScriptRoot\..\ComputeAdmin\AzureStack.ComputeAdmin.psm1 -Force
@@ -134,15 +142,15 @@ while ($runCount -le $NumberOfIterations)
134142
#
135143
# Start Canary
136144
#
145+
if($ListAvailable){$listAvl = $true} else{$listAvl = $false}
137146
$CanaryLogFileName = [IO.Path]::GetFileNameWithoutExtension($tmpLogname) + "-$runCount" + [IO.Path]::GetExtension($tmpLogname)
138147
$CanaryLogFile = Join-Path -Path $CanaryLogPath -ChildPath $CanaryLogFileName
139-
140-
Start-Scenario -Name 'Canary' -Type 'Basic' -LogFilename $CanaryLogFile -ContinueOnFailure $ContinueOnFailure
148+
Start-Scenario -Name 'Canary' -Type 'Basic' -LogFilename $CanaryLogFile -ContinueOnFailure $ContinueOnFailure -ListAvailable $listAvl -ExclusionList $ExclusionList
141149

142150
$SvcAdminEnvironmentName = $EnvironmentName + "-SVCAdmin"
143151
$TntAdminEnvironmentName = $EnvironmentName + "-Tenant"
144152

145-
if(-not $EnvironmentDomainFQDN)
153+
if((-not $EnvironmentDomainFQDN) -and (-not $listAvl))
146154
{
147155
$endptres = Invoke-RestMethod "${AdminArmEndpoint}/metadata/endpoints?api-version=1.0" -ErrorAction Stop
148156
$EnvironmentDomainFQDN = $endptres.portalEndpoint
@@ -251,12 +259,12 @@ while ($runCount -le $NumberOfIterations)
251259

252260
Invoke-Usecase -Name 'ListUpdatesResourceProviderInfo' -Description "List URP information like summary of updates available, update to be applied, last update applied etc." -UsecaseBlock `
253261
{
254-
Invoke-Usecase -Name 'GetAzureStackUpdateSummary' -Description "List summary of updates status" -UsecaseBlock `
262+
Invoke-Usecase -Name 'GetAzureStackUpdateSummary' -Description "List summary of updates status" -UsecaseBlock `
255263
{
256264
Get-AzSUpdateSummary -TenantID $TenantID -AzureStackCredentials $ServiceAdminCredentials -EnvironmentName $SvcAdminEnvironmentName -region $ResourceLocation
257265
}
258266

259-
Invoke-Usecase -Name 'GetAzureStackUpdateToApply' -Description "List all updates that can be applied" -UsecaseBlock `
267+
Invoke-Usecase -Name 'GetAzureStackUpdateToApply' -Description "List all updates that can be applied" -UsecaseBlock `
260268
{
261269
Get-AzSUpdate -TenantID $TenantID -AzureStackCredentials $ServiceAdminCredentials -EnvironmentName $SvcAdminEnvironmentName -region $ResourceLocation
262270
}
@@ -893,7 +901,10 @@ while ($runCount -le $NumberOfIterations)
893901

894902
End-Scenario
895903
$runCount += 1
896-
Get-CanaryResult
904+
if (-not $ListAvailable)
905+
{
906+
Get-CanaryResult
907+
}
897908
}
898909

899910
if ($NumberOfIterations -gt 1)

CanaryValidator/Canary.Utilities.psm1

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
$Global:ContinueOnFailure = $false
2-
$Global:JSONLogFile = "Run-Canary.JSON"
3-
$Global:TxtLogFile = "AzureStackCanaryLog.Log"
4-
$Global:wttLogFileName= ""
1+
$Global:ContinueOnFailure = $false
2+
$Global:JSONLogFile = "Run-Canary.JSON"
3+
$Global:TxtLogFile = "AzureStackCanaryLog.Log"
4+
$Global:wttLogFileName = ""
5+
$Global:listAvailableUsecases = $false
6+
$Global:exclusionList = @()
57
if (Test-Path -Path "$PSScriptRoot\..\WTTLog.ps1")
68
{
79
Import-Module -Name "$PSScriptRoot\..\WTTLog.ps1" -Force
@@ -161,7 +163,11 @@ function Start-Scenario
161163
[ValidateNotNullOrEmpty()]
162164
[string]$LogFilename,
163165
[parameter(Mandatory=$false)]
164-
[bool] $ContinueOnFailure = $false
166+
[bool]$ContinueOnFailure = $false,
167+
[parameter(Mandatory=$false)]
168+
[bool]$ListAvailable = $false,
169+
[parameter(Mandatory=$false)]
170+
[string[]]$ExclusionList
165171
)
166172

167173
if ($LogFileName)
@@ -181,14 +187,25 @@ function Start-Scenario
181187
{
182188
OpenWTTLogger $Global:wttLogFileName
183189
}
184-
185-
New-Item -Path $Global:JSONLogFile -Type File -Force
186-
New-Item -Path $Global:TxtLogFile -Type File -Force
187-
$jsonReport = @{
188-
"Scenario" = ($Name + "-" + $Type)
189-
"UseCases" = @()
190-
}
191-
$jsonReport | ConvertTo-Json -Depth 10 | Out-File -FilePath $Global:JSONLogFile
190+
if ($ListAvailable)
191+
{
192+
$Global:listAvailableUsecases = $true
193+
}
194+
if ($ExclusionList)
195+
{
196+
$Global:exclusionList = $ExclusionList
197+
}
198+
if (-not $ListAvailable)
199+
{
200+
New-Item -Path $Global:JSONLogFile -Type File -Force
201+
New-Item -Path $Global:TxtLogFile -Type File -Force
202+
$jsonReport = @{
203+
"Scenario" = ($Name + "-" + $Type)
204+
"UseCases" = @()
205+
}
206+
$jsonReport | ConvertTo-Json -Depth 10 | Out-File -FilePath $Global:JSONLogFile
207+
}
208+
192209
$Global:ContinueOnFailure = $ContinueOnFailure
193210
}
194211

@@ -214,6 +231,31 @@ function Invoke-Usecase
214231
[ValidateNotNullOrEmpty()]
215232
[ScriptBlock]$UsecaseBlock
216233
)
234+
235+
if ($Global:listAvailableUsecases)
236+
{
237+
$parentUsecase = $Name
238+
if ((Get-PSCallStack)[1].Arguments.Contains($parentUsecase))
239+
{
240+
" `t"*([math]::Floor((Get-PSCallStack).Count/3)) + "|--" + $Name
241+
}
242+
else
243+
{
244+
245+
"`t" + $Name
246+
}
247+
if ($UsecaseBlock.ToString().Contains("Invoke-Usecase"))
248+
{
249+
Invoke-Command -ScriptBlock $UsecaseBlock -ErrorAction SilentlyContinue
250+
}
251+
return
252+
}
253+
254+
if (($Global:exclusionList).Contains($Name))
255+
{
256+
Log-Info ("Skipping Usecase: $Name")
257+
return
258+
}
217259
Log-Info ("###### [START] Usecase: $Name ######`n")
218260
if ($Global:wttLogFileName)
219261
{

CanaryValidator/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,76 @@ $ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Ser
4040
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
4141
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds
4242
```
43+
44+
# To list the usecases in Canary
45+
```powershell
46+
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
47+
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
48+
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
49+
.\Canary.Tests.ps1 -ListAvailable
50+
Sample output:
51+
PS C:\AzureStack-Tools\CanaryValidator> .\Canary.Tests.ps1 -ListAvailable
52+
CreateAdminAzureStackEnv
53+
LoginToAzureStackEnvAsSvcAdmin
54+
SelectDefaultProviderSubscription
55+
ListFabricResourceProviderInfo
56+
|--GetAzureStackInfraRole
57+
|--GetAzureStackInfraRoleInstance
58+
|--GetAzureStackLogicalNetwork
59+
|--GetAzureStackStorageCapacity
60+
|--GetAzureStackStorageShare
61+
|--GetAzureStackScaleUnit
62+
|--GetAzureStackScaleUnitNode
63+
|--GetAzureStackIPPool
64+
|--GetAzureStackMacPool
65+
|--GetAzureStackGatewayPool
66+
|--GetAzureStackSLBMux
67+
|--GetAzureStackGateway
68+
ListHealthResourceProviderAlerts
69+
|--GetAzureStackAlert
70+
ListUpdatesResourceProviderInfo
71+
|--GetAzureStackUpdateSummary
72+
|--GetAzureStackUpdateToApply
73+
CreateResourceGroupForUtilities
74+
CreateStorageAccountForUtilities
75+
CreateStorageContainerForUtilities
76+
CreateDSCScriptResourceUtility
77+
CreateCustomScriptResourceUtility
78+
CreateDataDiskForVM
79+
UploadUtilitiesToBlobStorage
80+
CreateKeyVaultStoreForCertSecret
81+
CreateResourceGroupForVMs
82+
DeployARMTemplate
83+
QueryTheVMsDeployed
84+
CheckVMCommunicationPreVMReboot
85+
AddDatadiskToVMWithPrivateIP
86+
|--StopDeallocateVMWithPrivateIPBeforeAddingDatadisk
87+
|--AddTheDataDiskToVMWithPrivateIP
88+
|--StartVMWithPrivateIPAfterAddingDatadisk
89+
ApplyDataDiskCheckCustomScriptExtensionToVMWithPrivateIP
90+
|--CheckForExistingCustomScriptExtensionOnVMWithPrivateIP
91+
|--ApplyCustomScriptExtensionToVMWithPrivateIP
92+
RestartVMWithPublicIP
93+
StopDeallocateVMWithPrivateIP
94+
StartVMWithPrivateIP
95+
CheckVMCommunicationPostVMReboot
96+
CheckExistenceOfScreenShotForVMWithPrivateIP
97+
EnumerateAllResources
98+
DeleteVMWithPrivateIP
99+
DeleteVMResourceGroup
100+
DeleteUtilitiesResourceGroup
101+
```
102+
103+
# To exclude certain usecases from getting executed
104+
```powershell
105+
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
106+
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
107+
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
108+
# A new paramter called ExclusionList has been added which is a string array. Pass in the list of usecases you don't want to execute to this parameter.
109+
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
110+
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -ExclusionList "ListFabricResourceProviderInfo","ListUpdateResourceProviderInfo"
111+
```
112+
43113
# Reading the results & logs
44114
Canary generates log files in the TMP directory ($env:TMP). The logs can be found under the directory "CanaryLogs[DATETIME]". There are two types of logs generated, a text log and a JSON log. JSON log provides a quick and easy view of all the usecases and their corresponding results. Text log provides a more detailed output of each usecase execution, its output and results.
45115

0 commit comments

Comments
 (0)