From 9b55f69fa31eed6e097436651812195b6f9d6a8e Mon Sep 17 00:00:00 2001 From: Vincent Dai <23257217+vidai-msft@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:51:56 +0800 Subject: [PATCH 1/3] Reverted cmdlet error check and added -Force for New-AzResourceGroup --- tools/TestFx/Live/LiveTestUtility.psm1 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/TestFx/Live/LiveTestUtility.psm1 b/tools/TestFx/Live/LiveTestUtility.psm1 index 779c77ce2935..4d2e399473aa 100644 --- a/tools/TestFx/Live/LiveTestUtility.psm1 +++ b/tools/TestFx/Live/LiveTestUtility.psm1 @@ -143,7 +143,7 @@ function New-LiveTestResourceGroup { [string] $Location = "westus" ) - $rg = Invoke-LiveTestCommand -Command "New-AzResourceGroup -Name $Name -Location $Location" + $rg = Invoke-LiveTestCommand -Command "New-AzResourceGroup -Name $Name -Location $Location -Force" $rg } @@ -188,12 +188,7 @@ function Invoke-LiveTestCommand { $cmdResult = Invoke-Expression -Command $Command -ErrorAction Stop - if ($LASTEXITCODE -eq 0) { - Write-Host "##[section]Successfully executed the command `"$Command`"" -ForegroundColor Green - } - else { - throw "Error occurred when executing the command `"$Command`"." - } + Write-Host "##[section]Successfully executed the command `"$Command`"" -ForegroundColor Green $cmdResult break From 58fa15e1f0c3b8222ec62ce5b0920aaf28abeee1 Mon Sep 17 00:00:00 2001 From: Vincent Dai <23257217+vidai-msft@users.noreply.github.com> Date: Wed, 1 Mar 2023 15:42:50 +0800 Subject: [PATCH 2/3] Removed the $lastexitcode due to unexpected issues on non-windows system --- .../LiveTests/TestLiveScenarios.ps1 | 4 +-- tools/TestFx/Live/LiveTestUtility.psm1 | 32 +++++-------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/Compute/Compute.Test/LiveTests/TestLiveScenarios.ps1 b/src/Compute/Compute.Test/LiveTests/TestLiveScenarios.ps1 index b4c4ffbc3a95..079d099fbc7d 100644 --- a/src/Compute/Compute.Test/LiveTests/TestLiveScenarios.ps1 +++ b/src/Compute/Compute.Test/LiveTests/TestLiveScenarios.ps1 @@ -164,11 +164,11 @@ Invoke-LiveTestScenario -Name "Delete a ssh key" -Description "Test deleting a s New-AzSshKey -ResourceGroupName $rgName -Name $key1Name Remove-AzSshKey -ResourceGroupName $rgName -name $key1Name - $actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key1Name + $actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key1Name -ErrorAction SilentlyContinue Assert-Null $actual $key2 = New-AzSshKey -ResourceGroupName $rgName -Name $key2Name Remove-AzSshKey -ResourceId $key2.Id - $actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key2Name + $actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key2Name -ErrorAction SilentlyContinue Assert-Null $actual } diff --git a/tools/TestFx/Live/LiveTestUtility.psm1 b/tools/TestFx/Live/LiveTestUtility.psm1 index 4d2e399473aa..27fb3eae9921 100644 --- a/tools/TestFx/Live/LiveTestUtility.psm1 +++ b/tools/TestFx/Live/LiveTestUtility.psm1 @@ -183,12 +183,12 @@ function Invoke-LiveTestCommand { do { try { - Write-Host "##[section]Start to execute the command `"$Command`"." -ForegroundColor Green + Write-Host "##[section]Start executing the command `"$Command`"." -ForegroundColor Green Write-Host "##[command]The command `"$Command`" is running." -ForegroundColor Cyan $cmdResult = Invoke-Expression -Command $Command -ErrorAction Stop - Write-Host "##[section]Successfully executed the command `"$Command`"" -ForegroundColor Green + Write-Host "##[section]Finish executing the command `"$Command`"" -ForegroundColor Green $cmdResult break @@ -243,7 +243,7 @@ function Invoke-LiveTestScenario { throw "Error occurred when initializing live tests. The csv file was not found." } - Write-Host "##[group]Start to execute the live scenario `"$Name`"." -ForegroundColor Green + Write-Host "##[group]Start executing the live scenario `"$Name`"." -ForegroundColor Green try { $snrCsvData = [PSCustomObject]@{ @@ -267,13 +267,13 @@ function Invoke-LiveTestScenario { $snrResourceGroupLocation = $ResourceGroupLocation } - Write-Host "##[section]Start to create a resource group." -ForegroundColor Green + Write-Host "##[section]Start creating a resource group." -ForegroundColor Green Write-Host "##[section]Resource group name: $snrResourceGroupName" -ForegroundColor Green Write-Host "##[section]Resource group location: $snrResourceGroupLocation" -ForegroundColor Green $snrResourceGroup = New-LiveTestResourceGroup -Name $snrResourceGroupName -Location $snrResourceGroupLocation - Write-Host "##[section]Successfully created the resource group." -ForegroundColor Green + Write-Host "##[section]Finish creating the resource group." -ForegroundColor Green } $snrRetryCount = 0 @@ -288,12 +288,8 @@ function Invoke-LiveTestScenario { $ScenarioScript.InvokeWithContext($null, $prefs, $snrResourceGroup) - if ($LASTEXITCODE -eq 0) { - Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green - } - else { - throw "Error occurred when executing the live scenario `"$Name`"." - } + Write-Host "##[section]Finish executing the live scenario `"$Name`"." -ForegroundColor Green + break } catch { @@ -303,18 +299,6 @@ function Invoke-LiveTestScenario { $snrInvocationInfo = $snrErrorRecord.InvocationInfo - Write-Host "##[error]Error Object:" -ForegroundColor Red - $_ | Format-List * -Force - - Write-Host "##[error]Exception Object:" -ForegroundColor Red - $_.Exception.InnerException | Format-List * -Force - - Write-Host "##[error]Error Record:" -ForegroundColor Red - $snrErrorRecord | Format-List * -Force - - Write-Host "##[error]Invocation Info:" -ForegroundColor Red - $snrInvocationInfo | Format-List * -Force - if ($null -ne $snrInvocationInfo) { $snrScriptName = Split-Path -Path $snrInvocationInfo.ScriptName -Leaf -ErrorAction SilentlyContinue if ($snrScriptName -eq "Assert.ps1") { @@ -362,7 +346,7 @@ function Invoke-LiveTestScenario { if (!$NoResourceGroup.IsPresent -and $null -ne $snrResourceGroup) { try { - Write-Host "##[section]Start to clean up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green + Write-Host "##[section]Start cleaning up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green Clear-LiveTestResources -Name $snrResourceGroupName } catch { From c1c50b0454d312238c439b48bc82870c3d161a9b Mon Sep 17 00:00:00 2001 From: Vincent Dai <23257217+vidai-msft@users.noreply.github.com> Date: Wed, 1 Mar 2023 15:51:02 +0800 Subject: [PATCH 3/3] Modified cleanup jobs info --- tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 | 4 ++++ tools/TestFx/Live/InvokeLiveTestScenarios.ps1 | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 b/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 index bad46c146a2b..65ef56e9b6e9 100644 --- a/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 +++ b/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 @@ -56,8 +56,12 @@ function InvokeLocalLiveTestScenarios { Write-Host "##[section]All cleanup jobs are completed." -ForegroundColor Green Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green + + Write-Host $cleanupJobs = Get-Job $cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output + Write-Host + Write-Host "##[endgroup]" $cleanupJobs | Remove-Job diff --git a/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 b/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 index b7b749e47eef..3d0d861927b8 100644 --- a/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 +++ b/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 @@ -93,14 +93,17 @@ $liveScenarios | ForEach-Object { Write-Host "##[section]Waiting for all cleanup jobs to be completed." -ForegroundColor Green while (Get-Job -State Running) { - Write-Host "[section]Waiting for 30 seconds ..." -ForegroundColor Green Start-Sleep -Seconds 30 } Write-Host "##[section]All cleanup jobs are completed." -ForegroundColor Green Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green + +Write-Host $cleanupJobs = Get-Job $cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output +Write-Host + Write-Host "##[endgroup]" $cleanupJobs | Remove-Job