Skip to content

Commit 177e1c9

Browse files
committed
Merge pull request #8 from amarzavery/rp
Fix using in memory subscription with provider registration
2 parents 274e42d + 342136e commit 177e1c9

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,24 @@ private void RegisterServiceManagementProviders<T>(AzureContext context) where T
119119
}
120120
}
121121

122-
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
122+
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
123123
{
124-
if (providers != null && providers.Count > 0)
125-
{
126-
subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
127-
providers.ToArray());
128-
ProfileClient profileClient = new ProfileClient();
129-
profileClient.AddOrSetSubscription(subscription);
130-
profileClient.Profile.Save();
131-
}
124+
     if (providers != null && providers.Count > 0)
125+
     {
126+
         subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
127+
             providers.ToArray());
128+
         try
129+
         {
130+
             ProfileClient profileClient = new ProfileClient();
131+
             profileClient.AddOrSetSubscription(subscription);
132+
             profileClient.Profile.Save();
133+
         }
134+
         catch (KeyNotFoundException)
135+
         {
136+
             // if using a subscription data file, do not write registration to disk
137+
             // long term solution is using -Profile parameter
138+
         }
139+
     }
132140
}
133141
}
134142
}

tools/InstallationTests/InstallationTest.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ function Test-UpdateStorageAccount
4141
Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $accounts[1].StorageAccountName
4242
$storageAccountName = $(Get-AzureStorageContainer)[0].Context.StorageAccountName
4343
Assert-AreEqual $storageAccountName $accounts[1].StorageAccountName
44+
}
45+
46+
function Test-GetBatchAccountWithSubscriptionDataFile
47+
{
48+
param([PSCredential] $credential)
49+
Get-AzureSubscription | Remove-AzureSubscription -Force
50+
$account = Add-AzureAccount -Credential $credential -SubscriptionDataFile "File.txt"
51+
Select-AzureSubscription -SubscriptionId $account.Subscriptions.Split("`r`n")[0] -SubscriptionDataFile "File.txt"
52+
Get-AzureBatchAccount
53+
Add-AzureAccount -Credential $credential
4454
}

tools/InstallationTests/RunInstallationTests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Run-TestProtected { Test-UpdateStorageAccount } "Test-UpdateStorageAccount"
107107
$serviceCommands | % { Run-TestProtected $_ $_.ToString() }
108108
Write-Host -ForegroundColor Green "STARTING RESOURCE MANAGER TESTS"
109109
Switch-AzureMode AzureResourceManager > $null
110+
Run-TestProtected { Test-GetBatchAccountWithSubscriptionDataFile $credential} "Test-GetBatchAccountWithSubscriptionDataFile"
110111
$resourceCommands | % { Run-TestProtected $_ $_.ToString() }
111112
Write-Host
112113
Write-Host -ForegroundColor Green "$global:passedCount / $global:totalCount Installation Tests Pass"

0 commit comments

Comments
 (0)