Skip to content

Commit 2348041

Browse files
authored
Merge pull request #4075 from markcowl/iot410
Routing Support for IoTHub cmdlets
2 parents 4d61b78 + a73af24 commit 2348041

40 files changed

+3884
-1156
lines changed

setup/azurecmdfiles.wxi

Lines changed: 192 additions & 8 deletions
Large diffs are not rendered by default.

src/ResourceManager/IotHub/Commands.IotHub.Test/Commands.IotHub.Test.csproj

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,19 @@
4242
<Reference Include="Microsoft.Azure.Common">
4343
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
4444
</Reference>
45+
<Reference Include="Microsoft.Azure.Management.EventHub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.EventHub.1.2.0\lib\net452\Microsoft.Azure.Management.EventHub.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Microsoft.Azure.Management.IotHub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
49+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.IotHub.1.1.2\lib\net452\Microsoft.Azure.Management.IotHub.dll</HintPath>
50+
</Reference>
4551
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4652
<HintPath>..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.7-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
4753
<Private>True</Private>
4854
</Reference>
4955
<Reference Include="Microsoft.Azure.Common.NetFramework">
5056
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
5157
</Reference>
52-
<Reference Include="Microsoft.Azure.Management.IotHub, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
53-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.IotHub.1.0.0\lib\net45\Microsoft.Azure.Management.IotHub.dll</HintPath>
54-
<Private>True</Private>
55-
</Reference>
56-
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57-
<SpecificVersion>False</SpecificVersion>
58-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
59-
</Reference>
6058
<Reference Include="Microsoft.Azure.Test.Framework">
6159
<SpecificVersion>False</SpecificVersion>
6260
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
@@ -66,17 +64,11 @@
6664
<Private>True</Private>
6765
</Reference>
6866
<Reference Include="Microsoft.CSharp" />
69-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70-
<SpecificVersion>False</SpecificVersion>
71-
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
72-
</Reference>
73-
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74-
<SpecificVersion>False</SpecificVersion>
75-
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
76-
</Reference>
7767
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
78-
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.5\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
79-
<Private>True</Private>
68+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.8\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
69+
</Reference>
70+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
71+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.7\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
8072
</Reference>
8173
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8274
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
@@ -88,12 +80,6 @@
8880
<Reference Include="Microsoft.Threading.Tasks">
8981
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
9082
</Reference>
91-
<Reference Include="Microsoft.Threading.Tasks.Extensions">
92-
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
93-
</Reference>
94-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
95-
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
96-
</Reference>
9783
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
9884
<Reference Include="Microsoft.WindowsAzure.Management">
9985
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
@@ -175,9 +161,6 @@
175161
<SpecificVersion>False</SpecificVersion>
176162
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
177163
</Reference>
178-
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
179-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
180-
</Reference>
181164
<Reference Include="Microsoft.Threading.Tasks">
182165
<SpecificVersion>False</SpecificVersion>
183166
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>

src/ResourceManager/IotHub/Commands.IotHub.Test/ScenarioTests/IotHubController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Management.EventHub;
16+
1517
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
1618
{
1719
using System;
@@ -48,6 +50,8 @@ public sealed class IotHubController
4850

4951
public IotHubClient IotHubClient { get; private set; }
5052

53+
public EventHubManagementClient EHClient { get; private set; }
54+
5155
public string UserDomain { get; private set; }
5256

5357
public static IotHubController NewInstance
@@ -103,6 +107,7 @@ public void RunPsTestWorkflow(
103107
initialize(this.csmTestFactory);
104108
}
105109
SetupManagementClients(context);
110+
106111
helper.SetupEnvironment(AzureModule.AzureResourceManager);
107112

108113
var callingClassName = callingClassType
@@ -115,6 +120,7 @@ public void RunPsTestWorkflow(
115120
helper.RMProfileModule,
116121
helper.RMResourceModule,
117122
helper.GetRMModulePath(@"AzureRM.IotHub.psd1"),
123+
helper.GetRMModulePath(@"AzureRM.EventHub.psd1"),
118124
"AzureRM.Resources.ps1");
119125

120126
try
@@ -144,11 +150,13 @@ private void SetupManagementClients(MockContext context)
144150
ResourceManagementClient = GetResourceManagementClient();
145151
SubscriptionClient = GetSubscriptionClient();
146152
IotHubClient = GetIotHubClient(context);
153+
EHClient = GetEHClient(context);
147154
AuthorizationManagementClient = GetAuthorizationManagementClient();
148155

149156
helper.SetupManagementClients(ResourceManagementClient,
150157
SubscriptionClient,
151158
IotHubClient,
159+
EHClient,
152160
AuthorizationManagementClient
153161
);
154162
}
@@ -172,5 +180,9 @@ private IotHubClient GetIotHubClient(MockContext context)
172180
{
173181
return context.GetServiceClient<IotHubClient>(Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory.GetTestEnvironment());
174182
}
183+
private EventHubManagementClient GetEHClient(MockContext context)
184+
{
185+
return context.GetServiceClient<EventHubManagementClient>(Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory.GetTestEnvironment());
186+
}
175187
}
176188
}

