Skip to content

huangpf PR: dev <- Azure:dev #581

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 1 commit into from
Jul 27, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
using System;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;

/// <summary>
/// Get an existing resource.
Expand Down Expand Up @@ -94,9 +96,19 @@ public override void ExecuteCmdlet()

private PSResourceProvider[] ListPSResourceProviders()
{
var providers = this.ResourceManagerSdkClient.ListResourceProviders(
providerName: this.ProviderNamespace,
listAvailable: this.ListAvailable);
var allProviders = this.ResourceManagerSdkClient.ListResourceProviders(
providerName: null,
listAvailable: true);

var providers = allProviders;
if (!string.IsNullOrEmpty(this.ProviderNamespace))
{
providers = this.ResourceManagerSdkClient.ListResourceProviders(providerName: this.ProviderNamespace);
}
else if (this.ListAvailable == false)
{
providers = this.ResourceManagerSdkClient.GetRegisteredProviders(providers);
}

if (string.IsNullOrEmpty(this.Location))
{
Expand All @@ -105,10 +117,20 @@ private PSResourceProvider[] ListPSResourceProviders()
.ToArray();
}

var validLocations = this.SubscriptionSdkClient.ListLocations(DefaultContext.Subscription.Id.ToString());
var allRPLocations = allProviders
.SelectMany(provider => provider.ResourceTypes.CoalesceEnumerable().SelectMany(type => type.Locations))
.Distinct(StringComparer.InvariantCultureIgnoreCase);

var validLocations = this
.SubscriptionSdkClient
.ListLocations(DefaultContext.Subscription.Id.ToString())
.Select(location => location.DisplayName)
.Concat(allRPLocations)
.Distinct(StringComparer.InvariantCultureIgnoreCase);

if (!validLocations.Any(loc => loc.Name.EqualsAsLocation(this.Location)))
if (!validLocations.Any(loc => loc.EqualsAsLocation(this.Location)))
{
this.WriteErrorWithTimestamp(ProjectResources.InvalidLocation);
return new PSResourceProvider[] { };
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,7 @@
<data name="CreateDeployment" xml:space="preserve">
<value>Creating Deployment</value>
</data>
<data name="InvalidLocation" xml:space="preserve">
<value>Provided location is not supported</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ public virtual List<Provider> ListResourceProviders(string providerName = null,
}
}

public List<Provider> GetRegisteredProviders(List<Provider> providers)
{
return providers.CoalesceEnumerable().Where(this.IsProviderRegistered).ToList();
}

private bool IsProviderRegistered(Provider provider)
{
return string.Equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void ResetCalls()
private void VerifyGetCallPatternAndReset()
{
this.providerOperationsMock.Verify(f => f.GetWithHttpMessagesAsync(It.IsAny<string>(), null, It.IsAny<CancellationToken>()), Times.Once());
this.providerOperationsMock.Verify(f => f.ListWithHttpMessagesAsync(null, null, It.IsAny<CancellationToken>()), Times.Never);
this.providerOperationsMock.Verify(f => f.ListWithHttpMessagesAsync(null, null, It.IsAny<CancellationToken>()), Times.Once());
this.providerOperationsMock.Verify(f => f.ListNextWithHttpMessagesAsync(It.IsAny<string>(), null, It.IsAny<CancellationToken>()), Times.Never);
this.commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<object>(), It.IsAny<bool>()), Times.Once());
this.ResetCalls();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,42 @@
function Test-AzureProvider
{
$defaultProviders = Get-AzureRmResourceProvider

Assert-True { $defaultProviders.Length -gt 0 }

$allProviders = Get-AzureRmResourceProvider -ListAvailable

Assert-True { $allProviders.Length -gt $defaultProviders.Length }

$nonProviders = Get-AzureRmResourceProvider -Location "abc"
$ErrorActionPreference = "SilentlyContinue"
$Error.Clear()

$nonProviders = Get-AzureRmResourceProvider -Location "abc"
Assert-True { $Error[0].Contains("Provided location is not supported") }
Assert-True { $nonProviders.Length -eq 0 }

Register-AzureRmResourceProvider -ProviderName "Microsoft.ApiManagement" -Force
$ErrorActionPreference = "Stop"

$globalProviders = Get-AzureRmResourceProvider -Location "global"
Assert-True { $globalProviders.Length -gt 0 }

Register-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement" -Force

$endTime = [DateTime]::UtcNow.AddMinutes(5)

while ([DateTime]::UtcNow -lt $endTime -and @(Get-AzureRmResourceProvider -ProviderName "Microsoft.ApiManagement").RegistrationState -ne "Registered")
while ([DateTime]::UtcNow -lt $endTime -and @(Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement")[0].RegistrationState -ne "Registered")
{
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(1000)
}
$provider = Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement"
Assert-True { $provider[0].RegistrationState -eq "Registered" }

Assert-True { @(Get-AzureRmResourceProvider -ProviderName "Microsoft.ApiManagement").RegistrationState -eq "Registered" }
Unregister-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement" -Force

Unregister-AzureRmResourceProvider -ProviderName "Microsoft.ApiManagement" -Force

while ([DateTime]::UtcNow -lt $endTime -and @(Get-AzureRmResourceProvider -ProviderName "Microsoft.ApiManagement").RegistrationState -ne "Unregistered")
while ([DateTime]::UtcNow -lt $endTime -and @(Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement")[0].RegistrationState -ne "Unregistered")
{
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(1000)
}

Assert-True { @(Get-AzureRmResourceProvider -ProviderName "Microsoft.ApiManagement").RegistrationState -eq "Unregistered" }
$provider = Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.ApiManagement"
Assert-True { $provider[0].RegistrationState -eq "Unregistered" }
}

<#
Expand Down

Large diffs are not rendered by default.