Skip to content

Commit b86d7a6

Browse files
author
Hovsep Mkrtchyan
committed
Fix for "Select-AzureSubscription wipes CurrentStorageAccount field" bug
1 parent 1af62c0 commit b86d7a6

File tree

8 files changed

+131
-30
lines changed

8 files changed

+131
-30
lines changed

src/ServiceManagement/Common/Commands.ServiceManagement.Common/ProfileClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public AzureSubscription SetSubscriptionAsDefault(Guid id, string accountName)
654654
{
655655
if (subscription.IsPropertySet(AzureSubscription.Property.StorageAccount))
656656
{
657-
ServiceManagementUtilities.ClearCurrentStorageAccount();
657+
Microsoft.WindowsAzure.Commands.Utilities.Common.GeneralUtilities.ClearCurrentStorageAccount();
658658
}
659659

660660
Profile.DefaultSubscription = subscription;

src/ServiceManagement/Common/Commands.ServiceManagement.Common/ServiceManagementUtilities.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,5 @@ public static void EnsureDefaultProfileDirectoryExists()
5151
AzureSession.DataStore.CreateDirectory(AzureSession.ProfileDirectory);
5252
}
5353
}
54-
55-
/// <summary>
56-
/// Clear the current storage account from the context - guarantees that only one storage account will be active
57-
/// at a time.
58-
/// </summary>
59-
public static void ClearCurrentStorageAccount()
60-
{
61-
//TODO: Move to RM
62-
//var RMProfile = AzureRmProfileProvider.Instance.Profile;
63-
//if (RMProfile != null && RMProfile.Context != null &&
64-
// RMProfile.Context.Subscription != null && RMProfile.Context.Subscription.IsPropertySet(AzureSubscription.Property.StorageAccount))
65-
//{
66-
// RMProfile.Context.Subscription.SetProperty(AzureSubscription.Property.StorageAccount, null);
67-
//}
68-
69-
var SMProfile = AzureSMProfileProvider.Instance.Profile;
70-
if (SMProfile != null && SMProfile.Context != null
71-
&& SMProfile.Context.Subscription != null &&
72-
SMProfile.Context.Subscription.IsPropertySet(
73-
AzureSubscription.Property.StorageAccount))
74-
{
75-
SMProfile.Context.Subscription.SetProperty(
76-
AzureSubscription.Property.StorageAccount, null);
77-
}
78-
}
7954
}
8055
}

src/ServiceManagement/Profile/Commands.Profile/Subscription/SetAzureSubscription.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public override void ExecuteCmdlet()
164164
if (Profile.Context != null && Profile.Context.Subscription != null &&
165165
Profile.Context.Subscription.Id == subscription.Id)
166166
{
167-
ServiceManagementUtilities.ClearCurrentStorageAccount();
167+
GeneralUtilities.ClearCurrentStorageAccount();
168168
}
169169
var context = new AzureContext(subscription, ProfileClient.GetAccount(subscription.Account), ProfileClient.GetEnvironmentOrDefault(subscription.Environment));
170170
if (Context != null)

src/ServiceManagement/Services/Commands.Test/Commands.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@
385385
</Content>
386386
<None Include="packages.config" />
387387
<None Include="Performance\Microsoft.ServiceBus.MessagingPerformanceCounters.man" />
388+
<None Include="Profile\SelectAzureSubscriptionTests.ps1">
389+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
390+
</None>
388391
<None Include="Profile\SelectAzureProfileTests.ps1">
389392
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
390393
</None>

src/ServiceManagement/Services/Commands.Test/Profile/SelectAzureProfileTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ public void TestSelectDefaultProfile()
2727

2828
[Fact(Skip = "PSGet Migration: TODO Move to ARM")]
2929
[Trait(Category.AcceptanceType, Category.CheckIn)]
30-
[Trait(Category.AcceptanceType, Category.CheckIn)]
3130
public void TestMakeArmCallWithCreatedProfile()
3231
{
3332
ProfileTestController.NewARMInstance.RunPSTestWithToken((context, token) => string.Format("Test-NewAzureProfileInARMMode {0} {1} {2}", token, context.Account.Id, context.Subscription.Id));
3433
}
3534

