Skip to content

Commit 52cd58c

Browse files
authored
Merge pull request #138 from Azure/cbugfix
Cleanup linux temp files and fix logfile name regression for multi-iteration run
2 parents 293edc9 + 2737ce5 commit 52cd58c

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

CanaryValidator/Canary.Tests.ps1

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ param (
9696
[Parameter(ParameterSetName="default", Mandatory=$false)]
9797
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
9898
[ValidateNotNullOrEmpty()]
99-
[string]$CanaryLogFileName = "Canary-Basic$((Get-Date).ToString("-yyMMdd-hhmmss")).log"
99+
[string]$CanaryLogFileName
100100
)
101101

102102
#Requires -Modules AzureRM
@@ -130,6 +130,10 @@ while ($runCount -le $NumberOfIterations)
130130
#
131131
# Start Canary
132132
#
133+
if (-not $CanaryLogFileName)
134+
{
135+
$CanaryLogFileName = "Canary-Basic-$runCount-$((Get-Date).Ticks).log"
136+
}
133137
$CanaryLogFile = $CanaryLogPath + "\$CanaryLogFileName"
134138

135139
Start-Scenario -Name 'Canary' -Type 'Basic' -LogFilename $CanaryLogFile -ContinueOnFailure $ContinueOnFailure
@@ -186,17 +190,25 @@ while ($runCount -le $NumberOfIterations)
186190

187191
Invoke-Usecase -Name 'UploadLinuxImageToPIR' -Description "Uploads Linux image to the PIR" -UsecaseBlock `
188192
{
189-
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName $linuxImagePublisher -Offer $linuxImageOffer -Sku $LinuxOSSku -ErrorAction SilentlyContinue))
193+
try
190194
{
191-
$CanaryCustomImageFolder = Join-Path -Path $env:TMP -childPath "CanaryCustomImage$((Get-Date).ToString("-yyMMdd-hhmmss"))"
192-
if (Test-Path -Path $CanaryCustomImageFolder)
195+
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName $linuxImagePublisher -Offer $linuxImageOffer -Sku $LinuxOSSku -ErrorAction SilentlyContinue))
193196
{
194-
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
195-
}
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
197+
$CanaryCustomImageFolder = Join-Path -Path $env:TMP -childPath "CanaryCustomImage$((Get-Date).Ticks)"
198+
if (Test-Path -Path $CanaryCustomImageFolder)
199+
{
200+
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
201+
}
202+
New-Item -Path $CanaryCustomImageFolder -ItemType Directory
203+
$CustomVHDPath = CopyImage -ImagePath $LinuxImagePath -OutputFolder $CanaryCustomImageFolder
204+
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false -ArmEndpoint $AdminArmEndpoint
205+
Remove-Item $CanaryCustomImageFolder -Force -Recurse
206+
}
207+
}
208+
catch
209+
{
210+
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
211+
throw [System.Exception]"Failed to upload the linux image to PIR. `n$_.Exception.Message"
200212
}
201213
}
202214

0 commit comments

Comments
 (0)