@@ -31,6 +31,40 @@ for($i=0; $i -lt 9; $i++)
31
31
{
32
32
$randomValue += $strarray [(Get-Random - Maximum $strarray.Length )]
33
33
}
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
+
34
68
# The name of resource group is 1~90 charactors complying with ^[-\w\._\(\)]+$
35
69
$resourceGroupName = " azpssmokerg$randomValue "
36
70
# The name of storage account should be 3~24 lowercase letters and numbers.
@@ -39,27 +73,12 @@ $storageAccountName = "azpssmokesa$randomValue"
39
73
$resourceSetUpCommands = @ (
40
74
@ {Name = " Az.Resources" ; Command = {New-AzResourceGroup - Name $resourceGroupName - Location westus - ErrorAction Stop}}
41
75
)
76
+
42
77
$resourceCleanUpCommands = @ (
43
- @ {Name = " Az.Storage [Cleanup]" ; Command = {
44
- $loopLimit = 0
45
- do {
46
- try {
47
- Remove-AzStorageAccount - Name $storageAccountName - ResourceGroupName $resourceGroupName - Force - ErrorAction Stop
48
- break
49
- }
50
- catch {
51
- if (++ $loopLimit -gt 30 )
52
- {
53
- throw " Failed to invoke Az.Storage [Cleanup]. $_ "
54
- } else {
55
- Write-Warning " Retry Az.Storage [Cleanup] after 30 seconds"
56
- Start-Sleep - Seconds 30
57
- }
58
- }
59
- } while ($true )
60
- }},
78
+ @ {Name = " Az.Storage [Cleanup]" ; Command = {Retry- AzCommand - Command " Remove-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName -Force -ErrorAction Stop" - RetryCount 30 - Sleep 30 }},
61
79
@ {Name = " Az.Resources [Cleanup]" ; Command = {Remove-AzResourceGroup - Name $resourceGroupName - Force - ErrorAction Stop}}
62
80
)
81
+
63
82
$resourceTestCommands = @ (
64
83
@ {Name = " Az.Storage [Management]" ; Command = {New-AzStorageAccount - Name $storageAccountName - SkuName Standard_LRS - Location westus - ResourceGroupName $resourceGroupName - ErrorAction Stop}},
65
84
@ {Name = " Az.Storage [Data]" ; Command = {New-AzStorageContext - StorageAccountName $storageAccountName - StorageAccountKey 12345678 - ErrorAction Stop}},
0 commit comments