diff --git a/src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs b/src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs index 45752e551ab6..4f0c95b568d9 100644 --- a/src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs +++ b/src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs @@ -119,16 +119,24 @@ private void RegisterServiceManagementProviders(AzureContext context) where T } } - private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List providers) + private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List 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 +         } +     } } } } diff --git a/tools/InstallationTests/InstallationTest.ps1 b/tools/InstallationTests/InstallationTest.ps1 index e178ff651fdb..779312ea6632 100644 --- a/tools/InstallationTests/InstallationTest.ps1 +++ b/tools/InstallationTests/InstallationTest.ps1 @@ -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 } \ No newline at end of file diff --git a/tools/InstallationTests/RunInstallationTests.ps1 b/tools/InstallationTests/RunInstallationTests.ps1 index 6c59592736c7..e0b238ecc4c5 100644 --- a/tools/InstallationTests/RunInstallationTests.ps1 +++ b/tools/InstallationTests/RunInstallationTests.ps1 @@ -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"