Skip to content

Commit 69fe9d3

Browse files
authored
Update smoke test script to support different PowerShell version (#17579)
* Update smoke test script to support different PowerShell version * Update code
1 parent e5b56d8 commit 69fe9d3

File tree

1 file changed

+101
-92
lines changed

1 file changed

+101
-92
lines changed

tools/Test/SmokeTest/RmCoreSmokeTests.ps1

Lines changed: 101 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ function Retry-AzCommand {
3737
[CmdletBinding()]
3838
param (
3939
[string]
40+
$Name,
41+
42+
[ScriptBlock]
4043
$Command,
4144

4245
[int]
43-
$RetryCount,
46+
$Retry,
4447

4548
# Seconds between retries
4649
[int]
@@ -49,16 +52,18 @@ function Retry-AzCommand {
4952
$loopLimit = 0
5053
do {
5154
try {
52-
&([scriptblock]::Create($Command))
55+
$script = "`$ErrorActionPreference='Stop' `n"
56+
$script += $Command.ToString()
57+
&([ScriptBlock]::Create($script))
5358
break
5459
}
5560
catch {
5661
$commandName = ($Command -split ' ')[0]
57-
if (++$loopLimit -gt $RetryCount)
62+
if (++$loopLimit -gt $Retry)
5863
{
59-
throw "Failed to invoke $commandName. $_"
64+
throw "Failed to invoke script of $Name. $_"
6065
} else {
61-
Write-Warning "Retry $commandName after $Sleep seconds"
66+
Write-Warning "Retry $Name after $Sleep seconds"
6267
Start-Sleep -Seconds $Sleep
6368
}
6469
}
@@ -71,94 +76,90 @@ $resourceGroupName = "azpssmokerg$randomValue"
7176
$storageAccountName = "azpssmokesa$randomValue"
7277

7378
$resourceSetUpCommands=@(
74-
@{Name = "Az.Resources"; Command = {New-AzResourceGroup -Name $resourceGroupName -Location westus -ErrorAction Stop}}
79+
@{Name = "Az.Resources"; Command = {New-AzResourceGroup -Name $resourceGroupName -Location westus}}
7580
)
7681

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

8287
$resourceTestCommands = @(
83-
@{Name = "Az.Storage [Management]"; Command = {New-AzStorageAccount -Name $storageAccountName -SkuName Standard_LRS -Location westus -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
84-
@{Name = "Az.Storage [Data]"; Command = {New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey 12345678 -ErrorAction Stop}},
85-
@{Name = "Az.Storage [Data 1]"; Command = {Get-Command Get-AzStorageBlob -ErrorAction Stop}},
86-
@{Name = "Az.Accounts"; Command = {Get-AzDomain -ErrorAction Stop}},
88+
@{Name = "Az.Storage [Management]"; Command = {New-AzStorageAccount -Name $storageAccountName -SkuName Standard_LRS -Location westus -ResourceGroupName $resourceGroupName}},
89+
@{Name = "Az.Storage [Data]"; Command = {New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey 12345678}},
90+
@{Name = "Az.Storage [Data 1]"; Command = {Get-Command Get-AzStorageBlob}},
91+
@{Name = "Az.Accounts"; Command = {Get-AzDomain}},
8792
@{Name = "Az.Accounts [DefaultProfile]"; Command = {Get-AzSubscription -DefaultProfile (Get-AzContext)}},
88-
@{Name = "Az.Advisor"; Command = {Get-AzAdvisorConfiguration -ErrorAction Stop}},
89-
@{Name = "Az.Aks"; Command = {Get-AzAksCluster -ErrorAction Stop}},
90-
@{Name = "Az.AnalysisServices"; Command = {Get-AzAnalysisServicesServer -ErrorAction Stop}},
91-
@{Name = "Az.ApiManagement"; Command = {Get-AzApiManagement -ErrorAction Stop}},
92-
@{Name = "Az.ApplicationInsights"; Command = {Get-AzApplicationInsights -ErrorAction Stop}},
93-
@{Name = "Az.Automation"; Command = {Get-AzAutomationAccount -ErrorAction Stop}},
94-
@{Name = "Az.Batch [MngmPlane]"; Command = {Get-AzBatchAccount -ErrorAction Stop}},
95-
@{Name = "Az.Batch [DataPlane]"; Command = {Get-Command Get-AzBatchSupportedImage -ErrorAction Stop}},
96-
@{Name = "Az.Billing"; Command = {Get-AzBillingInvoice -ErrorAction Stop}},
97-
@{Name = "Az.Billing [Consumption]"; Command = {try {Get-AzConsumptionUsageDetail -ErrorAction Stop} catch {if ($_.ToString() -notlike "*422*" -and $_.ToString() -notlike "*UnprocessableEntity*" -and $_.ToString() -notlike "*BadRequest*") {throw $_}}}},
98-
@{Name = "Az.Cdn"; Command = {Get-AzCdnProfile -ErrorAction Stop}},
99-
@{Name = "Az.CognitiveServices"; Command = {Get-AzCognitiveServicesAccount -ErrorAction Stop}},
100-
@{Name = "Az.Compute"; Command = {Get-AzVM -ErrorAction Stop}},
101-
@{Name = "Az.ContainerInstance"; Command = {Get-AzContainerGroup -ErrorAction Stop}},
102-
@{Name = "Az.ContainerRegistry [MngmPlane]"; Command = {Get-AzContainerRegistry -ErrorAction Stop}},
103-
@{Name = "Az.ContainerRegistry [DataPlane]"; Command = {Get-Command Get-AzContainerRegistryManifest -ErrorAction Stop}},
104-
@{Name = "Az.DataBoxEdge"; Command = {Get-AzDataBoxEdgeDevice -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
105-
@{Name = "Az.Databricks"; Command = {Get-AzDatabricksWorkspace -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
106-
@{Name = "Az.DataFactory [V1]"; Command = {Get-AzDataFactory -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
107-
@{Name = "Az.DataFactoryV2 [V2]"; Command = {Get-AzDataFactoryV2 -ErrorAction Stop}},
108-
@{Name = "Az.DataLakeAnalytics"; Command = {Get-AzDataLakeAnalyticsAccount -ErrorAction Stop}},
109-
@{Name = "Az.DataLakeStore [MngmPlane]"; Command = {Get-AzDataLakeStoreAccount -ErrorAction Stop}},
110-
@{Name = "Az.DataLakeStore [DataPlane]"; Command = {Get-Command New-AzDataLakeStoreItem -ErrorAction Stop}},
111-
@{Name = "Az.DataShare"; Command = {Get-AzDataShareAccount -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
93+
@{Name = "Az.Advisor"; Command = {Get-AzAdvisorConfiguration}},
94+
@{Name = "Az.Aks"; Command = {Get-AzAksCluster}},
95+
@{Name = "Az.AnalysisServices"; Command = {Get-AzAnalysisServicesServer}},
96+
@{Name = "Az.ApiManagement"; Command = {Get-AzApiManagement}},
97+
@{Name = "Az.ApplicationInsights"; Command = {Get-AzApplicationInsights}},
98+
@{Name = "Az.Automation"; Command = {Get-AzAutomationAccount}},
99+
@{Name = "Az.Batch [MngmPlane]"; Command = {Get-AzBatchAccount}},
100+
@{Name = "Az.Batch [DataPlane]"; Command = {Get-Command Get-AzBatchSupportedImage}},
101+
@{Name = "Az.Billing"; Command = {Get-AzBillingInvoice}},
102+
@{Name = "Az.Billing [Consumption]"; Command = {Get-AzConsumptionBudget}},
103+
@{Name = "Az.Cdn"; Command = {Get-AzCdnProfile}},
104+
@{Name = "Az.CognitiveServices"; Command = {Get-AzCognitiveServicesAccount}},
105+
@{Name = "Az.Compute"; Command = {Get-AzVM}; Since="7.0.0"},
106+
@{Name = "Az.ContainerInstance"; Command = {Get-AzContainerGroup}},
107+
@{Name = "Az.ContainerRegistry [MngmPlane]"; Command = {Get-AzContainerRegistry}},
108+
@{Name = "Az.ContainerRegistry [DataPlane]"; Command = {Get-Command Get-AzContainerRegistryManifest}},
109+
@{Name = "Az.DataBoxEdge"; Command = {Get-AzDataBoxEdgeDevice -ResourceGroupName $resourceGroupName}},
110+
@{Name = "Az.Databricks"; Command = {Get-AzDatabricksWorkspace -ResourceGroupName $resourceGroupName}},
111+
@{Name = "Az.DataFactory [V1]"; Command = {Get-AzDataFactory -ResourceGroupName $resourceGroupName}},
112+
@{Name = "Az.DataFactoryV2 [V2]"; Command = {Get-AzDataFactoryV2}},
113+
@{Name = "Az.DataLakeAnalytics"; Command = {Get-AzDataLakeAnalyticsAccount}},
114+
@{Name = "Az.DataLakeStore [MngmPlane]"; Command = {Get-AzDataLakeStoreAccount}},
115+
@{Name = "Az.DataLakeStore [DataPlane]"; Command = {Get-Command New-AzDataLakeStoreItem}},
116+
@{Name = "Az.DataShare"; Command = {Get-AzDataShareAccount -ResourceGroupName $resourceGroupName}},
112117
# Waiting for an issue fix: https://github.com/Azure/azure-powershell/issues/13522#issuecomment-728659457
113-
# @{Name = "Az.DeploymentManager"; Command = {try {Get-AzDeploymentManagerArtifactSource -ResourceGroupName $resourceGroupName -ErrorAction Stop}catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
114-
@{Name = "Az.DesktopVirtualization"; Command = {Get-AzWvdApplicationGroup -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
115-
@{Name = "Az.DevTestLabs "; Command = {try {Get-AzDtlAllowedVMSizesPolicy -LabName nonexistent -ResourceGroupName nonexistent -ErrorAction Stop} catch {if ($_.ToString() -notlike "*'nonexistent' could not be found.") {throw $_}}}},
116-
@{Name = "Az.Dns"; Command = {Get-AzDnsZone -ErrorAction Stop}},
117-
@{Name = "Az.EventGrid"; Command = {Get-AzEventGridTopic -ErrorAction Stop}},
118-
@{Name = "Az.EventHub"; Command = {Get-AzEventHubNamespace -ErrorAction Stop}},
119-
@{Name = "Az.FrontDoor"; Command = {Get-AzFrontDoor -ErrorAction Stop}},
120-
@{Name = "Az.Functions"; Command = {Get-AzFunctionApp -ErrorAction Stop}},
121-
@{Name = "Az.HDInsight "; Command = {Get-AzHDInsightCluster -ErrorAction Stop}},
122-
@{Name = "Az.HealthcareApis"; Command = {Get-AzHealthcareApisService -ErrorAction Stop}},
123-
@{Name = "Az.IotHub [MngmPlane]"; Command = {Get-AzIotHub -ErrorAction Stop}},
124-
@{Name = "Az.IotHub [DataPlane]"; Command = {Get-Command Get-AzIotHubModuleConnectionString -ErrorAction Stop}},
125-
@{Name = "Az.KeyVault [MngmPlane]"; Command = {Get-AzKeyVault -ErrorAction Stop}},
126-
@{Name = "Az.KeyVault [DataPlane]"; Command = {Get-Command Get-AzKeyVaultKey -ErrorAction Stop}},
127-
@{Name = "Az.Kusto"; Command = {Get-AzKustoCluster -ErrorAction Stop}},
128-
@{Name = "Az.LogicApp"; Command = {Get-AzIntegrationAccount -ErrorAction Stop}},
129-
@{Name = "Az.MachineLearning"; Command = {Get-AzMlWebService -ErrorAction Stop}},
130-
@{Name = "Az.Maintenance"; Command = {Retry-AzCommand -Command "Get-AzMaintenanceConfiguration -ErrorAction Stop" -RetryCount 30 -Sleep 30}},
131-
@{Name = "Az.ManagedServices"; Command = {Get-AzManagedServicesAssignment -ErrorAction Stop}},
132-
# Machine learning compute cmdlets are removed. The following line are to be commented until they are brought back
133-
# @{Name = "Az.MachineLearning [Compute]"; Command = {Get-AzMlOpCluster -ErrorAction Stop}},
134-
@{Name = "Az.MarketplaceOrdering"; Command = {try {Get-AzMarketplaceTerms -Publisher nonexistent -Product nonexistent -Name nonexistent -ErrorAction Stop} catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
135-
@{Name = "Az.Media"; Command = {Get-AzMediaService -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
136-
@{Name = "Az.Monitor"; Command = {Get-AzLogProfile -ErrorAction Stop}},
137-
@{Name = "Az.Network"; Command = {Get-AzNetworkInterface -ErrorAction Stop}},
138-
@{Name = "Az.NotificationHubs"; Command = {Get-AzNotificationHubsNamespace -ErrorAction Stop}},
139-
@{Name = "Az.OperationalInsights [MngmPlane]"; Command = {Get-AzOperationalInsightsWorkspace -ErrorAction Stop}},
140-
@{Name = "Az.OperationalInsights [DataPlane]"; Command = {Get-Command Invoke-AzOperationalInsightsQuery -ErrorAction Stop}},
141-
@{Name = "Az.PolicyInsights"; Command = {Get-AzPolicyEvent -Top 10 -ErrorAction Stop}}, # without -Top service may return 400: ResponseTooLarge
142-
@{Name = "Az.PowerBIEmbedded"; Command = {Get-AzPowerBIEmbeddedCapacity -ErrorAction Stop}},
143-
@{Name = "Az.PowerBIUEmbedded"; Command = {Get-AzPowerBIWorkspaceCollection -ErrorAction Stop}},
144-
@{Name = "Az.PrivateDns"; Command = {Get-AzPrivateDnsZone -ErrorAction Stop}},
145-
@{Name = "Az.RecoveryServices"; Command = {Get-AzRecoveryServicesVault -ErrorAction Stop}},
146-
@{Name = "Az.RedisCache"; Command = {Get-AzRedisCache -ErrorAction Stop}},
147-
@{Name = "Az.Relay"; Command = {Get-AzRelayNamespace -ErrorAction Stop}},
148-
@{Name = "Az.ServiceBus"; Command = {Get-AzServiceBusNamespace -ErrorAction Stop}},
149-
@{Name = "Az.ServiceFabric [MngmPlane]"; Command = {Get-AzServiceFabricCluster -ErrorAction Stop}},
150-
@{Name = "Az.ServiceFabric [DataPlane]"; Command = {Get-Command New-AzServiceFabricCluster -ErrorAction Stop}},
151-
@{Name = "Az.SignalR"; Command = {Get-AzSignalR -ErrorAction Stop}},
152-
@{Name = "Az.Sql"; Command = {Get-AzSqlServer -ErrorAction Stop}},
153-
@{Name = "Az.SqlVirtualMachine"; Command = {Get-AzSqlVM -ErrorAction Stop}},
154-
@{Name = "Az.StreamAnalytics"; Command = {Get-AzStreamAnalyticsJob -ErrorAction Stop}},
155-
@{Name = "Az.StorageSync"; Command = {Get-AzStorageSyncService -ErrorAction Stop}},
156-
@{Name = "Az.Support"; Command = {Get-AzSupportTicket -ErrorAction Stop}},
157-
@{Name = "Az.Resources [Tags]"; Command = {Get-AzTag -ErrorAction Stop}},
158-
#@{Name = "Az.Resources [MSGraph]"; Command = {Get-AzAdGroup -First 1 -ErrorAction Stop}},
159-
@{Name = "Az.TrafficManager"; Command = {Get-AzTrafficManagerProfile -ErrorAction Stop}},
160-
@{Name = "Az.Billing [UsageAggregates]"; Command = {Get-UsageAggregates -ReportedStartTime '1/1/2018' -ReportedEndTime '1/2/2018' -ErrorAction Stop}},
161-
@{Name = "Az.Websites"; Command = {Get-AzWebApp -ErrorAction Stop}}
118+
# @{Name = "Az.DeploymentManager"; Command = {try {Get-AzDeploymentManagerArtifactSource -ResourceGroupName $resourceGroupName }catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
119+
@{Name = "Az.DesktopVirtualization"; Command = {Get-AzWvdApplicationGroup -ResourceGroupName $resourceGroupName}},
120+
@{Name = "Az.Dns"; Command = {Get-AzDnsZone}},
121+
@{Name = "Az.EventGrid"; Command = {Get-AzEventGridTopic}},
122+
@{Name = "Az.EventHub"; Command = {Get-AzEventHubNamespace}},
123+
@{Name = "Az.FrontDoor"; Command = {Get-AzFrontDoor}},
124+
@{Name = "Az.Functions"; Command = {Get-AzFunctionApp}},
125+
@{Name = "Az.HDInsight "; Command = {Get-AzHDInsightCluster}},
126+
@{Name = "Az.HealthcareApis"; Command = {Get-AzHealthcareApisService}},
127+
@{Name = "Az.IotHub [MngmPlane]"; Command = {Get-AzIotHub}},
128+
@{Name = "Az.IotHub [DataPlane]"; Command = {Get-Command Get-AzIotHubModuleConnectionString}},
129+
@{Name = "Az.KeyVault [MngmPlane]"; Command = {Get-AzKeyVault}},
130+
@{Name = "Az.KeyVault [DataPlane]"; Command = {Get-Command Get-AzKeyVaultKey}},
131+
@{Name = "Az.Kusto"; Command = {Get-AzKustoCluster}},
132+
@{Name = "Az.LogicApp"; Command = {Get-AzIntegrationAccount}},
133+
@{Name = "Az.MachineLearning"; Command = {Get-AzMlWebService}},
134+
@{Name = "Az.Maintenance"; Command = {Get-AzMaintenanceConfiguration}; Retry=30; Sleep=30},
135+
@{Name = "Az.ManagedServices"; Command = {Get-AzManagedServicesAssignment}},
136+
@{Name = "Az.Media"; Command = {Get-AzMediaService -ResourceGroupName $resourceGroupName}},
137+
@{Name = "Az.Monitor"; Command = {Get-AzLogProfile}},
138+
@{Name = "Az.Network"; Command = {Get-AzNetworkInterface}},
139+
@{Name = "Az.NotificationHubs"; Command = {Get-AzNotificationHubsNamespace}},
140+
@{Name = "Az.OperationalInsights [MngmPlane]"; Command = {Get-AzOperationalInsightsWorkspace}},
141+
@{Name = "Az.OperationalInsights [DataPlane]"; Command = {Get-Command Invoke-AzOperationalInsightsQuery}},
142+
@{Name = "Az.PolicyInsights"; Command = {Get-AzPolicyEvent -Top 10}}, # without -Top service may return 400: ResponseTooLarge
143+
@{Name = "Az.PowerBIEmbedded"; Command = {Get-AzPowerBIEmbeddedCapacity}},
144+
@{Name = "Az.PowerBIUEmbedded"; Command = {Get-AzPowerBIWorkspaceCollection}},
145+
@{Name = "Az.PrivateDns"; Command = {Get-AzPrivateDnsZone}},
146+
@{Name = "Az.RecoveryServices"; Command = {Get-AzRecoveryServicesVault}},
147+
@{Name = "Az.RedisCache"; Command = {Get-AzRedisCache}},
148+
@{Name = "Az.Relay"; Command = {Get-AzRelayNamespace}},
149+
@{Name = "Az.ServiceBus"; Command = {Get-AzServiceBusNamespace}},
150+
@{Name = "Az.ServiceFabric [MngmPlane]"; Command = {Get-AzServiceFabricCluster}},
151+
@{Name = "Az.ServiceFabric [DataPlane]"; Command = {Get-Command New-AzServiceFabricCluster}},
152+
@{Name = "Az.SignalR"; Command = {Get-AzSignalR}},
153+
@{Name = "Az.Sql"; Command = {Get-AzSqlServer}},
154+
@{Name = "Az.SqlVirtualMachine"; Command = {Get-AzSqlVM}},
155+
@{Name = "Az.StreamAnalytics"; Command = {Get-AzStreamAnalyticsJob}},
156+
@{Name = "Az.StorageSync"; Command = {Get-AzStorageSyncService}},
157+
@{Name = "Az.Support"; Command = {Get-AzSupportTicket}},
158+
@{Name = "Az.Resources [Tags]"; Command = {Get-AzTag}},
159+
@{Name = "Az.Resources [MSGraph]"; Command = {Get-AzAdGroup -First 1}},
160+
@{Name = "Az.TrafficManager"; Command = {Get-AzTrafficManagerProfile}},
161+
@{Name = "Az.Billing [UsageAggregates]"; Command = {Get-UsageAggregates -ReportedStartTime '1/1/2018' -ReportedEndTime '1/2/2018'}},
162+
@{Name = "Az.Websites"; Command = {Get-AzWebApp -ResourceGroupName $resourceGroupName}}
162163
)
163164

164165
if($Reverse.IsPresent){
@@ -171,20 +172,27 @@ $startTime = Get-Date
171172
$resourceCommands | ForEach-Object {
172173
$testName = $_.Name
173174
$script = $_.Command
175+
$retry = if($null -eq $_.retry) {0} Else {$_.retry}
176+
$sleep = if($null -eq $_.sleep) {30} Else {$_.sleep}
177+
if($null -ne $_.Since -and "Core" -eq $PSVersionTable.PSEdition -and $PSVersionTable.PSVersion -lt [System.Version]$_.Since) {
178+
Write-Output "Skip test $testName"
179+
$testInfo.SkippedCount += 1
180+
return
181+
}
174182
Write-Output "Running test $testName"
175183
$testStart = Get-Date
176184
try
177185
{
178-
&$script
179-
$testInfo.PassedCount += 1
180-
$testInfo.PassedTests += $testName
186+
Retry-AzCommand -Name $testName -Command $script -Retry $retry -Sleep $sleep
187+
$testInfo.PassedCount += 1
188+
$testInfo.PassedTests += $testName
181189
}
182190
catch
183191
{
184-
Write-Error $_.Exception
185-
$detail = Resolve-AzError -Last
186-
$testInfo.FailureDetails += (New-Object PSObject -Property @{Name = $testName; Details = $detail})
187-
$testInfo.FailedTests += $testName
192+
Write-Error $_.Exception
193+
$detail = Resolve-AzError -Last
194+
$testInfo.FailureDetails += (New-Object PSObject -Property @{Name = $testName; Details = $detail})
195+
$testInfo.FailedTests += $testName
188196
}
189197
finally
190198
{
@@ -203,6 +211,7 @@ $endTime = Get-Date
203211
Elapsed = $endTime - $startTime;
204212
TotalTests = $testInfo.TotalCount;
205213
PassedTests = $testInfo.PassedTests;
214+
SkippedTests = $testInfo.SkippedCount;
206215
FailedTests = $testInfo.FailedTests
207216
} | Write-Output
208217

0 commit comments

Comments
 (0)