@@ -59,8 +59,7 @@ param (
59
59
[ValidateNotNullOrEmpty ()]
60
60
[string ]$EnvironmentName = " AzureStackCanaryCloud" ,
61
61
[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 )]
64
63
[ValidateNotNullOrEmpty ()]
65
64
[string ]$CanaryUtilitiesRG = " canur" + [Random ]::new().Next(1 , 999 ),
66
65
[parameter (HelpMessage = " Resource group under which the virtual machines need to be placed" )]
@@ -73,7 +72,7 @@ param (
73
72
[Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
74
73
[ValidateNotNullOrEmpty ()]
75
74
[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" )]
77
76
[Parameter (ParameterSetName = " default" , Mandatory = $false )]
78
77
[Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
79
78
[bool ] $ContinueOnFailure = $false ,
@@ -91,12 +90,12 @@ param (
91
90
[Parameter (ParameterSetName = " default" , Mandatory = $false )]
92
91
[Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
93
92
[ValidateNotNullOrEmpty ()]
94
- [string ]$CanaryLogPath = $env: TMP + " \CanaryLogs$ ( (Get-Date ).ToString( " -yyMMdd-hhmmss " ) ) " ,
93
+ [string ]$CanaryLogPath = $env: TMP + " \CanaryLogs$ ( (Get-Date ).Ticks ) " ,
95
94
[parameter (HelpMessage = " Specifies the file name for canary log file" )]
96
95
[Parameter (ParameterSetName = " default" , Mandatory = $false )]
97
96
[Parameter (ParameterSetName = " tenant" , Mandatory = $false )]
98
97
[ValidateNotNullOrEmpty ()]
99
- [string ]$CanaryLogFileName = " Canary-Basic$ ( (Get-Date ).ToString( " -yyMMdd-hhmmss " ) ) .log"
98
+ [string ]$CanaryLogFileName = " Canary-Basic- $ ( (Get-Date ).Ticks ) .log"
100
99
)
101
100
102
101
# Requires -Modules AzureRM
@@ -113,12 +112,13 @@ $keyvaultCertName = "ASCanaryVMCertificate"
113
112
$kvSecretName = $keyvaultName.ToLowerInvariant () + " secret"
114
113
$VMAdminUserName = " CanaryAdmin"
115
114
$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 ) "
117
116
$linuxImagePublisher = " Canonical"
118
117
$linuxImageOffer = " UbuntuServer"
119
118
$linuxImageVersion = " 1.0.0"
120
119
121
120
$runCount = 1
121
+ $tmpLogname = $CanaryLogFileName
122
122
while ($runCount -le $NumberOfIterations )
123
123
{
124
124
if (Test-Path - Path $canaryUtilPath )
@@ -129,8 +129,9 @@ while ($runCount -le $NumberOfIterations)
129
129
130
130
#
131
131
# 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
134
135
135
136
Start-Scenario - Name ' Canary' - Type ' Basic' - LogFilename $CanaryLogFile - ContinueOnFailure $ContinueOnFailure
136
137
@@ -179,24 +180,35 @@ while ($runCount -le $NumberOfIterations)
179
180
{
180
181
if (-not (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2016-Datacenter-Core" - ErrorAction SilentlyContinue))
181
182
{
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
183
184
}
184
185
}
185
186
}
186
187
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 )
188
189
{
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 `
190
191
{
191
- $CanaryCustomImageFolder = Join-Path - Path $env: TMP - childPath " CanaryCustomImage$ ( (Get-Date ).ToString(" -yyMMdd-hhmmss" )) "
192
- if (Test-Path - Path $CanaryCustomImageFolder )
192
+ try
193
193
{
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 ) "
195
211
}
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
200
212
}
201
213
}
202
214
@@ -206,7 +218,7 @@ while ($runCount -le $NumberOfIterations)
206
218
$tenantPlanName = " ascantenantplan" + [Random ]::new().Next(1 , 999 )
207
219
$tenantOfferName = " ascantenantoffer" + [Random ]::new().Next(1 , 999 )
208
220
$tenantSubscriptionName = " ascanarytenantsubscription" + [Random ]::new().Next(1 , 999 )
209
- $canaryDefaultTenantSubscription = " canarytenantdefaultsubscription"
221
+ $canaryDefaultTenantSubscription = " canarytenantdefaultsubscription" + [ Random ]::new().Next( 1 , 999 )
210
222
211
223
if (-not $TenantArmEndpoint )
212
224
{
@@ -352,28 +364,38 @@ while ($runCount -le $NumberOfIterations)
352
364
}
353
365
354
366
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 )
366
372
{
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 )
372
380
{
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
+ }
374
389
}
375
390
}
376
391
}
392
+ finally
393
+ {
394
+ if (Test-Path - Path $canaryUtilPath )
395
+ {
396
+ Remove-Item - Path $canaryUtilPath - Recurse - Force
397
+ }
398
+ }
377
399
}
378
400
379
401
Invoke-Usecase - Name ' CreateKeyVaultStoreForCertSecret' - Description " Create a key vault store to put the certificate secret" - UsecaseBlock `
@@ -433,8 +455,13 @@ while ($runCount -le $NumberOfIterations)
433
455
elseif (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2012-R2-Datacenter" - ErrorAction SilentlyContinue)
434
456
{
435
457
$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
+
438
465
$templateDeploymentName = " CanaryVMDeployment"
439
466
$parameters = @ {" VMAdminUserName" = $VMAdminUserName ;
440
467
" VMAdminUserPassword" = $VMAdminUserPass ;
@@ -447,11 +474,22 @@ while ($runCount -le $NumberOfIterations)
447
474
" LinuxImagePublisher" = $linuxImagePublisher ;
448
475
" LinuxImageOffer" = $linuxImageOffer ;
449
476
" 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 ))
452
487
{
453
488
New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
454
489
}
490
+ elseif (-not $templateError ) {
491
+ New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.nolinux.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
492
+ }
455
493
else
456
494
{
457
495
throw [System.Exception ] " Template validation failed. `n $ ( $templateError.Message ) "
@@ -685,6 +723,23 @@ while ($runCount -le $NumberOfIterations)
685
723
}
686
724
}
687
725
}
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
+ }
688
743
689
744
if (-not $NoCleanup )
690
745
{
0 commit comments