Skip to content

Commit ea8f84d

Browse files
committed
Fix issue of the aliases of new storage account and set storage account don't work. Add new scenario test for storage management cmdlets.
1 parent 5864702 commit ea8f84d

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Param(
2+
[string]$rgname,
3+
[string]$resourceGroupLocation
4+
)
5+
Write-Host "=== Managing Storage Accounts Resources in Azure ==="
6+
7+
$stoname = 'sto' + $rgname;
8+
$stotype = 'Standard_GRS';
9+
$loc = 'West US';
10+
11+
New-AzureRmResourceGroup -Name $rgname -Location $resourceGroupLocation;
12+
13+
Write-Host "1. Create a new storage account"
14+
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
15+
16+
Write-Host "2. Get info of a storage account"
17+
$stos = Get-AzureRmStorageAccount -ResourceGroupName $rgname;
18+
19+
Write-Host "3. Update storage account type"
20+
$stotype = 'Standard_RAGRS';
21+
Set-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Type $stotype;
22+
23+
Write-Host "4. Get account key of a storage account"
24+
$stokeys=Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname;
25+
26+
Write-Host "5. Renew key1 of a storage account"
27+
New-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname -KeyName key1;
28+
29+
Write-Host "6. Renew key2 of a storage account"
30+
New-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname -KeyName key2;
31+
32+
Write-Host "7. Remove storage account"
33+
Remove-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
printf "\n=== Managing Storage Accounts Resources in Azure ===\n"
3+
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
5+
azure group get -n $groupName
6+
if [ $? -ne 0 ]; then
7+
printf "\n Creating group %s in location %s \n" $groupName $location
8+
azure group create -n "$groupName" --location "$location"
9+
fi
10+
11+
set -e
12+
accountName=`randomName $groupName`
13+
accountType="Standard_GRS"
14+
15+
printf "\n1. Creating storage account %s in resrouce group %s with type %s in location %s \n" $accountName $groupName $accountType $location
16+
azure storage account new -g "$groupName" -n "$accountName" -t "$accountType" -l "$location"
17+
18+
printf "\n2. Get account info of storage account %s in group %s\n" $accountName $groupName
19+
azure storage account get -g $groupName -n $accountName > $BASEDIR/$accountName.json
20+
[ $(cat $BASEDIR/$accountName.json | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
21+
[ $(cat $BASEDIR/$accountName.json | jq '.StorageAccountName' --raw-output) == "$accountName" ]
22+
[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType" ]
23+
[ $(cat $BASEDIR/$accountName.json | jq '.Location' --raw-output) == "$location" ]
24+
rm -f $BASEDIR/$accountName.json
25+
26+
accountType1="Standard_RAGRS"
27+
printf "\n3. Set account type from %s to %s of storage account %s in group %s\n" $accountType $accountType1 $accountName $groupName
28+
azure storage account set -g $groupName -n $accountName -t "$accountType1" > $BASEDIR/$accountName.json
29+
[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType1" ]
30+
rm -f $BASEDIR/$accountName.json
31+
32+
printf "\n4. Get account key of storage account %s in group %s\n" $accountName $groupName
33+
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
34+
key1=$(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output)
35+
key2=$(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output)
36+
[ $key1 != $key2 ]
37+
rm -f $BASEDIR/$accountName.json
38+
39+
printf "\n5. Renew account key1 of storage account %s in group %s\n" $accountName $groupName
40+
azure storage account key new -g $groupName -n $accountName -k "key1"
41+
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
42+
[ $(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output) != $key1 ]
43+
rm -f $BASEDIR/$accountName.json
44+
45+
printf "\n6. Renew account key2 of storage account %s in group %s\n" $accountName $groupName
46+
azure storage account key new -g $groupName -n $accountName -k "key2"
47+
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
48+
[ $(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output) != $key2 ]
49+
rm -f $BASEDIR/$accountName.json
50+
51+
printf "\n7. Removing account %s in group %s\n" $accountName $groupName
52+
azure storage account remove -g $groupName -n $accountName

src/CLU/Microsoft.Azure.Commands.Management.Storage/StorageAccount/NewAzureStorageAccount.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public class NewAzureStorageAccountCommand : StorageAccountBaseCmdlet
7272
ValueFromPipelineByPropertyName = true,
7373
HelpMessage = "Storage Account Tags.")]
7474
[ValidateNotNull]
75-
[Alias("t")]
7675
public Hashtable[] Tags { get; set; }
7776

7877
protected override void ProcessRecord()

src/CLU/Microsoft.Azure.Commands.Management.Storage/StorageAccount/NewAzureStorageAccountKey.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class NewAzureStorageAccountKeyCommand : StorageAccountBaseCmdlet
5050
ValueFromPipelineByPropertyName = true,
5151
HelpMessage = "Storage Account Key StorageAccountName.")]
5252
[ValidateSet(Key1, Key2, IgnoreCase = true)]
53+
[Alias("k")]
5354
public string KeyName { get; set; }
5455

5556
protected override void ProcessRecord()

src/CLU/Microsoft.Azure.Commands.Management.Storage/StorageAccount/SetAzureStorageAccount.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public class SetAzureStorageAccountCommand : StorageAccountBaseCmdlet
9191
HelpMessage = "Storage Account Tags.")]
9292
[AllowEmptyCollection]
9393
[ValidateNotNull]
94-
[Alias("t")]
9594
public Hashtable[] Tags { get; set; }
9695

9796
protected override void ProcessRecord()

0 commit comments

Comments
 (0)