Skip to content

Commit 8ac94d8

Browse files
authored
Merge pull request #6968 from anusapan/preview
Add Routing cmdlets in IoTHub
2 parents c665357 + bad8397 commit 8ac94d8

File tree

71 files changed

+7445
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+7445
-127
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
<Private>True</Private>
4343
</Reference>
4444
<Reference Include="Microsoft.Azure.Management.IotHub, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.IotHub.2.0.0\lib\net452\Microsoft.Azure.Management.IotHub.dll</HintPath>
45+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.IotHub.2.1.0\lib\net452\Microsoft.Azure.Management.IotHub.dll</HintPath>
4646
<Private>True</Private>
4747
</Reference>
4848
</ItemGroup>
4949
<ItemGroup>
5050
<Compile Include="ScenarioTests\IotHubController.cs" />
51+
<Compile Include="ScenarioTests\IotHubRoutingTests.cs" />
5152
<Compile Include="ScenarioTests\IotHubTests.cs" />
5253
<Compile Include="Properties\AssemblyInfo.cs" />
5354
</ItemGroup>
@@ -57,9 +58,15 @@
5758
</None>
5859
<None Include="ScenarioTests\Assert.ps1" />
5960
<None Include="ScenarioTests\Common.ps1" />
61+
<None Include="ScenarioTests\IotHubRoutingTests.ps1">
62+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
63+
</None>
6064
<None Include="ScenarioTests\IotHubTests.ps1">
6165
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6266
</None>
67+
<None Include="SessionRecords\Microsoft.Azure.Commands.IotHub.Test.ScenarioTests.IotHubRoutingTests\TestAzureIotHubRoutingLifeCycle.json">
68+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
69+
</None>
6370
<None Include="SessionRecords\Microsoft.Azure.Commands.IotHub.Test.ScenarioTests.IotHubTests\TestAzureIotHubCertificateLifeCycle.json">
6471
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6572
</None>

src/ResourceManager/IotHub/Commands.IotHub.Test/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
3+
using Xunit;
44

