@@ -59,8 +59,7 @@ param (
5959 [ValidateNotNullOrEmpty ()]
6060 [string ]$EnvironmentName = " AzureStackCanaryCloud" ,
6161 [parameter (HelpMessage = " Resource group under which all the utilities need to be placed" )]
62- [Parameter (ParameterSetName = " default" , Mandatory = $false )]
63- [Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
62+ [Parameter (ParameterSetName = " default" , Mandatory = $false )] [Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
6463 [ValidateNotNullOrEmpty ()]
6564 [string ]$CanaryUtilitiesRG = " canur" + [Random ]::new().Next(1 , 999 ),
6665 [parameter (HelpMessage = " Resource group under which the virtual machines need to be placed" )]
@@ -73,7 +72,7 @@ param (
7372 [Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
7473 [ValidateNotNullOrEmpty ()]
7574 [string ]$ResourceLocation = " local" ,
76- [parameter (HelpMessage = " Flag to cleanup resources after exception" )]
75+ [parameter (HelpMessage = " Flag to indicate whether to continue Canary after an exception" )]
7776 [Parameter (ParameterSetName = " default" , Mandatory = $false )]
7877 [Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
7978 [bool ] $ContinueOnFailure = $false ,
@@ -91,12 +90,12 @@ param (
9190 [Parameter (ParameterSetName = " default" , Mandatory = $false )]
9291 [Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
9392 [ValidateNotNullOrEmpty ()]
94- [string ]$CanaryLogPath = $env: TMP + " \CanaryLogs$ ( (Get-Date ).ToString( " -yyMMdd-hhmmss " ) ) " ,
93+ [string ]$CanaryLogPath = $env: TMP + " \CanaryLogs$ ( (Get-Date ).Ticks ) " ,
9594 [parameter (HelpMessage = " Specifies the file name for canary log file" )]
9695 [Parameter (ParameterSetName = " default" , Mandatory = $false )]
9796 [Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
9897 [ValidateNotNullOrEmpty ()]
99- [string ]$CanaryLogFileName = " Canary-Basic$ ( (Get-Date ).ToString( " -yyMMdd-hhmmss " ) ) .log"
98+ [string ]$CanaryLogFileName = " Canary-Basic- $ ( (Get-Date ).Ticks ) .log"
10099)
101100
102101# Requires -Modules AzureRM
@@ -113,12 +112,13 @@ $keyvaultCertName = "ASCanaryVMCertificate"
113112$kvSecretName = $keyvaultName.ToLowerInvariant () + " secret"
114113$VMAdminUserName = " CanaryAdmin"
115114$VMAdminUserPass = " CanaryAdmin@123"
116- $canaryUtilPath = Join-Path - Path $env: TEMP - ChildPath " CanaryUtilities$ ( (Get-Date ).ToString( " -yyMMdd-hhmmss " ) ) "
115+ $canaryUtilPath = Join-Path - Path $env: TEMP - ChildPath " CanaryUtilities$ ( (Get-Date ).Ticks ) "
117116$linuxImagePublisher = " Canonical"
118117$linuxImageOffer = " UbuntuServer"
119118$linuxImageVersion = " 1.0.0"
120119
121120$runCount = 1
121+ $tmpLogname = $CanaryLogFileName
122122while ($runCount -le $NumberOfIterations )
123123{
124124 if (Test-Path - Path $canaryUtilPath )
@@ -129,8 +129,9 @@ while ($runCount -le $NumberOfIterations)
129129
130130 #
131131 # Start Canary
132- #
133- $CanaryLogFile = $CanaryLogPath + " \$CanaryLogFileName "
132+ #
133+ $CanaryLogFileName = [IO.Path ]::GetFileNameWithoutExtension($tmpLogname ) + " -$runCount " + [IO.Path ]::GetExtension($tmpLogname )
134+ $CanaryLogFile = Join-Path - Path $CanaryLogPath - ChildPath $CanaryLogFileName
134135
135136 Start-Scenario - Name ' Canary' - Type ' Basic' - LogFilename $CanaryLogFile - ContinueOnFailure $ContinueOnFailure
136137
@@ -179,24 +180,35 @@ while ($runCount -le $NumberOfIterations)
179180 {
180181 if (-not (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2016-Datacenter-Core" - ErrorAction SilentlyContinue))
181182 {
182- New-Server2016VMImage - ISOPath $WindowsISOPath - TenantId $TenantID - ArmEndpoint $AdminArmEndpoint - Version Core - AzureStackCredentials $ServiceAdminCredentials - CreateGalleryItem $false
183+ New-Server2016VMImage - ISOPath $WindowsISOPath - TenantId $TenantID - EnvironmentName $SvcAdminEnvironmentName - Version Core - AzureStackCredentials $ServiceAdminCredentials - CreateGalleryItem $false
183184 }
184185 }
185186 }
186187
187- Invoke-Usecase - Name ' UploadLinuxImageToPIR ' - Description " Uploads Linux image to the PIR " - UsecaseBlock `
188+ if (( Get-Volume (( Get-Item - Path $ ENV: TMP ).PSDrive.Name)).SizeRemaining / 1 GB -gt 35 )
188189 {
189- if ( -not ( Get-AzureRmVMImage - Location $ResourceLocation - PublisherName $linuxImagePublisher - Offer $linuxImageOffer - Sku $LinuxOSSku - ErrorAction SilentlyContinue))
190+ Invoke-Usecase - Name ' UploadLinuxImageToPIR ' - Description " Uploads Linux image to the PIR " - UsecaseBlock `
190191 {
191- $CanaryCustomImageFolder = Join-Path - Path $env: TMP - childPath " CanaryCustomImage$ ( (Get-Date ).ToString(" -yyMMdd-hhmmss" )) "
192- if (Test-Path - Path $CanaryCustomImageFolder )
192+ try
193193 {
194- Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
194+ if (-not (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName $linuxImagePublisher - Offer $linuxImageOffer - Sku $LinuxOSSku - ErrorAction SilentlyContinue))
195+ {
196+ $CanaryCustomImageFolder = Join-Path - Path $env: TMP - childPath " CanaryCustomImage$ ( (Get-Date ).Ticks) "
197+ if (Test-Path - Path $CanaryCustomImageFolder )
198+ {
199+ Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
200+ }
201+ New-Item - Path $CanaryCustomImageFolder - ItemType Directory
202+ $CustomVHDPath = CopyImage - ImagePath $LinuxImagePath - OutputFolder $CanaryCustomImageFolder
203+ Add-VMImage - publisher $linuxImagePublisher - offer $linuxImageOffer - sku $LinuxOSSku - version $linuxImageVersion - osDiskLocalPath $CustomVHDPath - osType Linux - tenantID $TenantID - azureStackCredentials $ServiceAdminCredentials - CreateGalleryItem $false - EnvironmentName $SvcAdminEnvironmentName
204+ Remove-Item $CanaryCustomImageFolder - Force - Recurse
205+ }
206+ }
207+ catch
208+ {
209+ Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
210+ throw [System.Exception ]" Failed to upload the linux image to PIR. `n $ ( $_.Exception.Message ) "
195211 }
196- New-Item - Path $CanaryCustomImageFolder - ItemType Directory
197- $CustomVHDPath = CopyImage - ImagePath $LinuxImagePath - OutputFolder $CanaryCustomImageFolder
198- Add-VMImage - publisher $linuxImagePublisher - offer $linuxImageOffer - sku $LinuxOSSku - version $linuxImageVersion - osDiskLocalPath $CustomVHDPath - osType Linux - tenantID $TenantID - azureStackCredentials $ServiceAdminCredentials - CreateGalleryItem $false - ArmEndpoint $AdminArmEndpoint
199- Remove-Item $CanaryCustomImageFolder - Recurse
200212 }
201213 }
202214
@@ -206,7 +218,7 @@ while ($runCount -le $NumberOfIterations)
206218 $tenantPlanName = " ascantenantplan" + [Random ]::new().Next(1 , 999 )
207219 $tenantOfferName = " ascantenantoffer" + [Random ]::new().Next(1 , 999 )
208220 $tenantSubscriptionName = " ascanarytenantsubscription" + [Random ]::new().Next(1 , 999 )
209- $canaryDefaultTenantSubscription = " canarytenantdefaultsubscription"
221+ $canaryDefaultTenantSubscription = " canarytenantdefaultsubscription" + [ Random ]::new().Next( 1 , 999 )
210222
211223 if (-not $TenantArmEndpoint )
212224 {
@@ -352,28 +364,38 @@ while ($runCount -le $NumberOfIterations)
352364 }
353365
354366 Invoke-Usecase - Name ' UploadUtilitiesToBlobStorage' - Description " Upload the canary utilities to the blob storage" - UsecaseBlock `
355- {
356- $asStorageAccountKey = Get-AzureRmStorageAccountKey - ResourceGroupName $CanaryUtilitiesRG - Name $storageAccName - ErrorAction Stop
357- if ($asStorageAccountKey )
358- {
359- $storageAccountKey = $asStorageAccountKey.Key1
360- }
361- $asStorageContext = New-AzureStorageContext - StorageAccountName $storageAccName - StorageAccountKey $storageAccountKey - ErrorAction Stop
362- if ($asStorageContext )
363- {
364- $files = Get-ChildItem - Path $canaryUtilPath - File
365- foreach ($file in $files )
367+ {
368+ try
369+ {
370+ $asStorageAccountKey = Get-AzureRmStorageAccountKey - ResourceGroupName $CanaryUtilitiesRG - Name $storageAccName - ErrorAction Stop
371+ if ($asStorageAccountKey )
366372 {
367- if ($file.Extension -match " VHD" )
368- {
369- Set-AzureStorageBlobContent - Container $storageCtrName - File $file.FullName - BlobType Page - Context $asStorageContext - Force - ErrorAction Stop
370- }
371- else
373+ $storageAccountKey = $asStorageAccountKey.Key1
374+ }
375+ $asStorageContext = New-AzureStorageContext - StorageAccountName $storageAccName - StorageAccountKey $storageAccountKey - ErrorAction Stop
376+ if ($asStorageContext )
377+ {
378+ $files = Get-ChildItem - Path $canaryUtilPath - File
379+ foreach ($file in $files )
372380 {
373- Set-AzureStorageBlobContent - Container $storageCtrName - File $file.FullName - Context $asStorageContext - Force - ErrorAction Stop
381+ if ($file.Extension -match " VHD" )
382+ {
383+ Set-AzureStorageBlobContent - Container $storageCtrName - File $file.FullName - BlobType Page - Context $asStorageContext - Force - ErrorAction Stop
384+ }
385+ else
386+ {
387+ Set-AzureStorageBlobContent - Container $storageCtrName - File $file.FullName - Context $asStorageContext - Force - ErrorAction Stop
388+ }
374389 }
375390 }
376391 }
392+ finally
393+ {
394+ if (Test-Path - Path $canaryUtilPath )
395+ {
396+ Remove-Item - Path $canaryUtilPath - Recurse - Force
397+ }
398+ }
377399 }
378400
379401 Invoke-Usecase - Name ' CreateKeyVaultStoreForCertSecret' - Description " Create a key vault store to put the certificate secret" - UsecaseBlock `
@@ -433,8 +455,13 @@ while ($runCount -le $NumberOfIterations)
433455 elseif (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2012-R2-Datacenter" - ErrorAction SilentlyContinue)
434456 {
435457 $osVersion = " 2012-R2-Datacenter"
436- }
437-
458+ }
459+ $linuxImgExists = $false
460+ if (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " Canonical" - Offer " UbuntuServer" - Sku $LinuxOSSku - ErrorAction SilentlyContinue)
461+ {
462+ $linuxImgExists = $true
463+ }
464+
438465 $templateDeploymentName = " CanaryVMDeployment"
439466 $parameters = @ {" VMAdminUserName" = $VMAdminUserName ;
440467 " VMAdminUserPassword" = $VMAdminUserPass ;
@@ -447,11 +474,22 @@ while ($runCount -le $NumberOfIterations)
447474 " LinuxImagePublisher" = $linuxImagePublisher ;
448475 " LinuxImageOffer" = $linuxImageOffer ;
449476 " LinuxImageSku" = $LinuxOSSku }
450- $templateError = Test-AzureRmResourceGroupDeployment - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.json - TemplateParameterObject $parameters
451- if (-not $templateError )
477+ if (-not $linuxImgExists )
478+ {
479+ $templateError = Test-AzureRmResourceGroupDeployment - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.json - TemplateParameterObject $parameters
480+ }
481+ elseif ($linuxImgExists )
482+ {
483+ $templateError = Test-AzureRmResourceGroupDeployment - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.nolinux.json - TemplateParameterObject $parameters
484+ }
485+
486+ if ((-not $templateError ) -and ($linuxImgExists ))
452487 {
453488 New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
454489 }
490+ elseif (-not $templateError ) {
491+ New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.nolinux.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
492+ }
455493 else
456494 {
457495 throw [System.Exception ] " Template validation failed. `n $ ( $templateError.Message ) "
@@ -685,6 +723,23 @@ while ($runCount -le $NumberOfIterations)
685723 }
686724 }
687725 }
726+
727+ Invoke-Usecase - Name ' CheckExistenceOfScreenShotForVMWithPrivateIP' - Description " Check if screen shots are available for Windows VM with private IP and store the screen shot in log folder" - UsecaseBlock `
728+ {
729+ $sa = Get-AzureRmStorageAccount - ResourceGroupName $CanaryVMRG - Name " $ ( $CanaryVMRG ) 2sa"
730+ $diagSC = $sa | Get-AzureStorageContainer | Where-Object {$_.Name -like " bootdiagnostics-$CanaryVMRG *" }
731+ $screenShotBlob = $diagSC | Get-AzureStorageBlob | Where-Object {$_.Name -like " $privateVMName *screenshot.bmp" }
732+ $sa | Get-AzureStorageBlobContent - Blob $screenShotBlob.Name - Container $diagSC.Name - Destination $CanaryLogPath - Force
733+ if (-not (Get-ChildItem - Path $CanaryLogPath - File - Filter $screenShotBlob.name ))
734+ {
735+ throw [System.Exception ]" Unable to download screen shot for a Windows VM with private IP"
736+ }
737+ }
738+
739+ Invoke-Usecase - Name ' EnumerateAllResources' - Description " List out all the resources that have been deployed" - UsecaseBlock `
740+ {
741+ Get-AzureRmResource
742+ }
688743
689744 if (-not $NoCleanup )
690745 {
0 commit comments