Skip to content

Commit

Permalink
Shared/livetest (#21052)
Browse files Browse the repository at this point in the history
* Added live test cases for Network and DNS

* Added live test cases for modules Automation, Databricks and Functions
Added more detailed error info and enabled Debug preference during the last retry

* Updated live test to make it support no built-in resource group
  • Loading branch information
vidai-msft authored Feb 27, 2023
1 parent 8a45596 commit 49459fb
Showing 1 changed file with 25 additions and 19 deletions.
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

0 comments on commit 49459fb

Please sign in to comment.