src/ResourceManager/IotHub/Commands.IotHub.Test/ScenarioTests/IotHubTests.ps1

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,50 @@ function Test-AzureRmIotHubLifecycle
3737
# Create or Update Resource Group
3838
$resourceGroup = New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
3939

40+
Write-Debug " Create new eventHub "
41+
$namespaceName = "IotHubPSEHNamespaceTest"
42+
$result = New-AzureRmEventHubNamespace -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -Location $Location
43+
44+
Wait-Seconds 15
45+
46+
# Assert
47+
Assert-True {$result.ProvisioningState -eq "Succeeded"}
48+
49+
Write-Debug " Create new eventHub "
50+
$eventHubName = "IotHubPSEHTest"
51+
$msgRetentionInDays = 3
52+
$partionCount = 2
53+
$result = New-AzureRmEventHub -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -Location $Location -EventHubName $eventHubName -MessageRetentionInDays $msgRetentionInDays -PartitionCount $partionCount
54+
55+
# Create AuthRule
56+
$authRuleName = "IotHubPSEHAuthRule"
57+
$rights = "Listen","Send"
58+
$authRule = New-AzureRmEventHubAuthorizationRule -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -AuthorizationRuleName $authRuleName -Rights $rights
59+
$keys = Get-AzureRmEventHubKey -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -AuthorizationRuleName $authRuleName
60+
$ehConnectionString = $keys.PrimaryConnectionString
61+
4062
# Create Iot Hub
41-
$newIothub1 = New-AzureRmIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1
63+
$properties = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSIotHubInputProperties
64+
$routingProperties = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingProperties
65+
$routingEndpoints = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingEndpoints
66+
$routingEndpoints.EventHubs = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingEventHubProperties]'
67+
$eventHubRouting = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingEventHubProperties
68+
$eventHubRouting.Name = "eh1"
69+
$eventHubRouting.ConnectionString = $ehConnectionString
70+
$routingEndpoints.EventHubs.Add($eventHubRouting)
71+
$routingProperties.Endpoints = $routingEndpoints
72+
73+
$routeProp = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
74+
$routeProp.Name = "route"
75+
$routeProp.Condition = "true"
76+
$routeProp.IsEnabled = 1
77+
$routeProp.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
78+
$routeProp.EndpointNames.Add("eh1")
79+
$routeProp.Source = "DeviceMessages"
80+
$routingProperties.Routes = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata]'
81+
$routingProperties.Routes.Add($routeProp)
82+
$properties.Routing = $routingProperties
83+
$newIothub1 = New-AzureRmIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1 -Properties $properties
4284

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

4991
Assert-True { $allIotHubsInResourceGroup.Count -eq 1 }
5092
Assert-True { $iotHub.Name -eq $IotHubName }
93+
Assert-True { $iotHub.Properties.Routing.Routes.Count -eq 1}
94+
Assert-True { $iotHub.Properties.Routing.Routes[0].Name -eq "route"}
95+
Assert-True { $iotHub.Properties.Routing.Endpoints.EventHubs[0].Name -eq "eh1"}
5196

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

