Skip to content

Commit 2ad4b83

Browse files
authored
Modified SmokeTest/RmCoreSmokeTests.ps1. (#13883)
Force merge it due to Macos out of time. * Modified SmokeTest/RmCoreSmokeTests.ps1. * updated file SmokeTest/RmCoreSmokeTests.ps1. * Remove comment in SmokeTest/RmCoreSmokeTests.ps1. * Removed logic of the Az.Resources [Cleanup] in SmokeTest/RmCoreSmokeTests.ps1. * throw exception when the storage clean up failed in SmokeTest/RmCoreSmokeTests.ps1. * Remove break code after throw code in SmokeTest/RmCoreSmokeTests.ps1. * Add Retry-AzCommand function in SmokeTest/RmCoreSmokeTests.ps1
1 parent a29cc98 commit 2ad4b83

File tree

1 file changed

+84
-49
lines changed

1 file changed

+84
-49
lines changed

tools/Test/SmokeTest/RmCoreSmokeTests.ps1

Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,89 +31,124 @@ for($i=0; $i -lt 9; $i++)
3131
{
3232
$randomValue += $strarray[(Get-Random -Maximum $strarray.Length)]
3333
}
34+
35+
# Retry azure powershell command.
36+
function Retry-AzCommand {
37+
[CmdletBinding()]
38+
param (
39+
[string]
40+
$Command,
41+
42+
[int]
43+
$RetryCount,
44+
45+
# Seconds between retries
46+
[int]
47+
$Sleep
48+
)
49+
$loopLimit = 0
50+
do {
51+
try {
52+
&([scriptblock]::Create($Command))
53+
break
54+
}
55+
catch {
56+
$commandName = ($Command -split ' ')[0]
57+
if (++$loopLimit -gt $RetryCount)
58+
{
59+
throw "Failed to invoke $commandName. $_"
60+
} else {
61+
Write-Warning "Retry $commandName after $Sleep seconds"
62+
Start-Sleep -Seconds $Sleep
63+
}
64+
}
65+
} while ($true)
66+
}
67+
3468
# The name of resource group is 1~90 charactors complying with ^[-\w\._\(\)]+$
3569
$resourceGroupName = "azpssmokerg$randomValue"
3670
# The name of storage account should be 3~24 lowercase letters and numbers.
3771
$storageAccountName = "azpssmokesa$randomValue"
3872

3973
$resourceSetUpCommands=@(
40-
@{Name = "Az.Resources"; Command = {New-AzureRmResourceGroup -Name $resourceGroupName -Location westus -ErrorAction Stop}}
74+
@{Name = "Az.Resources"; Command = {New-AzResourceGroup -Name $resourceGroupName -Location westus -ErrorAction Stop}}
4175
)
76+
4277
$resourceCleanUpCommands = @(
43-
@{Name = "Az.Storage [Cleanup]"; Command = {Remove-AzureRmStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName -Force -ErrorAction Stop}},
44-
@{Name = "Az.Resources [Cleanup]"; Command = {Remove-AzureRmResourceGroup -Name $resourceGroupName -Force -ErrorAction Stop}}
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}}
4580
)
81+
4682
$resourceTestCommands = @(
47-
@{Name = "Az.Storage [Management]"; Command = {New-AzureRmStorageAccount -Name $storageAccountName -SkuName Standard_LRS -Location westus -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
48-
@{Name = "Az.Storage [Data]"; Command = {New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey 12345678 -ErrorAction Stop}},
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}},
4985
@{Name = "Az.Accounts"; Command = {Get-AzDomain -ErrorAction Stop}},
5086
@{Name = "Az.Advisor"; Command = {Get-AzAdvisorConfiguration -ErrorAction Stop}},
5187
@{Name = "Az.Aks"; Command = {Get-AzAksCluster -ErrorAction Stop}},
52-
@{Name = "Az.AnalysisServices"; Command = {Get-AzureRmAnalysisServicesServer -ErrorAction Stop}},
53-
@{Name = "Az.ApiManagement"; Command = {Get-AzureRmApiManagement -ErrorAction Stop}},
54-
@{Name = "Az.ApplicationInsights"; Command = {Get-AzureRmApplicationInsights -ErrorAction Stop}},
55-
@{Name = "Az.Automation"; Command = {Get-AzureRmAutomationAccount -ErrorAction Stop}},
56-
@{Name = "Az.Batch"; Command = {Get-AzureRmBatchAccount -ErrorAction Stop}},
57-
@{Name = "Az.Billing"; Command = {Get-AzureRmBillingInvoice -ErrorAction Stop}},
58-
@{Name = "Az.Billing [Consumption]"; Command = {try {Get-AzureRmConsumptionUsageDetail -ErrorAction Stop} catch {if ($_.ToString() -notlike "*422*" -and $_.ToString() -notlike "*UnprocessableEntity*" -and $_.ToString() -notlike "*BadRequest*") {throw $_}}}},
59-
@{Name = "Az.Cdn"; Command = {Get-AzureRmCdnProfile -ErrorAction Stop}},
60-
@{Name = "Az.CognitiveServices"; Command = {Get-AzureRmCognitiveServicesAccount -ErrorAction Stop}},
61-
@{Name = "Az.Compute"; Command = {Get-AzureRmVM -ErrorAction Stop}},
62-
@{Name = "Az.ContainerInstance"; Command = {Get-AzureRmContainerGroup -ErrorAction Stop}},
63-
@{Name = "Az.ContainerRegistry"; Command = {Get-AzureRmContainerRegistry -ErrorAction Stop}},
88+
@{Name = "Az.AnalysisServices"; Command = {Get-AzAnalysisServicesServer -ErrorAction Stop}},
89+
@{Name = "Az.ApiManagement"; Command = {Get-AzApiManagement -ErrorAction Stop}},
90+
@{Name = "Az.ApplicationInsights"; Command = {Get-AzApplicationInsights -ErrorAction Stop}},
91+
@{Name = "Az.Automation"; Command = {Get-AzAutomationAccount -ErrorAction Stop}},
92+
@{Name = "Az.Batch"; Command = {Get-AzBatchAccount -ErrorAction Stop}},
93+
@{Name = "Az.Billing"; Command = {Get-AzBillingInvoice -ErrorAction Stop}},
94+
@{Name = "Az.Billing [Consumption]"; Command = {try {Get-AzConsumptionUsageDetail -ErrorAction Stop} catch {if ($_.ToString() -notlike "*422*" -and $_.ToString() -notlike "*UnprocessableEntity*" -and $_.ToString() -notlike "*BadRequest*") {throw $_}}}},
95+
@{Name = "Az.Cdn"; Command = {Get-AzCdnProfile -ErrorAction Stop}},
96+
@{Name = "Az.CognitiveServices"; Command = {Get-AzCognitiveServicesAccount -ErrorAction Stop}},
97+
@{Name = "Az.Compute"; Command = {Get-AzVM -ErrorAction Stop}},
98+
@{Name = "Az.ContainerInstance"; Command = {Get-AzContainerGroup -ErrorAction Stop}},
99+
@{Name = "Az.ContainerRegistry"; Command = {Get-AzContainerRegistry -ErrorAction Stop}},
64100
@{Name = "Az.DataBoxEdge"; Command = {Get-AzDataBoxEdgeDevice -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
65101
@{Name = "Az.Databricks"; Command = {Get-AzDatabricksWorkspace -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
66-
@{Name = "Az.DataFactory [V1]"; Command = {Get-AzureRmDataFactory -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
67-
@{Name = "Az.DataFactoryV2 [V2]"; Command = {Get-AzureRmDataFactoryV2 -ErrorAction Stop}},
68-
@{Name = "Az.DataLakeAnalytics"; Command = {Get-AzureRmDataLakeAnalyticsAccount -ErrorAction Stop}},
69-
@{Name = "Az.DataLakeStore"; Command = {Get-AzureRmDataLakeStoreAccount -ErrorAction Stop}},
102+
@{Name = "Az.DataFactory [V1]"; Command = {Get-AzDataFactory -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
103+
@{Name = "Az.DataFactoryV2 [V2]"; Command = {Get-AzDataFactoryV2 -ErrorAction Stop}},
104+
@{Name = "Az.DataLakeAnalytics"; Command = {Get-AzDataLakeAnalyticsAccount -ErrorAction Stop}},
105+
@{Name = "Az.DataLakeStore"; Command = {Get-AzDataLakeStoreAccount -ErrorAction Stop}},
70106
@{Name = "Az.DataShare"; Command = {Get-AzDataShareAccount -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
71107
# Waiting for an issue fix: https://github.com/Azure/azure-powershell/issues/13522#issuecomment-728659457
72108
# @{Name = "Az.DeploymentManager"; Command = {try {Get-AzDeploymentManagerArtifactSource -ResourceGroupName $resourceGroupName -ErrorAction Stop}catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
73-
# Waiting for api '2020-11-02-preview' ready
74-
# @{Name = "Az.DesktopVirtualization"; Command = {Get-AzWvdApplicationGroup -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
109+
@{Name = "Az.DesktopVirtualization"; Command = {Get-AzWvdApplicationGroup -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
75110
@{Name = "Az.DevTestLabs "; Command = {try {Get-AzDtlAllowedVMSizesPolicy -LabName nonexistent -ResourceGroupName nonexistent -ErrorAction Stop} catch {if ($_.ToString() -notlike "*'nonexistent' could not be found.") {throw $_}}}},
76-
@{Name = "Az.Dns"; Command = {Get-AzureRmDnsZone -ErrorAction Stop}},
77-
@{Name = "Az.EventGrid"; Command = {Get-AzureRmEventGridTopic -ErrorAction Stop}},
78-
@{Name = "Az.EventHub"; Command = {Get-AzureRmEventHubNamespace -ErrorAction Stop}},
111+
@{Name = "Az.Dns"; Command = {Get-AzDnsZone -ErrorAction Stop}},
112+
@{Name = "Az.EventGrid"; Command = {Get-AzEventGridTopic -ErrorAction Stop}},
113+
@{Name = "Az.EventHub"; Command = {Get-AzEventHubNamespace -ErrorAction Stop}},
79114
@{Name = "Az.FrontDoor"; Command = {Get-AzFrontDoor -ErrorAction Stop}},
80115
@{Name = "Az.Functions"; Command = {Get-AzFunctionApp -ErrorAction Stop}},
81116
@{Name = "Az.HDInsight "; Command = {Get-AzHDInsightCluster -ErrorAction Stop}},
82117
@{Name = "Az.HealthcareApis"; Command = {Get-AzHealthcareApisService -ErrorAction Stop}},
83-
@{Name = "Az.IotHub"; Command = {Get-AzureRmIotHub -ErrorAction Stop}},
84-
@{Name = "Az.KeyVault"; Command = {Get-AzureRmKeyVault -ErrorAction Stop}},
118+
@{Name = "Az.IotHub"; Command = {Get-AzIotHub -ErrorAction Stop}},
119+
@{Name = "Az.KeyVault"; Command = {Get-AzKeyVault -ErrorAction Stop}},
85120
@{Name = "Az.Kusto"; Command = {Get-AzKustoCluster -ErrorAction Stop}},
86-
@{Name = "Az.LogicApp"; Command = {Get-AzureRmIntegrationAccount -ErrorAction Stop}},
87-
@{Name = "Az.MachineLearning"; Command = {Get-AzureRmMlWebService -ErrorAction Stop}},
121+
@{Name = "Az.LogicApp"; Command = {Get-AzIntegrationAccount -ErrorAction Stop}},
122+
@{Name = "Az.MachineLearning"; Command = {Get-AzMlWebService -ErrorAction Stop}},
88123
@{Name = "Az.Maintenance"; Command = {Get-AzMaintenanceConfiguration -ErrorAction Stop}},
89124
@{Name = "Az.ManagedServices"; Command = {Get-AzManagedServicesAssignment -ErrorAction Stop}},
90125
# Machine learning compute cmdlets are removed. The following line are to be commented until they are brought back
91-
# @{Name = "Az.MachineLearning [Compute]"; Command = {Get-AzureRmMlOpCluster -ErrorAction Stop}},
126+
# @{Name = "Az.MachineLearning [Compute]"; Command = {Get-AzMlOpCluster -ErrorAction Stop}},
92127
@{Name = "Az.MarketplaceOrdering"; Command = {try {Get-AzMarketplaceTerms -Publisher nonexistent -Product nonexistent -Name nonexistent -ErrorAction Stop} catch {if ($_.ToString() -notlike "*not found*") {throw $_}}}},
93-
@{Name = "Az.Media"; Command = {Get-AzureRmMediaService -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
94-
@{Name = "Az.Monitor"; Command = {Get-AzureRmLogProfile -ErrorAction Stop}},
95-
@{Name = "Az.Network"; Command = {Get-AzureRmNetworkInterface -ErrorAction Stop}},
96-
@{Name = "Az.NotificationHubs"; Command = {Get-AzureRmNotificationHubsNamespace -ErrorAction Stop}},
97-
@{Name = "Az.OperationalInsights"; Command = {Get-AzureRmOperationalInsightsWorkspace -ErrorAction Stop}},
128+
@{Name = "Az.Media"; Command = {Get-AzMediaService -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
129+
@{Name = "Az.Monitor"; Command = {Get-AzLogProfile -ErrorAction Stop}},
130+
@{Name = "Az.Network"; Command = {Get-AzNetworkInterface -ErrorAction Stop}},
131+
@{Name = "Az.NotificationHubs"; Command = {Get-AzNotificationHubsNamespace -ErrorAction Stop}},
132+
@{Name = "Az.OperationalInsights"; Command = {Get-AzOperationalInsightsWorkspace -ErrorAction Stop}},
98133
@{Name = "Az.PolicyInsights"; Command = {Get-AzPolicyEvent -ErrorAction Stop}},
99134
@{Name = "Az.PowerBIEmbedded"; Command = {Get-AzPowerBIEmbeddedCapacity -ErrorAction Stop}},
100-
@{Name = "Az.PowerBIUEmbedded"; Command = {Get-AzureRmPowerBIWorkspaceCollection -ErrorAction Stop}},
135+
@{Name = "Az.PowerBIUEmbedded"; Command = {Get-AzPowerBIWorkspaceCollection -ErrorAction Stop}},
101136
@{Name = "Az.PrivateDns"; Command = {Get-AzPrivateDnsZone -ErrorAction Stop}},
102137
@{Name = "Az.RecoveryServices"; Command = {Get-AzRecoveryServicesVault -ErrorAction Stop}},
103-
@{Name = "Az.RedisCache"; Command = {Get-AzureRmRedisCache -ErrorAction Stop}},
104-
@{Name = "Az.Relay"; Command = {Get-AzureRmRelayNamespace -ErrorAction Stop}},
105-
@{Name = "Az.ServiceBus"; Command = {Get-AzureRmServiceBusNamespace -ErrorAction Stop}},
106-
@{Name = "Az.ServiceFabric"; Command = {Get-AzureRmServiceFabricCluster -ErrorAction Stop}},
138+
@{Name = "Az.RedisCache"; Command = {Get-AzRedisCache -ErrorAction Stop}},
139+
@{Name = "Az.Relay"; Command = {Get-AzRelayNamespace -ErrorAction Stop}},
140+
@{Name = "Az.ServiceBus"; Command = {Get-AzServiceBusNamespace -ErrorAction Stop}},
141+
@{Name = "Az.ServiceFabric"; Command = {Get-AzServiceFabricCluster -ErrorAction Stop}},
107142
@{Name = "Az.SignalR"; Command = {Get-AzSignalR -ErrorAction Stop}},
108-
@{Name = "Az.Sql"; Command = {Get-AzureRmSqlServer -ErrorAction Stop}},
143+
@{Name = "Az.Sql"; Command = {Get-AzSqlServer -ErrorAction Stop}},
109144
@{Name = "Az.SqlVirtualMachine"; Command = {Get-AzSqlVM -ErrorAction Stop}},
110-
@{Name = "Az.StreamAnalytics"; Command = {Get-AzureRmStreamAnalyticsJob -ErrorAction Stop}},
145+
@{Name = "Az.StreamAnalytics"; Command = {Get-AzStreamAnalyticsJob -ErrorAction Stop}},
111146
@{Name = "Az.StorageSync"; Command = {Get-AzStorageSyncService -ErrorAction Stop}},
112-
@{Name = "Az.Support"; Command = {Get-AzSupportTicket -ErrorAction Stop}}
113-
@{Name = "Az.Resources [Tags]"; Command = {Get-AzureRmTag -ErrorAction Stop}},
114-
@{Name = "Az.TrafficManager"; Command = {Get-AzureRmTrafficManagerProfile -ErrorAction Stop}},
147+
@{Name = "Az.Support"; Command = {Get-AzSupportTicket -ErrorAction Stop}},
148+
@{Name = "Az.Resources [Tags]"; Command = {Get-AzTag -ErrorAction Stop}},
149+
@{Name = "Az.TrafficManager"; Command = {Get-AzTrafficManagerProfile -ErrorAction Stop}},
115150
@{Name = "Az.Billing [UsageAggregates]"; Command = {Get-UsageAggregates -ReportedStartTime '1/1/2018' -ReportedEndTime '1/2/2018' -ErrorAction Stop}},
116-
@{Name = "Az.Websites"; Command = {Get-AzureRmWebApp -ErrorAction Stop}}
151+
@{Name = "Az.Websites"; Command = {Get-AzWebApp -ErrorAction Stop}}
117152
)
118153

119154
if($Reverse.IsPresent){
@@ -137,7 +172,7 @@ $resourceCommands | ForEach-Object {
137172
catch
138173
{
139174
Write-Error $_.Exception
140-
$detail = Resolve-AzureRmError -Last
175+
$detail = Resolve-AzError -Last
141176
$testInfo.FailureDetails += (New-Object PSObject -Property @{Name = $testName; Details = $detail})
142177
$testInfo.FailedTests += $testName
143178
}
@@ -172,6 +207,6 @@ if ($testInfo.FailedTests.Count -gt 0)
172207
throw ("Test run failed with " + $testInfo.FailedTests.Count + " failures.")
173208
}
174209

175-
# Resolve-AzureRmError
210+
# Resolve-AzError
176211
# $DebugPreference = $oldDebug
177212
# $VerbosePreference = $oldVerbose

0 commit comments

Comments
 (0)