Skip to content

Update smoke test script to support different PowerShell version #17579

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

Merged
merged 2 commits into from
Mar 25, 2022
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
193 changes: 101 additions & 92 deletions tools/Test/SmokeTest/RmCoreSmokeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ function Retry-AzCommand {
[CmdletBinding()]
param (
[string]
$Name,

[ScriptBlock]
$Command,

[int]
$RetryCount,
$Retry,

# Seconds between retries
[int]
Expand All @@ -49,16 +52,18 @@ function Retry-AzCommand {
$loopLimit = 0
do {
try {
&([scriptblock]::Create($Command))
$script = "`$ErrorActionPreference='Stop' `n"
$script += $Command.ToString()
&([ScriptBlock]::Create($script))
break
}
catch {
$commandName = ($Command -split ' ')[0]
if (++$loopLimit -gt $RetryCount)
if (++$loopLimit -gt $Retry)
{
throw "Failed to invoke $commandName. $_"
throw "Failed to invoke script of $Name. $_"
} else {
Write-Warning "Retry $commandName after $Sleep seconds"
Write-Warning "Retry $Name after $Sleep seconds"
Start-Sleep -Seconds $Sleep
}
}
Expand All @@ -71,94 +76,90 @@ $resourceGroupName = "azpssmokerg$randomValue"
$storageAccountName = "azpssmokesa$randomValue"

$resourceSetUpCommands=@(
@{Name = "Az.Resources"; Command = {New-AzResourceGroup -Name $resourceGroupName -Location westus -ErrorAction Stop}}
@{Name = "Az.Resources"; Command = {New-AzResourceGroup -Name $resourceGroupName -Location westus}}
)

$resourceCleanUpCommands = @(
@{Name = "Az.Storage [Cleanup]"; Command = {Retry-AzCommand -Command "Remove-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName -Force -ErrorAction Stop" -RetryCount 30 -Sleep 30}},
@{Name = "Az.Resources [Cleanup]"; Command = {Remove-AzResourceGroup -Name $resourceGroupName -Force -ErrorAction Stop}}
@{Name = "Az.Storage [Cleanup]"; Command = {Remove-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName -Force}; Retry=30; Sleep=30},
@{Name = "Az.Resources [Cleanup]"; Command = {Remove-AzResourceGroup -Name $resourceGroupName -Force}}
)

$resourceTestCommands = @(
@{Name = "Az.Storage [Management]"; Command = {New-AzStorageAccount -Name $storageAccountName -SkuName Standard_LRS -Location westus -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.Storage [Data]"; Command = {New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey 12345678 -ErrorAction Stop}},
@{Name = "Az.Storage [Data 1]"; Command = {Get-Command Get-AzStorageBlob -ErrorAction Stop}},
@{Name = "Az.Accounts"; Command = {Get-AzDomain -ErrorAction Stop}},
@{Name = "Az.Storage [Management]"; Command = {New-AzStorageAccount -Name $storageAccountName -SkuName Standard_LRS -Location westus -ResourceGroupName $resourceGroupName}},
@{Name = "Az.Storage [Data]"; Command = {New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey 12345678}},
@{Name = "Az.Storage [Data 1]"; Command = {Get-Command Get-AzStorageBlob}},
@{Name = "Az.Accounts"; Command = {Get-AzDomain}},
@{Name = "Az.Accounts [DefaultProfile]"; Command = {Get-AzSubscription -DefaultProfile (Get-AzContext)}},
@{Name = "Az.Advisor"; Command = {Get-AzAdvisorConfiguration -ErrorAction Stop}},
@{Name = "Az.Aks"; Command = {Get-AzAksCluster -ErrorAction Stop}},
@{Name = "Az.AnalysisServices"; Command = {Get-AzAnalysisServicesServer -ErrorAction Stop}},
@{Name = "Az.ApiManagement"; Command = {Get-AzApiManagement -ErrorAction Stop}},
@{Name = "Az.ApplicationInsights"; Command = {Get-AzApplicationInsights -ErrorAction Stop}},
@{Name = "Az.Automation"; Command = {Get-AzAutomationAccount -ErrorAction Stop}},
@{Name = "Az.Batch [MngmPlane]"; Command = {Get-AzBatchAccount -ErrorAction Stop}},
@{Name = "Az.Batch [DataPlane]"; Command = {Get-Command Get-AzBatchSupportedImage -ErrorAction Stop}},
@{Name = "Az.Billing"; Command = {Get-AzBillingInvoice -ErrorAction Stop}},
@{Name = "Az.Billing [Consumption]"; Command = {try {Get-AzConsumptionUsageDetail -ErrorAction Stop} catch {if ($_.ToString() -notlike "*422*" -and $_.ToString() -notlike "*UnprocessableEntity*" -and $_.ToString() -notlike "*BadRequest*") {throw $_}}}},
@{Name = "Az.Cdn"; Command = {Get-AzCdnProfile -ErrorAction Stop}},
@{Name = "Az.CognitiveServices"; Command = {Get-AzCognitiveServicesAccount -ErrorAction Stop}},
@{Name = "Az.Compute"; Command = {Get-AzVM -ErrorAction Stop}},
@{Name = "Az.ContainerInstance"; Command = {Get-AzContainerGroup -ErrorAction Stop}},
@{Name = "Az.ContainerRegistry [MngmPlane]"; Command = {Get-AzContainerRegistry -ErrorAction Stop}},
@{Name = "Az.ContainerRegistry [DataPlane]"; Command = {Get-Command Get-AzContainerRegistryManifest -ErrorAction Stop}},
@{Name = "Az.DataBoxEdge"; Command = {Get-AzDataBoxEdgeDevice -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.Databricks"; Command = {Get-AzDatabricksWorkspace -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.DataFactory [V1]"; Command = {Get-AzDataFactory -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.DataFactoryV2 [V2]"; Command = {Get-AzDataFactoryV2 -ErrorAction Stop}},
@{Name = "Az.DataLakeAnalytics"; Command = {Get-AzDataLakeAnalyticsAccount -ErrorAction Stop}},
@{Name = "Az.DataLakeStore [MngmPlane]"; Command = {Get-AzDataLakeStoreAccount -ErrorAction Stop}},
@{Name = "Az.DataLakeStore [DataPlane]"; Command = {Get-Command New-AzDataLakeStoreItem -ErrorAction Stop}},
@{Name = "Az.DataShare"; Command = {Get-AzDataShareAccount -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.Advisor"; Command = {Get-AzAdvisorConfiguration}},
@{Name = "Az.Aks"; Command = {Get-AzAksCluster}},
@{Name = "Az.AnalysisServices"; Command = {Get-AzAnalysisServicesServer}},
@{Name = "Az.ApiManagement"; Command = {Get-AzApiManagement}},
@{Name = "Az.ApplicationInsights"; Command = {Get-AzApplicationInsights}},
@{Name = "Az.Automation"; Command = {Get-AzAutomationAccount}},
@{Name = "Az.Batch [MngmPlane]"; Command = {Get-AzBatchAccount}},
@{Name = "Az.Batch [DataPlane]"; Command = {Get-Command Get-AzBatchSupportedImage}},
@{Name = "Az.Billing"; Command = {Get-AzBillingInvoice}},
@{Name = "Az.Billing [Consumption]"; Command = {Get-AzConsumptionBudget}},
@{Name = "Az.Cdn"; Command = {Get-AzCdnProfile}},
@{Name = "Az.CognitiveServices"; Command = {Get-AzCognitiveServicesAccount}},
@{Name = "Az.Compute"; Command = {Get-AzVM}; Since="7.0.0"},
@{Name = "Az.ContainerInstance"; Command = {Get-AzContainerGroup}},
@{Name = "Az.ContainerRegistry [MngmPlane]"; Command = {Get-AzContainerRegistry}},
@{Name = "Az.ContainerRegistry [DataPlane]"; Command = {Get-Command Get-AzContainerRegistryManifest}},
@{Name = "Az.DataBoxEdge"; Command = {Get-AzDataBoxEdgeDevice -ResourceGroupName $resourceGroupName}},
@{Name = "Az.Databricks"; Command = {Get-AzDatabricksWorkspace -ResourceGroupName $resourceGroupName}},
@{Name = "Az.DataFactory [V1]"; Command = {Get-AzDataFactory -ResourceGroupName $resourceGroupName}},
@{Name = "Az.DataFactoryV2 [V2]"; Command = {Get-AzDataFactoryV2}},
@{Name = "Az.DataLakeAnalytics"; Command = {Get-AzDataLakeAnalyticsAccount}},
@{Name = "Az.DataLakeStore [MngmPlane]"; Command = {Get-AzDataLakeStoreAccount}},
@{Name = "Az.DataLakeStore [DataPlane]"; Command = {Get-Command New-AzDataLakeStoreItem}},
@{Name = "Az.DataShare"; Command = {Get-AzDataShareAccount -ResourceGroupName $resourceGroupName}},
# Waiting for an issue fix: https://github.com/Azure/azure-powershell/issues/13522#issuecomment-728659457
# @{Name = "Az.DeploymentManager"; Command = {try {Get-AzDeploymentManagerArtifactSource -ResourceGroupName $resourceGroupName -ErrorAction Stop}catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
@{Name = "Az.DesktopVirtualization"; Command = {Get-AzWvdApplicationGroup -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.DevTestLabs "; Command = {try {Get-AzDtlAllowedVMSizesPolicy -LabName nonexistent -ResourceGroupName nonexistent -ErrorAction Stop} catch {if ($_.ToString() -notlike "*'nonexistent' could not be found.") {throw $_}}}},
@{Name = "Az.Dns"; Command = {Get-AzDnsZone -ErrorAction Stop}},
@{Name = "Az.EventGrid"; Command = {Get-AzEventGridTopic -ErrorAction Stop}},
@{Name = "Az.EventHub"; Command = {Get-AzEventHubNamespace -ErrorAction Stop}},
@{Name = "Az.FrontDoor"; Command = {Get-AzFrontDoor -ErrorAction Stop}},
@{Name = "Az.Functions"; Command = {Get-AzFunctionApp -ErrorAction Stop}},
@{Name = "Az.HDInsight "; Command = {Get-AzHDInsightCluster -ErrorAction Stop}},
@{Name = "Az.HealthcareApis"; Command = {Get-AzHealthcareApisService -ErrorAction Stop}},
@{Name = "Az.IotHub [MngmPlane]"; Command = {Get-AzIotHub -ErrorAction Stop}},
@{Name = "Az.IotHub [DataPlane]"; Command = {Get-Command Get-AzIotHubModuleConnectionString -ErrorAction Stop}},
@{Name = "Az.KeyVault [MngmPlane]"; Command = {Get-AzKeyVault -ErrorAction Stop}},
@{Name = "Az.KeyVault [DataPlane]"; Command = {Get-Command Get-AzKeyVaultKey -ErrorAction Stop}},
@{Name = "Az.Kusto"; Command = {Get-AzKustoCluster -ErrorAction Stop}},
@{Name = "Az.LogicApp"; Command = {Get-AzIntegrationAccount -ErrorAction Stop}},
@{Name = "Az.MachineLearning"; Command = {Get-AzMlWebService -ErrorAction Stop}},
@{Name = "Az.Maintenance"; Command = {Retry-AzCommand -Command "Get-AzMaintenanceConfiguration -ErrorAction Stop" -RetryCount 30 -Sleep 30}},
@{Name = "Az.ManagedServices"; Command = {Get-AzManagedServicesAssignment -ErrorAction Stop}},
# Machine learning compute cmdlets are removed. The following line are to be commented until they are brought back
# @{Name = "Az.MachineLearning [Compute]"; Command = {Get-AzMlOpCluster -ErrorAction Stop}},
@{Name = "Az.MarketplaceOrdering"; Command = {try {Get-AzMarketplaceTerms -Publisher nonexistent -Product nonexistent -Name nonexistent -ErrorAction Stop} catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
@{Name = "Az.Media"; Command = {Get-AzMediaService -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.Monitor"; Command = {Get-AzLogProfile -ErrorAction Stop}},
@{Name = "Az.Network"; Command = {Get-AzNetworkInterface -ErrorAction Stop}},
@{Name = "Az.NotificationHubs"; Command = {Get-AzNotificationHubsNamespace -ErrorAction Stop}},
@{Name = "Az.OperationalInsights [MngmPlane]"; Command = {Get-AzOperationalInsightsWorkspace -ErrorAction Stop}},
@{Name = "Az.OperationalInsights [DataPlane]"; Command = {Get-Command Invoke-AzOperationalInsightsQuery -ErrorAction Stop}},
@{Name = "Az.PolicyInsights"; Command = {Get-AzPolicyEvent -Top 10 -ErrorAction Stop}}, # without -Top service may return 400: ResponseTooLarge
@{Name = "Az.PowerBIEmbedded"; Command = {Get-AzPowerBIEmbeddedCapacity -ErrorAction Stop}},
@{Name = "Az.PowerBIUEmbedded"; Command = {Get-AzPowerBIWorkspaceCollection -ErrorAction Stop}},
@{Name = "Az.PrivateDns"; Command = {Get-AzPrivateDnsZone -ErrorAction Stop}},
@{Name = "Az.RecoveryServices"; Command = {Get-AzRecoveryServicesVault -ErrorAction Stop}},
@{Name = "Az.RedisCache"; Command = {Get-AzRedisCache -ErrorAction Stop}},
@{Name = "Az.Relay"; Command = {Get-AzRelayNamespace -ErrorAction Stop}},
@{Name = "Az.ServiceBus"; Command = {Get-AzServiceBusNamespace -ErrorAction Stop}},
@{Name = "Az.ServiceFabric [MngmPlane]"; Command = {Get-AzServiceFabricCluster -ErrorAction Stop}},
@{Name = "Az.ServiceFabric [DataPlane]"; Command = {Get-Command New-AzServiceFabricCluster -ErrorAction Stop}},
@{Name = "Az.SignalR"; Command = {Get-AzSignalR -ErrorAction Stop}},
@{Name = "Az.Sql"; Command = {Get-AzSqlServer -ErrorAction Stop}},
@{Name = "Az.SqlVirtualMachine"; Command = {Get-AzSqlVM -ErrorAction Stop}},
@{Name = "Az.StreamAnalytics"; Command = {Get-AzStreamAnalyticsJob -ErrorAction Stop}},
@{Name = "Az.StorageSync"; Command = {Get-AzStorageSyncService -ErrorAction Stop}},
@{Name = "Az.Support"; Command = {Get-AzSupportTicket -ErrorAction Stop}},
@{Name = "Az.Resources [Tags]"; Command = {Get-AzTag -ErrorAction Stop}},
#@{Name = "Az.Resources [MSGraph]"; Command = {Get-AzAdGroup -First 1 -ErrorAction Stop}},
@{Name = "Az.TrafficManager"; Command = {Get-AzTrafficManagerProfile -ErrorAction Stop}},
@{Name = "Az.Billing [UsageAggregates]"; Command = {Get-UsageAggregates -ReportedStartTime '1/1/2018' -ReportedEndTime '1/2/2018' -ErrorAction Stop}},
@{Name = "Az.Websites"; Command = {Get-AzWebApp -ErrorAction Stop}}
# @{Name = "Az.DeploymentManager"; Command = {try {Get-AzDeploymentManagerArtifactSource -ResourceGroupName $resourceGroupName }catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
@{Name = "Az.DesktopVirtualization"; Command = {Get-AzWvdApplicationGroup -ResourceGroupName $resourceGroupName}},
@{Name = "Az.Dns"; Command = {Get-AzDnsZone}},
@{Name = "Az.EventGrid"; Command = {Get-AzEventGridTopic}},
@{Name = "Az.EventHub"; Command = {Get-AzEventHubNamespace}},
@{Name = "Az.FrontDoor"; Command = {Get-AzFrontDoor}},
@{Name = "Az.Functions"; Command = {Get-AzFunctionApp}},
@{Name = "Az.HDInsight "; Command = {Get-AzHDInsightCluster}},
@{Name = "Az.HealthcareApis"; Command = {Get-AzHealthcareApisService}},
@{Name = "Az.IotHub [MngmPlane]"; Command = {Get-AzIotHub}},
@{Name = "Az.IotHub [DataPlane]"; Command = {Get-Command Get-AzIotHubModuleConnectionString}},
@{Name = "Az.KeyVault [MngmPlane]"; Command = {Get-AzKeyVault}},
@{Name = "Az.KeyVault [DataPlane]"; Command = {Get-Command Get-AzKeyVaultKey}},
@{Name = "Az.Kusto"; Command = {Get-AzKustoCluster}},
@{Name = "Az.LogicApp"; Command = {Get-AzIntegrationAccount}},
@{Name = "Az.MachineLearning"; Command = {Get-AzMlWebService}},
@{Name = "Az.Maintenance"; Command = {Get-AzMaintenanceConfiguration}; Retry=30; Sleep=30},
@{Name = "Az.ManagedServices"; Command = {Get-AzManagedServicesAssignment}},
@{Name = "Az.Media"; Command = {Get-AzMediaService -ResourceGroupName $resourceGroupName}},
@{Name = "Az.Monitor"; Command = {Get-AzLogProfile}},
@{Name = "Az.Network"; Command = {Get-AzNetworkInterface}},
@{Name = "Az.NotificationHubs"; Command = {Get-AzNotificationHubsNamespace}},
@{Name = "Az.OperationalInsights [MngmPlane]"; Command = {Get-AzOperationalInsightsWorkspace}},
@{Name = "Az.OperationalInsights [DataPlane]"; Command = {Get-Command Invoke-AzOperationalInsightsQuery}},
@{Name = "Az.PolicyInsights"; Command = {Get-AzPolicyEvent -Top 10}}, # without -Top service may return 400: ResponseTooLarge
@{Name = "Az.PowerBIEmbedded"; Command = {Get-AzPowerBIEmbeddedCapacity}},
@{Name = "Az.PowerBIUEmbedded"; Command = {Get-AzPowerBIWorkspaceCollection}},
@{Name = "Az.PrivateDns"; Command = {Get-AzPrivateDnsZone}},
@{Name = "Az.RecoveryServices"; Command = {Get-AzRecoveryServicesVault}},
@{Name = "Az.RedisCache"; Command = {Get-AzRedisCache}},
@{Name = "Az.Relay"; Command = {Get-AzRelayNamespace}},
@{Name = "Az.ServiceBus"; Command = {Get-AzServiceBusNamespace}},
@{Name = "Az.ServiceFabric [MngmPlane]"; Command = {Get-AzServiceFabricCluster}},
@{Name = "Az.ServiceFabric [DataPlane]"; Command = {Get-Command New-AzServiceFabricCluster}},
@{Name = "Az.SignalR"; Command = {Get-AzSignalR}},
@{Name = "Az.Sql"; Command = {Get-AzSqlServer}},
@{Name = "Az.SqlVirtualMachine"; Command = {Get-AzSqlVM}},
@{Name = "Az.StreamAnalytics"; Command = {Get-AzStreamAnalyticsJob}},
@{Name = "Az.StorageSync"; Command = {Get-AzStorageSyncService}},
@{Name = "Az.Support"; Command = {Get-AzSupportTicket}},
@{Name = "Az.Resources [Tags]"; Command = {Get-AzTag}},
@{Name = "Az.Resources [MSGraph]"; Command = {Get-AzAdGroup -First 1}},
@{Name = "Az.TrafficManager"; Command = {Get-AzTrafficManagerProfile}},
@{Name = "Az.Billing [UsageAggregates]"; Command = {Get-UsageAggregates -ReportedStartTime '1/1/2018' -ReportedEndTime '1/2/2018'}},
@{Name = "Az.Websites"; Command = {Get-AzWebApp -ResourceGroupName $resourceGroupName}}
)

if($Reverse.IsPresent){
Expand All @@ -171,20 +172,27 @@ $startTime = Get-Date
$resourceCommands | ForEach-Object {
$testName = $_.Name
$script = $_.Command
$retry = if($null -eq $_.retry) {0} Else {$_.retry}
$sleep = if($null -eq $_.sleep) {30} Else {$_.sleep}
if($null -ne $_.Since -and "Core" -eq $PSVersionTable.PSEdition -and $PSVersionTable.PSVersion -lt [System.Version]$_.Since) {
Write-Output "Skip test $testName"
$testInfo.SkippedCount += 1
return
}
Write-Output "Running test $testName"
$testStart = Get-Date
try
{
&$script
$testInfo.PassedCount += 1
$testInfo.PassedTests += $testName
Retry-AzCommand -Name $testName -Command $script -Retry $retry -Sleep $sleep
$testInfo.PassedCount += 1
$testInfo.PassedTests += $testName
}
catch
{
Write-Error $_.Exception
$detail = Resolve-AzError -Last
$testInfo.FailureDetails += (New-Object PSObject -Property @{Name = $testName; Details = $detail})
$testInfo.FailedTests += $testName
Write-Error $_.Exception
$detail = Resolve-AzError -Last
$testInfo.FailureDetails += (New-Object PSObject -Property @{Name = $testName; Details = $detail})
$testInfo.FailedTests += $testName
}
finally
{
Expand All @@ -203,6 +211,7 @@ $endTime = Get-Date
Elapsed = $endTime - $startTime;
TotalTests = $testInfo.TotalCount;
PassedTests = $testInfo.PassedTests;
SkippedTests = $testInfo.SkippedCount;
FailedTests = $testInfo.FailedTests
} | Write-Output

Expand Down