@@ -185,27 +185,30 @@ while ($runCount -le $NumberOfIterations)
185185 }
186186 }
187187
188- 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 )
189189 {
190- try
190+ Invoke-Usecase - Name ' UploadLinuxImageToPIR ' - Description " Uploads Linux image to the PIR " - UsecaseBlock `
191191 {
192- if ( -not ( Get-AzureRmVMImage - Location $ResourceLocation - PublisherName $linuxImagePublisher - Offer $linuxImageOffer - Sku $LinuxOSSku - ErrorAction SilentlyContinue))
192+ try
193193 {
194- $CanaryCustomImageFolder = Join-Path - Path $env: TMP - childPath " CanaryCustomImage$ ( (Get-Date ).Ticks) "
195- if (Test-Path - Path $CanaryCustomImageFolder )
194+ if (-not (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName $linuxImagePublisher - Offer $linuxImageOffer - Sku $LinuxOSSku - ErrorAction SilentlyContinue))
196195 {
197- Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
198- }
199- New-Item - Path $CanaryCustomImageFolder - ItemType Directory
200- $CustomVHDPath = CopyImage - ImagePath $LinuxImagePath - OutputFolder $CanaryCustomImageFolder
201- Add-VMImage - publisher $linuxImagePublisher - offer $linuxImageOffer - sku $LinuxOSSku - version $linuxImageVersion - osDiskLocalPath $CustomVHDPath - osType Linux - tenantID $TenantID - azureStackCredentials $ServiceAdminCredentials - CreateGalleryItem $false - ArmEndpoint $AdminArmEndpoint
202- Remove-Item $CanaryCustomImageFolder - Force - Recurse
203- }
204- }
205- catch
206- {
207- Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
208- throw [System.Exception ]" Failed to upload the linux image to PIR. `n $ ( $_.Exception.Message ) "
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 - ArmEndpoint $AdminArmEndpoint
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 ) "
211+ }
209212 }
210213 }
211214
@@ -361,28 +364,38 @@ while ($runCount -le $NumberOfIterations)
361364 }
362365
363366 Invoke-Usecase - Name ' UploadUtilitiesToBlobStorage' - Description " Upload the canary utilities to the blob storage" - UsecaseBlock `
364- {
365- $asStorageAccountKey = Get-AzureRmStorageAccountKey - ResourceGroupName $CanaryUtilitiesRG - Name $storageAccName - ErrorAction Stop
366- if ($asStorageAccountKey )
367- {
368- $storageAccountKey = $asStorageAccountKey.Key1
369- }
370- $asStorageContext = New-AzureStorageContext - StorageAccountName $storageAccName - StorageAccountKey $storageAccountKey - ErrorAction Stop
371- if ($asStorageContext )
372- {
373- $files = Get-ChildItem - Path $canaryUtilPath - File
374- foreach ($file in $files )
367+ {
368+ try
369+ {
370+ $asStorageAccountKey = Get-AzureRmStorageAccountKey - ResourceGroupName $CanaryUtilitiesRG - Name $storageAccName - ErrorAction Stop
371+ if ($asStorageAccountKey )
375372 {
376- if ($file.Extension -match " VHD" )
377- {
378- Set-AzureStorageBlobContent - Container $storageCtrName - File $file.FullName - BlobType Page - Context $asStorageContext - Force - ErrorAction Stop
379- }
380- 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 )
381380 {
382- 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+ }
383389 }
384390 }
385391 }
392+ finally
393+ {
394+ if (Test-Path - Path $canaryUtilPath )
395+ {
396+ Remove-Item - Path $canaryUtilPath - Recurse - Force
397+ }
398+ }
386399 }
387400
388401 Invoke-Usecase - Name ' CreateKeyVaultStoreForCertSecret' - Description " Create a key vault store to put the certificate secret" - UsecaseBlock `
@@ -442,8 +455,13 @@ while ($runCount -le $NumberOfIterations)
442455 elseif (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2012-R2-Datacenter" - ErrorAction SilentlyContinue)
443456 {
444457 $osVersion = " 2012-R2-Datacenter"
445- }
446-
458+ }
459+ $linuxImgExists = $false
460+ if (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " Canonical" - Offer " UbuntuServer" - Sku $LinuxOSSku - ErrorAction SilentlyContinue)
461+ {
462+ $linuxImgExists = $true
463+ }
464+
447465 $templateDeploymentName = " CanaryVMDeployment"
448466 $parameters = @ {" VMAdminUserName" = $VMAdminUserName ;
449467 " VMAdminUserPassword" = $VMAdminUserPass ;
@@ -456,11 +474,22 @@ while ($runCount -le $NumberOfIterations)
456474 " LinuxImagePublisher" = $linuxImagePublisher ;
457475 " LinuxImageOffer" = $linuxImageOffer ;
458476 " LinuxImageSku" = $LinuxOSSku }
459- $templateError = Test-AzureRmResourceGroupDeployment - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.json - TemplateParameterObject $parameters
460- 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 ))
461487 {
462488 New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
463489 }
490+ elseif (-not $templateError ) {
491+ New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile $PSScriptRoot \azuredeploy.nolinux.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
492+ }
464493 else
465494 {
466495 throw [System.Exception ] " Template validation failed. `n $ ( $templateError.Message ) "
@@ -707,6 +736,11 @@ while ($runCount -le $NumberOfIterations)
707736 }
708737 }
709738
739+ Invoke-Usecase - Name ' EnumerateAllResources' - Description " List out all the resources that have been deployed" - UsecaseBlock `
740+ {
741+ Get-AzureRmResource
742+ }
743+
710744 if (-not $NoCleanup )
711745 {
712746 Invoke-Usecase - Name ' DeleteVMWithPrivateIP' - Description " Delete the VM with private IP" - UsecaseBlock `
0 commit comments