Skip to content

Routing Support for IoTHub cmdlets #4075

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
Jun 5, 2017
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
200 changes: 192 additions & 8 deletions setup/azurecmdfiles.wxi

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,19 @@
<Reference Include="Microsoft.Azure.Common">
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.EventHub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.EventHub.1.2.0\lib\net452\Microsoft.Azure.Management.EventHub.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.IotHub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.IotHub.1.1.2\lib\net452\Microsoft.Azure.Management.IotHub.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.7-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Common.NetFramework">
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.IotHub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.IotHub.1.0.0\lib\net45\Microsoft.Azure.Management.IotHub.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Test.Framework">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
Expand All @@ -66,17 +64,11 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.5\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.8\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.7\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
Expand All @@ -88,12 +80,6 @@
<Reference Include="Microsoft.Threading.Tasks">
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions">
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
Expand Down Expand Up @@ -175,9 +161,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.EventHub;

namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
{
using System;
Expand Down Expand Up @@ -48,6 +50,8 @@ public sealed class IotHubController

public IotHubClient IotHubClient { get; private set; }

public EventHubManagementClient EHClient { get; private set; }

public string UserDomain { get; private set; }

public static IotHubController NewInstance
Expand Down Expand Up @@ -103,6 +107,7 @@ public void RunPsTestWorkflow(
initialize(this.csmTestFactory);
}
SetupManagementClients(context);

helper.SetupEnvironment(AzureModule.AzureResourceManager);

var callingClassName = callingClassType
Expand All @@ -115,6 +120,7 @@ public void RunPsTestWorkflow(
helper.RMProfileModule,
helper.RMResourceModule,
helper.GetRMModulePath(@"AzureRM.IotHub.psd1"),
helper.GetRMModulePath(@"AzureRM.EventHub.psd1"),
"AzureRM.Resources.ps1");

try
Expand Down Expand Up @@ -144,11 +150,13 @@ private void SetupManagementClients(MockContext context)
ResourceManagementClient = GetResourceManagementClient();
SubscriptionClient = GetSubscriptionClient();
IotHubClient = GetIotHubClient(context);
EHClient = GetEHClient(context);
AuthorizationManagementClient = GetAuthorizationManagementClient();

helper.SetupManagementClients(ResourceManagementClient,
SubscriptionClient,
IotHubClient,
EHClient,
AuthorizationManagementClient
);
}
Expand All @@ -172,5 +180,9 @@ private IotHubClient GetIotHubClient(MockContext context)
{
return context.GetServiceClient<IotHubClient>(Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory.GetTestEnvironment());
}
private EventHubManagementClient GetEHClient(MockContext context)
{
return context.GetServiceClient<EventHubManagementClient>(Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory.GetTestEnvironment());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,50 @@ function Test-AzureRmIotHubLifecycle
# Create or Update Resource Group
$resourceGroup = New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location

Write-Debug " Create new eventHub "
$namespaceName = "IotHubPSEHNamespaceTest"
$result = New-AzureRmEventHubNamespace -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -Location $Location

Wait-Seconds 15

# Assert
Assert-True {$result.ProvisioningState -eq "Succeeded"}

Write-Debug " Create new eventHub "
$eventHubName = "IotHubPSEHTest"
$msgRetentionInDays = 3
$partionCount = 2
$result = New-AzureRmEventHub -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -Location $Location -EventHubName $eventHubName -MessageRetentionInDays $msgRetentionInDays -PartitionCount $partionCount

# Create AuthRule
$authRuleName = "IotHubPSEHAuthRule"
$rights = "Listen","Send"
$authRule = New-AzureRmEventHubAuthorizationRule -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -AuthorizationRuleName $authRuleName -Rights $rights
$keys = Get-AzureRmEventHubKey -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -AuthorizationRuleName $authRuleName
$ehConnectionString = $keys.PrimaryConnectionString

# Create Iot Hub
$newIothub1 = New-AzureRmIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1
$properties = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubInputProperties
$routingProperties = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingProperties
$routingEndpoints = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingEndpoints
$routingEndpoints.EventHubs = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingEventHubProperties]'
$eventHubRouting = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingEventHubProperties
$eventHubRouting.Name = "eh1"
$eventHubRouting.ConnectionString = $ehConnectionString
$routingEndpoints.EventHubs.Add($eventHubRouting)
$routingProperties.Endpoints = $routingEndpoints