55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
@@ -34,3 +34,4 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("3.0.0")]
3636
[assembly: AssemblyFileVersion("3.0.0")]
37+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
16+
using Microsoft.Azure.Test;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
23+
{
24+
public class IotHubRoutingTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public IotHubRoutingTests(ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
}
33+
34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
[Trait("Re-record", "ClientRuntime changes")]
37+
public void TestAzureIotHubRoutingLifeCycle()
38+
{
39+
IotHubController.NewInstance.RunPsTestWorkflow(
40+
_logger,
41+
() => { return new[] { "Test-AzureRmIotHubRoutingLifecycle" }; },
42+
null,
43+
null,
44+
TestUtilities.GetCallingClass(),
45+
TestUtilities.GetCurrentMethodName());
46+
}
47+
}
48+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
16+
#################################
17+
## IotHub Routing Cmdlets ##
18+
#################################
19+
20+
<#
21+
.SYNOPSIS
22+
Test all iothub routing cmdlets
23+
#>
24+
function Test-AzureRmIotHubRoutingLifecycle
25+
{
26+
$Location = Get-Location "Microsoft.Devices" "IotHub"
27+
$IotHubName = getAssetName
28+
$ResourceGroupName = getAssetName
29+
$namespaceName = getAssetName 'eventHub'
30+
$eventHubName = getAssetName
31+
$authRuleName = getAssetName
32+
$endpointName = getAssetName
33+
$routeName = getAssetName
34+
$Sku = "S1"
35+
$EndpointTypeEventHub = [Microsoft.Azure.Commands.Management.IotHub.Models.PSEndpointType] "EventHub"
36+
$RoutingSourceTwinChangeEvents = [Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingSource] "TwinChangeEvents"
37+
$RoutingSourceDeviceMessages = [Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingSource] "DeviceMessages"
38+
39+
# Create or Update Resource Group
40+
$resourceGroup = New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
41+
42+
# Create Iot Hub
43+
$iothub = New-AzureRmIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1
44+
45+
# Create new eventHub namespace
46+
$eventHubNamespace = New-AzureRmEventHubNamespace -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -Location $Location
47+
Wait-Seconds 15
48+
Assert-True {$eventHubNamespace.ProvisioningState -eq "Succeeded"}
49+
$regexMatches = $eventHubNamespace.Id | Select-String -Pattern '^/subscriptions/(.*)/resourceGroups/(.*)/providers/(.*)$'
50+
$eventHubSubscriptionId = $regexMatches.Matches.Groups[1].Value
51+
$eventHubResourceGroup = $regexMatches.Matches.Groups[2].Value
52+
53+
# Create new eventHub
54+
$msgRetentionInDays = 3
55+
$partionCount = 2
56+
$eventHub = New-AzureRmEventHub -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -MessageRetentionInDays $msgRetentionInDays -PartitionCount $partionCount
57+
58+
# Create AuthRule for eventhub
59+
$rights = "Listen","Send"
60+
$authRule = New-AzureRmEventHubAuthorizationRule -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -AuthorizationRuleName $authRuleName -Rights $rights
61+
$keys = Get-AzureRmEventHubKey -ResourceGroup $ResourceGroupName -NamespaceName $namespaceName -EventHubName $eventHubName -AuthorizationRuleName $authRuleName
62+
$ehConnectionString = $keys.PrimaryConnectionString
63+
64+
# Get all routing endpoints
65+
$routingEndpoints = Get-AzureRmIotHubRoutingEndpoint -ResourceGroupName $ResourceGroupName -Name $IotHubName
66+
Assert-True { $routingEndpoints.Count -eq 0}
67+
68+
# Add event hub endpoint
69+
$newRoutingEndpoint = Add-AzureRmIotHubRoutingEndpoint -ResourceGroupName $ResourceGroupName -Name $IotHubName -EndpointName $endpointName -EndpointType $EndpointTypeEventHub -EndpointResourceGroup $eventHubResourceGroup -EndpointSubscriptionId $eventHubSubscriptionId -ConnectionString $ehConnectionString
70+
Assert-True { $newRoutingEndpoint.ResourceGroup -eq $eventHubResourceGroup}
71+
Assert-True { $newRoutingEndpoint.SubscriptionId -eq $eventHubSubscriptionId}
72+
Assert-True { $newRoutingEndpoint.Name -eq $endpointName}
73+
74+
# Get all routing endpoints
75+
$updatedRoutingEndpoints = Get-AzureRmIotHubRoutingEndpoint -ResourceGroupName $ResourceGroupName -Name $IotHubName
76+
Assert-True { $updatedRoutingEndpoints.Count -eq 1}
77+
Assert-True { $updatedRoutingEndpoints[0].ResourceGroup -eq $eventHubResourceGroup}
78+
Assert-True { $updatedRoutingEndpoints[0].SubscriptionId -eq $eventHubSubscriptionId}
79+
Assert-True { $updatedRoutingEndpoints[0].Name -eq $endpointName}
80+
81+
# Get all routes
82+
$routes = Get-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName
83+
Assert-True { $routingEndpoints.Count -eq 0}
84+
85+
# Add new route
86+
$newRoute = Add-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Source $RoutingSourceDeviceMessages -EndpointName $endpointName
87+
Assert-True { $newRoute.Name -eq $routeName}
88+
Assert-True { $newRoute.Source -eq $RoutingSourceDeviceMessages}
89+
Assert-True { $newRoute.EndpointNames -eq $endpointName}
90+
Assert-False { $newRoute.IsEnabled }
91+
92+
# Get all routes
93+
$routes = Get-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName
94+
Assert-True { $routes.Count -eq 1}
95+
Assert-True { $routes[0].Name -eq $routeName}
96+
Assert-True { $routes[0].Source -eq $RoutingSourceDeviceMessages}
97+
Assert-True { $routes[0].EndpointNames -eq $endpointName}
98+
Assert-False { $routes[0].IsEnabled }
99+
100+
# Set route
101+
$updatedRoute = Set-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Source $RoutingSourceTwinChangeEvents -Enabled
102+
Assert-True { $updatedRoute.Name -eq $routeName}
103+
Assert-True { $updatedRoute.Source -eq $RoutingSourceTwinChangeEvents}
104+
Assert-True { $updatedRoute.EndpointNames -eq $endpointName}
105+
Assert-True { $updatedRoute.IsEnabled }
106+
107+
# Test All Routes
108+
$testRouteOutput = Test-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -Source $RoutingSourceTwinChangeEvents
109+
Assert-True { $testRouteOutput.Count -eq 1}
110+
Assert-True { $testRouteOutput[0].Name -eq $routeName}
111+
Assert-True { $testRouteOutput[0].Source -eq $RoutingSourceTwinChangeEvents}
112+
Assert-True { $testRouteOutput[0].EndpointNames -eq $endpointName}
113+
Assert-True { $testRouteOutput[0].IsEnabled }
114+
115+
# Delete Route
116+
$result = Remove-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Passthru
117+
Assert-True { $result }
118+
119+
# Delete routing endpoint
120+
$result = Remove-AzureRmIotHubRoutingEndpoint -ResourceGroupName $ResourceGroupName -Name $IotHubName -EndpointName $endpointName -Passthru
121+
Assert-True { $result }
122+
123+
# Remove IotHub
124+
Remove-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName
125+
}

0 commit comments

Comments
 (0)