Skip to content

Commit fe41b35

Browse files
authored
Merge branch 'vnext' into vnext
2 parents 8e0fa53 + 910d5b7 commit fe41b35

29 files changed

Lines changed: 3098 additions & 842 deletions

CanaryValidator/Canary.Tests.ps1

Lines changed: 43 additions & 20 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 = ("GetAzureStackInfraRoleInstance", "GetAzureStackScaleUnitNode"),
103+
[parameter(HelpMessage="Lists the available usecases in Canary")]
104+
[Parameter(ParameterSetName="listavl", Mandatory=$true)]
105+
[ValidateNotNullOrEmpty()]
106+
[switch]$ListAvailable
99107
)
100108

101-
#Requires -Modules AzureRM
109+
#requires -Modules AzureRM.Profile, AzureRM.AzureStackAdmin
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
}
@@ -268,7 +276,7 @@ while ($runCount -le $NumberOfIterations)
268276
{
269277
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2016-Datacenter-Core" -ErrorAction SilentlyContinue))
270278
{
271-
New-Server2016VMImage -ISOPath $WindowsISOPath -TenantId $TenantID -EnvironmentName $SvcAdminEnvironmentName -Version Core -AzureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false
279+
New-Server2016VMImage -ISOPath $WindowsISOPath -TenantId $TenantID -EnvironmentName $SvcAdminEnvironmentName -Location $ResourceLocation -Version Core -AzureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false
272280
}
273281
}
274282
}
@@ -288,7 +296,7 @@ while ($runCount -le $NumberOfIterations)
288296
}
289297
New-Item -Path $CanaryCustomImageFolder -ItemType Directory
290298
$CustomVHDPath = CopyImage -ImagePath $LinuxImagePath -OutputFolder $CanaryCustomImageFolder
291-
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false -EnvironmentName $SvcAdminEnvironmentName
299+
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -Location $ResourceLocation -CreateGalleryItem $false -EnvironmentName $SvcAdminEnvironmentName
292300
Remove-Item $CanaryCustomImageFolder -Force -Recurse
293301
}
294302
}
@@ -647,18 +655,24 @@ while ($runCount -le $NumberOfIterations)
647655
if (($pubVMObject = Get-AzureRmVM -ResourceGroupName $CanaryVMRG -Name $publicVMName -ErrorAction Stop) -and ($pvtVMObject = Get-AzureRmVM -ResourceGroupName $CanaryVMRG -Name $privateVMName -ErrorAction Stop))
648656
{
649657
Set-item wsman:\localhost\Client\TrustedHosts -Value $publicVMIP -Force -Confirm:$false
650-
if ($publicVMSession = New-PSSession -ComputerName $publicVMIP -Credential $vmCreds -ErrorAction Stop)
658+
$sw = [system.diagnostics.stopwatch]::startNew()
659+
while (-not($publicVMSession = New-PSSession -ComputerName $publicVMIP -Credential $vmCreds -ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000) -and (-not($publicVMSession))){$sw.Stop(); throw [System.Exception]"Unable to establish a remote session to the tenant VM using public IP: $publicVMIP"}; Start-Sleep -Seconds 15}
660+
if ($publicVMSession)
651661
{
652662
Invoke-Command -Session $publicVMSession -Script{param ($privateIP) Set-item wsman:\localhost\Client\TrustedHosts -Value $privateIP -Force -Confirm:$false} -ArgumentList $privateVMIP | Out-Null
653-
$privateVMResponseFromRemoteSession = Invoke-Command -Session $publicVMSession -Script{param ($privateIP, $vmCreds, $scriptToRun) $privateSess = New-PSSession -ComputerName $privateIP -Credential $vmCreds; Invoke-Command -Session $privateSess -Script{param($script) Invoke-Expression $script} -ArgumentList $scriptToRun} -ArgumentList $privateVMIP, $vmCreds, $vmCommsScriptBlock
663+
$privateVMResponseFromRemoteSession = Invoke-Command -Session $publicVMSession -Script{param ($privateIP, $vmCreds, $scriptToRun) $sw = [system.diagnostics.stopwatch]::startNew(); while (-not($privateSess = New-PSSession -ComputerName $privateIP -Credential $vmCreds -ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000) -and (-not($privateSess))){$sw.Stop(); throw [System.Exception]"Unable to establish a remote session to the tenant VM using private IP: $privateIP"}; Start-Sleep -Seconds 15}; Invoke-Command -Session $privateSess -Script{param($script) Invoke-Expression $script} -ArgumentList $scriptToRun} -ArgumentList $privateVMIP, $vmCreds, $vmCommsScriptBlock -ErrorVariable remoteExecError 2>$null
664+
$publicVMSession | Remove-PSSession -Confirm:$false
665+
if ($remoteExecError)
666+
{
667+
throw [System.Exception]"$remoteExecError"
668+
}
654669
if ($privateVMResponseFromRemoteSession)
655670
{
656-
$publicVMSession | Remove-PSSession -Confirm:$false
657671
$privateVMResponseFromRemoteSession
658672
}
659673
else
660674
{
661-
throw [System.Exception]"Public VM was not able to talk to the Private VM via the private IP"
675+
throw [System.Exception]"The expected certificate from KV was not found on the tenant VM with private IP: $privateVMIP"
662676
}
663677
}
664678
}
@@ -795,18 +809,24 @@ while ($runCount -le $NumberOfIterations)
795809
if (($pubVMObject = Get-AzureRmVM -ResourceGroupName $CanaryVMRG -Name $publicVMName -ErrorAction Stop) -and ($pvtVMObject = Get-AzureRmVM -ResourceGroupName $CanaryVMRG -Name $privateVMName -ErrorAction Stop))
796810
{
797811
Set-item wsman:\localhost\Client\TrustedHosts -Value $publicVMIP -Force -Confirm:$false
798-
if ($publicVMSession = New-PSSession -ComputerName $publicVMIP -Credential $vmCreds -ErrorAction Stop)
812+
$sw = [system.diagnostics.stopwatch]::startNew()
813+
while (-not($publicVMSession = New-PSSession -ComputerName $publicVMIP -Credential $vmCreds -ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000) -and (-not($publicVMSession))){$sw.Stop(); throw [System.Exception]"Unable to establish a remote session to the tenant VM using public IP: $publicVMIP"}; Start-Sleep -Seconds 15}
814+
if ($publicVMSession)
799815
{
800816
Invoke-Command -Session $publicVMSession -Script{param ($privateIP) Set-item wsman:\localhost\Client\TrustedHosts -Value $privateIP -Force -Confirm:$false} -ArgumentList $privateVMIP | Out-Null
801-
$privateVMResponseFromRemoteSession = Invoke-Command -Session $publicVMSession -Script{param ($privateIP, $vmCreds, $scriptToRun) $privateSess = New-PSSession -ComputerName $privateIP -Credential $vmCreds; Invoke-Command -Session $privateSess -Script{param($script) Invoke-Expression $script} -ArgumentList $scriptToRun} -ArgumentList $privateVMIP, $vmCreds, $vmCommsScriptBlock
817+
$privateVMResponseFromRemoteSession = Invoke-Command -Session $publicVMSession -Script{param ($privateIP, $vmCreds, $scriptToRun) $sw = [system.diagnostics.stopwatch]::startNew(); while (-not($privateSess = New-PSSession -ComputerName $privateIP -Credential $vmCreds -ErrorAction SilentlyContinue)){if (($sw.ElapsedMilliseconds -gt 240000) -and (-not($privateSess))){$sw.Stop(); throw [System.Exception]"Unable to establish a remote session to the tenant VM using private IP: $privateIP"}; Start-Sleep -Seconds 15}; Invoke-Command -Session $privateSess -Script{param($script) Invoke-Expression $script} -ArgumentList $scriptToRun} -ArgumentList $privateVMIP, $vmCreds, $vmCommsScriptBlock -ErrorVariable remoteExecError 2>$null
818+
$publicVMSession | Remove-PSSession -Confirm:$false
819+
if ($remoteExecError)
820+
{
821+
throw [System.Exception]"$remoteExecError"
822+
}
802823
if ($privateVMResponseFromRemoteSession)
803824
{
804-
$publicVMSession | Remove-PSSession -Confirm:$false
805825
$privateVMResponseFromRemoteSession
806826
}
807827
else
808828
{
809-
throw [System.Exception]"Public VM was not able to talk to the Private VM via the private IP"
829+
throw [System.Exception]"Host name could not be retrieved from the tenant VM with private IP: $privateVMIP"
810830
}
811831
}
812832
}
@@ -859,7 +879,7 @@ while ($runCount -le $NumberOfIterations)
859879
}
860880
}
861881

