Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared/livetest #21052

Merged
merged 5 commits into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions tools/TestFx/Live/LiveTestUtility.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function Invoke-LiveTestCommand {
}

function Invoke-LiveTestScenario {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = "HasDefaultResourceGroup")]
[OutputType([bool])]
param (
[Parameter(Mandatory, Position = 0)]
Expand All @@ -226,10 +226,13 @@ function Invoke-LiveTestScenario {
[ValidateNotNullOrEmpty()]
[string] $Description,

[Parameter()]
[Parameter(ParameterSetName = "HasDefaulResourceGroup")]
[ValidateNotNullOrEmpty()]
[string] $ResourceGroupLocation,

[Parameter(ParameterSetName = "HasNoDefaultResourceGroup")]
[switch] $NoResourceGroup,

[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[scriptblock] $ScenarioScript
Expand All @@ -256,32 +259,34 @@ function Invoke-LiveTestScenario {
Errors = ""
}

$snrResourceGroupName = New-LiveTestResourceGroupName
$snrResourceGroupLocation = "westus"
if ($PSBoundParameters.ContainsKey("ResourceGroupLocation")) {
$snrResourceGroupLocation = $ResourceGroupLocation
}
if (!$NoResourceGroup.IsPresent) {
$snrResourceGroupName = New-LiveTestResourceGroupName
$snrResourceGroupLocation = "westus"
if ($PSBoundParameters.ContainsKey("ResourceGroupLocation")) {
$snrResourceGroupLocation = $ResourceGroupLocation
}

Write-Host "##[section]Start to create a resource group." -ForegroundColor Green
Write-Host "##[section]Resource group name: $snrResourceGroupName" -ForegroundColor Green
Write-Host "##[section]Resource group location: $snrResourceGroupLocation" -ForegroundColor Green
Write-Host "##[section]Start to create 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
$snrResourceGroup = New-LiveTestResourceGroup -Name $snrResourceGroupName -Location $snrResourceGroupLocation

Write-Host "##[section]Successfully created the resource group." -ForegroundColor Green
Write-Host "##[section]Successfully created the resource group." -ForegroundColor Green
}

$snrRetryCount = 0
$snrRetryErrors = @()

do {
try {
$sPrefs = @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None"))
if ($snrRetryCount -eq $script:ScenarioMaxRetryCount) {
$ScenarioScript.InvokeWithContext($null, @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None"), [psvariable]::new("DebugPreference", "Continue")), $snrResourceGroup)
}
else {
$ScenarioScript.InvokeWithContext($null, @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None")), $snrResourceGroup)
$prefs += [psvariable]::new("DebugPreference", "Continue")
}

$ScenarioScript.InvokeWithContext($null, $prefs, $snrResourceGroup)

Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
break
}
Expand Down Expand Up @@ -346,7 +351,10 @@ function Invoke-LiveTestScenario {
$snrCsvData.Errors = ConvertToLiveTestJsonErrors -Errors $snrErrorMessage
}
finally {
if ($null -ne $snrResourceGroup) {
$snrCsvData.EndDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss")
$snrCsvData | Export-Csv -LiteralPath $script:LiveTestRawCsvFile -Encoding utf8 -NoTypeInformation -Append

if (!$NoResourceGroup.IsPresent -and $null -ne $snrResourceGroup) {
try {
Write-Host "##[section]Start to clean up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green
Clear-LiveTestResources -Name $snrResourceGroupName
Expand All @@ -355,8 +363,6 @@ function Invoke-LiveTestScenario {
# Ignore exception for clean up
}
}
$snrCsvData.EndDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss")
$snrCsvData | Export-Csv -LiteralPath $script:LiveTestRawCsvFile -Encoding utf8 -NoTypeInformation -Append

Write-Host "##[endgroup]"
}
Expand Down