3635
[Fact]
3736
[Trait(Category.AcceptanceType, Category.CheckIn)]
38-
[Trait(Category.AcceptanceType, Category.CheckIn)]
3937
public void TestMakeRdfeCallWithCreatedProfile()
4038
{
4139
ProfileTestController.NewRdfeInstance.RunPSTestWithToken((context, token) => string.Format("Test-NewAzureProfileInRDFEMode {0} {1} {2}", token, context.Account.Id, context.Subscription.Id));

src/ServiceManagement/Services/Commands.Test/Profile/SelectAzureSubscriptionTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
using Xunit;
1818
using Microsoft.WindowsAzure.Commands.Profile;
1919
using Moq;
20+
using Microsoft.Azure.Commands.Test.Profile;
2021

21-
namespace Microsoft.WindowsAzure.Commands.Test.Profile
22+
namespace Microsoft.Azure.Commands.Test.Profile
2223
{
2324

2425
public class SelectAzureSubscriptionTests
@@ -43,5 +44,12 @@ public void CleansDefaultSubscriptionTwice()
4344
// Assert that no exception is thrown
4445
Assert.True(true);
4546
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void StorageAccountIsNotCleaned()
51+
{
52+
ProfileTestController.NewRdfeInstance.RunPsTest("Test-StorageAccountIsNotCleaned");
53+
}
4654
}
4755
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests creating new azure profile with access token
18+
#>
19+
function Test-StorageAccountIsNotCleaned
20+
{
21+
Set-AzureSubscription -SubscriptionId 2c224e7e-3ef5-431d-a57b-e71f4662e3a6 -CurrentStorageAccount teststorage1220
22+
Select-AzureSubscription -SubscriptionId 2c224e7e-3ef5-431d-a57b-e71f4662e3a6
23+
$subscription = Get-AzureSubscription -SubscriptionId 2c224e7e-3ef5-431d-a57b-e71f4662e3a6
24+
$storageContainer = Get-AzureStorageContainer
25+
Assert-NotNull $($subscription.CurrentStorageAccountName)
26+
Assert-NotNull $($storageContainer)
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/2c224e7e-3ef5-431d-a57b-e71f4662e3a6/services/storageservices/teststorage1220",
5+
"EncodedRequestUri": "LzJjMjI0ZTdlLTNlZjUtNDMxZC1hNTdiLWU3MWY0NjYyZTNhNi9zZXJ2aWNlcy9zdG9yYWdlc2VydmljZXMvdGVzdHN0b3JhZ2UxMjIw",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-version": [
10+
"2014-10-01"
11+
],
12+
"User-Agent": [
13+
"Microsoft.WindowsAzure.Management.Storage.StorageManagementClient/5.0.0.0"
14+
]
15+
},
16+
"ResponseBody": "<StorageService xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <Url>https://management.core.windows.net/2c224e7e-3ef5-431d-a57b-e71f4662e3a6/services/storageservices/teststorage1220</Url>\r\n <ServiceName>teststorage1220</ServiceName>\r\n <StorageServiceProperties>\r\n <Description i:nil=\"true\" />\r\n <Location>West US</Location>\r\n <Label>dGVzdHN0b3JhZ2UxMjIw</Label>\r\n <Status>Created</Status>\r\n <Endpoints>\r\n <Endpoint>https://teststorage1220.blob.core.windows.net/</Endpoint>\r\n <Endpoint>https://teststorage1220.queue.core.windows.net/</Endpoint>\r\n <Endpoint>https://teststorage1220.table.core.windows.net/</Endpoint>\r\n <Endpoint>https://teststorage1220.file.core.windows.net/</Endpoint>\r\n </Endpoints>\r\n <GeoPrimaryRegion>West US</GeoPrimaryRegion>\r\n <StatusOfPrimary>Available</StatusOfPrimary>\r\n <GeoSecondaryRegion />\r\n <StatusOfSecondary />\r\n <CreationTime>2014-07-09T19:35:26Z</CreationTime>\r\n <CustomDomains />\r\n <AccountType>Standard_LRS</AccountType>\r\n </StorageServiceProperties>\r\n <ExtendedProperties>\r\n <ExtendedProperty>\r\n <Name>ResourceGroup</Name>\r\n <Value>Default-Storage-WestUS</Value>\r\n </ExtendedProperty>\r\n <ExtendedProperty>\r\n <Name>ResourceLocation</Name>\r\n <Value>West US</Value>\r\n </ExtendedProperty>\r\n </ExtendedProperties>\r\n <Capabilities>\r\n <Capability>PersistentVMRole</Capability>\r\n </Capabilities>\r\n</StorageService>",
17+
"ResponseHeaders": {
18+
"Content-Length": [
19+
"1293"
20+
],
21+
"Content-Type": [
22+
"application/xml; charset=utf-8"
23+
],
24+
"x-ms-servedbyregion": [
25+
"ussouth3"
26+
],
27+
"x-ms-request-id": [
28+
"3cc3414cd2838856bdfbece82a8a9ee5"
29+
],
30+
"Cache-Control": [
31+
"no-cache"
32+
],
33+
"Date": [
34+
"Mon, 07 Mar 2016 22:17:48 GMT"
35+
],
36+
"Server": [
37+
"1.0.6198.323",
38+
"(rd_rdfe_stable.160224-0707)",
39+
"Microsoft-HTTPAPI/2.0"
40+
]
41+
},
42+
"StatusCode": 200
43+
},
44+
{
45+
"RequestUri": "/2c224e7e-3ef5-431d-a57b-e71f4662e3a6/services/storageservices/teststorage1220/keys",
46+
"EncodedRequestUri": "LzJjMjI0ZTdlLTNlZjUtNDMxZC1hNTdiLWU3MWY0NjYyZTNhNi9zZXJ2aWNlcy9zdG9yYWdlc2VydmljZXMvdGVzdHN0b3JhZ2UxMjIwL2tleXM=",
47+
"RequestMethod": "GET",
48+
"RequestBody": "",
49+
"RequestHeaders": {
50+
"x-ms-version": [
51+
"2014-10-01"
52+
],
53+
"User-Agent": [
54+
"Microsoft.WindowsAzure.Management.Storage.StorageManagementClient/5.0.0.0"
55+
]
56+
},
57+
"ResponseBody": "<StorageService xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <Url>https://management.core.windows.net/2c224e7e-3ef5-431d-a57b-e71f4662e3a6/services/storageservices/teststorage1220</Url>\r\n <StorageServiceKeys>\r\n <Primary>/hYt36JRM3StLgfEuTa4IOi9yWzKhBKhRY3V3WZjq97Fv/84wToozLuT0aVqioUtreSTBJMD+LXI4g5jI5MGWA==</Primary>\r\n <Secondary>R1oLky011b/RZa9K6qVWKpnSsLjHMqvupJfg+DsbAZJxi1nN6Toc9ZNUQjMskDxQkdHaXmYY00jVxr86v4QPww==</Secondary>\r\n </StorageServiceKeys>\r\n</StorageService>",
58+
"ResponseHeaders": {
59+
"Content-Length": [
60+
"518"
61+
],
62+
"Content-Type": [
63+
"application/xml; charset=utf-8"
64+
],
65+
"x-ms-servedbyregion": [
66+
"ussouth3"
67+
],
68+
"x-ms-request-id": [
69+
"97717179d40c8f788e741e3cbe0e4b55"
70+
],
71+
"Cache-Control": [
72+
"no-cache"
73+
],
74+
"Date": [
75+
"Mon, 07 Mar 2016 22:17:48 GMT"
76+
],
77+
"Server": [
78+
"1.0.6198.323",
79+
"(rd_rdfe_stable.160224-0707)",
80+
"Microsoft-HTTPAPI/2.0"
81+
]
82+
},
83+
"StatusCode": 200
84+
}
85+
],
86+
"Names": {},
87+
"Variables": {
88+
"SubscriptionId": "2c224e7e-3ef5-431d-a57b-e71f4662e3a6"
89+
}
90+
}

0 commit comments

Comments
 (0)