862-
if ($TenantAdminCredentials)
882+
if (($TenantAdminCredentials) -or ($listAvl))
863883
{
864884
Invoke-Usecase -Name 'TenantRelatedcleanup' -Description "Remove all the tenant related stuff" -UsecaseBlock `
865885
{
@@ -893,7 +913,10 @@ while ($runCount -le $NumberOfIterations)
893913

894914
End-Scenario
895915
$runCount += 1
896-
Get-CanaryResult
916+
if (-not $ListAvailable)
917+
{
918+
Get-CanaryResult
919+
}
897920
}
898921

899922
if ($NumberOfIterations -gt 1)

CanaryValidator/Canary.Utilities.psm1

Lines changed: 69 additions & 25 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
@@ -10,7 +12,7 @@ if (Test-Path -Path "$PSScriptRoot\..\WTTLog.ps1")
1012

1113
$CurrentUseCase = @{}
1214
[System.Collections.Stack] $UseCaseStack = New-Object System.Collections.Stack
13-
filter timestamp {"$(Get-Date -Format HH:mm:ss.ffff): $_"}
15+
filter timestamp {"$(Get-Date -Format "yyyy-MM-dd HH:mm:ss.ffff") $_"}
1416

1517

1618
function Log-Info
@@ -49,14 +51,11 @@ function Log-JSONReport
4951
[string] $Message
5052
)
5153
if ($Message)
52-
{
53-
if ($Message.Contains(": ["))
54-
{
55-
$time = $Message.Substring(0, $Message.IndexOf(": ["))
56-
}
54+
{
5755
if ($Message.Contains("[START]"))
5856
{
59-
$name = $Message.Substring($Message.LastIndexOf(":") + 1).Trim().Replace("######", "").Trim()
57+
$time = $Message.Substring(0, $Message.IndexOf("[")).Trim()
58+
$name = $Message.Substring($Message.LastIndexOf(":") + 1).Trim()
6059
if ($UseCaseStack.Count)
6160
{
6261
$nestedUseCase = @{
@@ -79,14 +78,19 @@ function Log-JSONReport
7978
}
8079
elseif ($Message.Contains("[END]"))
8180
{
81+
$time = $Message.Substring(0, $Message.IndexOf("[")).Trim()
8282
$result = ""
8383
if ($UseCaseStack.Peek().UseCase -and ($UseCaseStack.Peek().UseCase | Where-Object {$_.Result -eq "FAIL"}))
8484
{
8585
$result = "FAIL"
8686
}
87-
else
87+
elseif ($Message.Contains("[RESULT = PASS]"))
8888
{
89-
$result = $Message.Substring($Message.LastIndexOf("=") + 1).Trim().Replace("] ######", "").Trim()
89+
$result = "PASS"
90+
}
91+
elseif ($Message.Contains("[RESULT = FAIL]"))
92+
{
93+
$result = "FAIL"
9094
}
9195
$UseCaseStack.Peek().Add("Result", $result)
9296
$UseCaseStack.Peek().Add("EndTime", $time)
@@ -161,7 +165,11 @@ function Start-Scenario
161165
[ValidateNotNullOrEmpty()]
162166
[string]$LogFilename,
163167
[parameter(Mandatory=$false)]
164-
[bool] $ContinueOnFailure = $false
168+
[bool]$ContinueOnFailure = $false,
169+
[parameter(Mandatory=$false)]
170+
[bool]$ListAvailable = $false,
171+
[parameter(Mandatory=$false)]
172+
[string[]]$ExclusionList
165173
)
166174

167175
if ($LogFileName)
@@ -181,14 +189,25 @@ function Start-Scenario
181189
{
182190
OpenWTTLogger $Global:wttLogFileName
183191
}
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
192+
if ($ListAvailable)
193+
{
194+
$Global:listAvailableUsecases = $true
195+
}
196+
if ($ExclusionList)
197+
{
198+
$Global:exclusionList = $ExclusionList
199+
}
200+
if (-not $ListAvailable)
201+
{
202+
New-Item -Path $Global:JSONLogFile -Type File -Force
203+
New-Item -Path $Global:TxtLogFile -Type File -Force
204+
$jsonReport = @{
205+
"Scenario" = ($Name + "-" + $Type)
206+
"UseCases" = @()
207+
}
208+
$jsonReport | ConvertTo-Json -Depth 10 | Out-File -FilePath $Global:JSONLogFile
209+
}
210+
192211
$Global:ContinueOnFailure = $ContinueOnFailure
193212
}
194213

@@ -214,7 +233,32 @@ function Invoke-Usecase
214233
[ValidateNotNullOrEmpty()]
215234
[ScriptBlock]$UsecaseBlock
216235
)
217-
Log-Info ("###### [START] Usecase: $Name ######`n")
236+
237+
if ($Global:listAvailableUsecases)
238+
{
239+
$parentUsecase = $Name
240+
if ((Get-PSCallStack)[1].Arguments.Contains($parentUsecase))
241+
{
242+
" `t"*([math]::Floor((Get-PSCallStack).Count/3)) + "|--" + $Name
243+
}
244+
else
245+
{
246+
247+
"`t" + $Name
248+
}
249+
if ($UsecaseBlock.ToString().Contains("Invoke-Usecase"))
250+
{
251+
Invoke-Command -ScriptBlock $UsecaseBlock -ErrorAction SilentlyContinue
252+
}
253+
return
254+
}
255+
256+
if (($Global:exclusionList).Contains($Name))
257+
{
258+
Log-Info ("Skipping Usecase: $Name")
259+
return
260+
}
261+
Log-Info ("[START] Usecase: $Name`n")
218262
if ($Global:wttLogFileName)
219263
{
220264
StartTest "CanaryGate:$Name"
@@ -236,7 +280,7 @@ function Invoke-Usecase
236280
{
237281
EndTest "CanaryGate:$Name" $true
238282
}
239-
Log-Info ("###### [END] Usecase: $Name ###### [RESULT = PASS] ######`n")
283+
Log-Info ("[END] [RESULT = PASS] Usecase: $Name`n")
240284
return $result | Out-Null
241285
}
242286
catch [System.Exception]
@@ -245,7 +289,7 @@ function Invoke-Usecase
245289
Log-Info ("###### <FAULTING SCRIPTBLOCK> ######")
246290
Log-Info ("$UsecaseBlock")
247291
Log-Info ("###### </FAULTING SCRIPTBLOCK> ######")
248-
Log-Error ("###### [END] Usecase: $Name ###### [RESULT = FAIL] ######`n")
292+
Log-Error ("[END] [RESULT = FAIL] Usecase: $Name`n")
249293
if ($Global:wttLogFileName)
250294
{
251295
EndTest "CanaryGate:$Name" $false

0 commit comments

Comments
 (0)