104149
# Add Key
105-
Add-AzureRmIotHubKey -ResourceGroupName $ResourceGroupName -Name $IotHubName -KeyName iothubowner1 -PrimaryKey primarykey -SecondaryKey secondarykey -Rights RegistryRead
150+
Add-AzureRmIotHubKey -ResourceGroupName $ResourceGroupName -Name $IotHubName -KeyName iothubowner1 -Rights RegistryRead
106151

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

184+
# Routing Properties Update
185+
$routingProperties = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingProperties
186+
$routeProp = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
187+
$routeProp.Name = "route1"
188+
$routeProp.Condition = "true"
189+
$routeProp.IsEnabled = 1
190+
$routeProp.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
191+
$routeProp.EndpointNames.Add("events")
192+
$routeProp.Source = "DeviceMessages"
193+
$routingProperties.Routes = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata]'
194+
$routingProperties.Routes.Add($routeProp)
195+
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -RoutingProperties $routingProperties
196+
Assert-True { $iotHubUpdated.Properties.Routing.Routes.Count -eq 1}
197+
Assert-True { $iotHubUpdated.Properties.Routing.Routes[0].Name -eq "route1"}
198+
199+
# Route Properties Update
200+
$routeProp1 = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
201+
$routeProp1.Name = "route2"
202+
$routeProp1.Condition = "true"
203+
$routeProp1.IsEnabled = 1
204+
$routeProp1.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
205+
$routeProp1.EndpointNames.Add("events")
206+
$routeProp1.Source = "DeviceMessages"
207+
208+
$routeProp2 = New-Object Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata
209+
$routeProp2.Name = "route3"
210+
$routeProp2.Condition = "true"
211+
$routeProp2.IsEnabled = 1
212+
$routeProp2.EndpointNames = New-Object 'System.Collections.Generic.List[String]'
213+
$routeProp2.EndpointNames.Add("events")
214+
$routeProp2.Source = "DeviceMessages"
215+
216+
$routes = New-Object 'System.Collections.Generic.List[Microsoft.Azure.Commands.Management.IotHub.Models.PSRouteMetadata]'
217+
$routes.Add($routeProp1)
218+
$routes.Add($routeProp2)
219+
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -Routes $routes
220+
Assert-True { $iotHubUpdated.Properties.Routing.Routes.Count -eq 2}
221+
Assert-True { $iotHubUpdated.Properties.Routing.Routes[0].Name -eq "route2"}
222+
Assert-True { $iotHubUpdated.Properties.Routing.FallbackRoute.IsEnabled -eq 0}
223+
224+
$iothub = Get-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName
225+
$iothub.Properties.Routing.FallbackRoute.IsEnabled = 1
226+
$iotHubUpdated = Set-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName -FallbackRoute $iothub.Properties.Routing.FallbackRoute
227+
Assert-True { $iotHubUpdated.Properties.Routing.FallbackRoute.IsEnabled -eq 1}
228+
139229
# Remove IotHub
140230
Remove-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName
141231
}

src/ResourceManager/IotHub/Commands.IotHub.Test/SessionRecords/Microsoft.Azure.Commands.IotHub.Test.ScenarioTests.IotHubTests/TestAzureIotHubLifeCycle.json

Lines changed: 2754 additions & 930 deletions
Large diffs are not rendered by default.

src/ResourceManager/IotHub/Commands.IotHub.Test/packages.config

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Hyak.Common" version="1.0.3" targetFramework="net45" />
43
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
54
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
65
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
76
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Management.EventHub" version="1.2.0" targetFramework="net452" />
8+
<package id="Microsoft.Azure.Management.IotHub" version="1.1.2" targetFramework="net452" />
89
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
910
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
1011
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
@@ -13,8 +14,8 @@
1314
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
1415
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net45" />
1516
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
16-
<package id="Microsoft.Rest.ClientRuntime" version="2.3.5" targetFramework="net45" />
17-
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.5" targetFramework="net45" />
17+
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net452" />
18+
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.7" targetFramework="net452" />
1819
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.9-preview" targetFramework="net45" />
1920
<package id="Microsoft.Rest.ClientRuntime.Azure.TestFramework" version="1.5.0-preview" targetFramework="net45" />
2021
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />

0 commit comments

Comments
 (0)