@@ -138,6 +138,7 @@ while ($runCount -le $NumberOfIterations)
138138 $linuxImagePublisher = " Canonical"
139139 $linuxImageOffer = " UbuntuServer"
140140 $linuxImageVersion = " 1.0.0"
141+ [boolean ]$linuxUpload = $false
141142 if (Test-Path - Path $canaryUtilPath )
142143 {
143144 Remove-Item - Path $canaryUtilPath - Force - Recurse
@@ -289,27 +290,34 @@ while ($runCount -le $NumberOfIterations)
289290
290291 if ((Get-Volume ((Get-Item - Path $ENV: TMP ).PSDrive.Name)).SizeRemaining/ 1 GB -gt 35 )
291292 {
292- Invoke-Usecase - Name ' UploadLinuxImageToPIR' - Description " Uploads Linux image to the PIR" - UsecaseBlock `
293+ [boolean ]$invalidUri = $false
294+ try {Invoke-WebRequest - Uri $LinuxImagePath - UseBasicParsing - DisableKeepAlive - Method Head - ErrorAction SilentlyContinue | Out-Null }
295+ catch {$invalidUri = $true }
296+ if (-not $invalidUri )
293297 {
294- try
298+ Invoke-Usecase - Name ' UploadLinuxImageToPIR ' - Description " Uploads Linux image to the PIR " - UsecaseBlock `
295299 {
296- if ( -not ( Get-AzureRmVMImage - Location $ResourceLocation - PublisherName $linuxImagePublisher - Offer $linuxImageOffer - Sku $LinuxOSSku - ErrorAction SilentlyContinue))
300+ try
297301 {
298- $CanaryCustomImageFolder = Join-Path - Path $env: TMP - childPath " CanaryCustomImage$ ( (Get-Date ).Ticks) "
299- if (Test-Path - Path $CanaryCustomImageFolder )
302+ if (-not (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName $linuxImagePublisher - Offer $linuxImageOffer - Sku $LinuxOSSku - ErrorAction SilentlyContinue))
300303 {
301- Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
302- }
303- New-Item - Path $CanaryCustomImageFolder - ItemType Directory
304- $CustomVHDPath = CopyImage - ImagePath $LinuxImagePath - OutputFolder $CanaryCustomImageFolder
305- Add-AzsVMImage - publisher $linuxImagePublisher - offer $linuxImageOffer - sku $LinuxOSSku - version $linuxImageVersion - osDiskLocalPath $CustomVHDPath - osType Linux - Location $ResourceLocation - CreateGalleryItem $false
306- Remove-Item $CanaryCustomImageFolder - Force - Recurse
307- }
308- }
309- catch
310- {
311- Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
312- throw [System.Exception ]" Failed to upload the linux image to PIR. `n $ ( $_.Exception.Message ) "
304+ $CanaryCustomImageFolder = Join-Path - Path $env: TMP - childPath " CanaryCustomImage$ ( (Get-Date ).Ticks) "
305+ if (Test-Path - Path $CanaryCustomImageFolder )
306+ {
307+ Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
308+ }
309+ New-Item - Path $CanaryCustomImageFolder - ItemType Directory
310+ $CustomVHDPath = CopyImage - ImagePath $LinuxImagePath - OutputFolder $CanaryCustomImageFolder
311+ Add-AzsVMImage - publisher $linuxImagePublisher - offer $linuxImageOffer - sku $LinuxOSSku - version $linuxImageVersion - osDiskLocalPath $CustomVHDPath - osType Linux - Location $ResourceLocation - CreateGalleryItem $false
312+ Remove-Item $CanaryCustomImageFolder - Force - Recurse
313+ $linuxUpload = $true
314+ }
315+ }
316+ catch
317+ {
318+ Remove-Item - Path $CanaryCustomImageFolder - Force - Recurse
319+ throw [System.Exception ]" Failed to upload the linux image to PIR. `n $ ( $_.Exception.Message ) "
320+ }
313321 }
314322 }
315323 }
@@ -322,7 +330,7 @@ while ($runCount -le $NumberOfIterations)
322330 $tenantSubscriptionName = $CanaryUtilitiesRG + " tenantsubscription" + [Random ]::new().Next(1 , 999 )
323331 $canaryDefaultTenantSubscription = $CanaryUtilitiesRG + " tenantdefaultsubscription" + [Random ]::new().Next(1 , 999 )
324332
325- if (-not $TenantArmEndpoint )
333+ if (( -not $TenantArmEndpoint ) -and ( -not $listAvl ) )
326334 {
327335 throw [System.Exception ] " Tenant ARM endpoint is required."
328336 }
0 commit comments