$routeProp = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
$routeProp.Name = "route"
$routeProp.Condition = "true"
$routeProp.IsEnabled = 1
$routeProp.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
$routeProp.EndpointNames.Add("eh1")
$routeProp.Source = "DeviceMessages"
$routingProperties.Routes = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata]'
$routingProperties.Routes.Add($routeProp)
$properties.Routing = $routingProperties
$newIothub1 = New-AzureRmIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1 -Properties $properties

# Get Iot Hub in resourcegroup
$allIotHubsInResourceGroup = Get-AzureRmIotHub -ResourceGroupName $ResourceGroupName
Expand All @@ -48,6 +90,9 @@ function Test-AzureRmIotHubLifecycle

Assert-True { $allIotHubsInResourceGroup.Count -eq 1 }
Assert-True { $iotHub.Name -eq $IotHubName }
Assert-True { $iotHub.Properties.Routing.Routes.Count -eq 1}
Assert-True { $iotHub.Properties.Routing.Routes[0].Name -eq "route"}
Assert-True { $iotHub.Properties.Routing.Endpoints.EventHubs[0].Name -eq "eh1"}

# Get Quota Metrics
$quotaMetrics = Get-AzureRmIotHubQuotaMetric -ResourceGroupName $ResourceGroupName -Name $IotHubName
Expand Down Expand Up @@ -102,7 +147,7 @@ function Test-AzureRmIotHubLifecycle
Assert-True { $eventubConsumerGroup.Count -eq 1 }

# Add Key
Add-AzureRmIotHubKey -ResourceGroupName $ResourceGroupName -Name $IotHubName -KeyName iothubowner1 -PrimaryKey primarykey -SecondaryKey secondarykey -Rights RegistryRead
Add-AzureRmIotHubKey -ResourceGroupName $ResourceGroupName -Name $IotHubName -KeyName iothubowner1 -Rights RegistryRead

# Get Keys
$keys = Get-AzureRmIotHubKey -ResourceGroupName $ResourceGroupName -Name $IotHubName
Expand Down Expand Up @@ -136,6 +181,51 @@ function Test-AzureRmIotHubLifecycle
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -OperationsMonitoringProperties $op
Assert-True { $iothubUpdated.Properties.OperationsMonitoringProperties.OperationMonitoringEvents["Connections"] -eq "Information" }

# Routing Properties Update
$routingProperties = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingProperties
$routeProp = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
$routeProp.Name = "route1"
$routeProp.Condition = "true"
$routeProp.IsEnabled = 1
$routeProp.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
$routeProp.EndpointNames.Add("events")
$routeProp.Source = "DeviceMessages"
$routingProperties.Routes = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata]'
$routingProperties.Routes.Add($routeProp)
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -RoutingProperties $routingProperties
Assert-True { $iotHubUpdated.Properties.Routing.Routes.Count -eq 1}
Assert-True { $iotHubUpdated.Properties.Routing.Routes[0].Name -eq "route1"}

# Route Properties Update
$routeProp1 = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
$routeProp1.Name = "route2"
$routeProp1.Condition = "true"
$routeProp1.IsEnabled = 1
$routeProp1.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
$routeProp1.EndpointNames.Add("events")
$routeProp1.Source = "DeviceMessages"

$routeProp2 = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
$routeProp2.Name = "route3"
$routeProp2.Condition = "true"
$routeProp2.IsEnabled = 1
$routeProp2.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
$routeProp2.EndpointNames.Add("events")
$routeProp2.Source = "DeviceMessages"

$routes = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata]'
$routes.Add($routeProp1)
$routes.Add($routeProp2)
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -Routes $routes
Assert-True { $iotHubUpdated.Properties.Routing.Routes.Count -eq 2}
Assert-True { $iotHubUpdated.Properties.Routing.Routes[0].Name -eq "route2"}
Assert-True { $iotHubUpdated.Properties.Routing.FallbackRoute.IsEnabled -eq 0}

$iothub = Get-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName
$iothub.Properties.Routing.FallbackRoute.IsEnabled = 1
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -FallbackRoute $iothub.Properties.Routing.FallbackRoute
Assert-True { $iotHubUpdated.Properties.Routing.FallbackRoute.IsEnabled -eq 1}

# Remove IotHub
Remove-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Hyak.Common" version="1.0.3" targetFramework="net45" />
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.EventHub" version="1.2.0" targetFramework="net452" />
<package id="Microsoft.Azure.Management.IotHub" version="1.1.2" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
Expand All @@ -13,8 +14,8 @@
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.7" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.9-preview" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.5.0-preview" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
Expand Down
Loading