Skip to content

Fix using in memory subscription with provider registration #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,24 @@ private void RegisterServiceManagementProviders<T>(AzureContext context) where T
}
}

private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
{
if (providers != null && providers.Count > 0)
{
subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
providers.ToArray());
ProfileClient profileClient = new ProfileClient();
profileClient.AddOrSetSubscription(subscription);
profileClient.Profile.Save();
}
     if (providers != null && providers.Count > 0)
     {
         subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
             providers.ToArray());
         try
         {
             ProfileClient profileClient = new ProfileClient();
             profileClient.AddOrSetSubscription(subscription);
             profileClient.Profile.Save();
         }
         catch (KeyNotFoundException)
         {
             // if using a subscription data file, do not write registration to disk
             // long term solution is using -Profile parameter
         }
     }
}
}
}
10 changes: 10 additions & 0 deletions tools/InstallationTests/InstallationTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ function Test-UpdateStorageAccount
Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccountName $accounts[1].StorageAccountName
$storageAccountName = $(Get-AzureStorageContainer)[0].Context.StorageAccountName
Assert-AreEqual $storageAccountName $accounts[1].StorageAccountName
}

function Test-GetBatchAccountWithSubscriptionDataFile
{
param([PSCredential] $credential)
Get-AzureSubscription | Remove-AzureSubscription -Force
$account = Add-AzureAccount -Credential $credential -SubscriptionDataFile "File.txt"
Select-AzureSubscription -SubscriptionId $account.Subscriptions.Split("`r`n")[0] -SubscriptionDataFile "File.txt"
Get-AzureBatchAccount
Add-AzureAccount -Credential $credential
}
1 change: 1 addition & 0 deletions tools/InstallationTests/RunInstallationTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Run-TestProtected { Test-UpdateStorageAccount } "Test-UpdateStorageAccount"
$serviceCommands | % { Run-TestProtected $_ $_.ToString() }
Write-Host -ForegroundColor Green "STARTING RESOURCE MANAGER TESTS"
Switch-AzureMode AzureResourceManager > $null
Run-TestProtected { Test-GetBatchAccountWithSubscriptionDataFile $credential} "Test-GetBatchAccountWithSubscriptionDataFile"
$resourceCommands | % { Run-TestProtected $_ $_.ToString() }
Write-Host
Write-Host -ForegroundColor Green "$global:passedCount / $global:totalCount Installation Tests Pass"
Expand Down