@@ -37,8 +37,50 @@ function Test-AzureRmIotHubLifecycle
37
37
# Create or Update Resource Group
38
38
$resourceGroup = New-AzureRmResourceGroup - Name $ResourceGroupName - Location $Location
39
39
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
+
40
62
# 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
42
84
43
85
# Get Iot Hub in resourcegroup
44
86
$allIotHubsInResourceGroup = Get-AzureRmIotHub - ResourceGroupName $ResourceGroupName
@@ -48,6 +90,9 @@ function Test-AzureRmIotHubLifecycle
48
90
49
91
Assert-True { $allIotHubsInResourceGroup.Count -eq 1 }
50
92
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" }
51
96
52
97
# Get Quota Metrics
53
98
$quotaMetrics = Get-AzureRmIotHubQuotaMetric - ResourceGroupName $ResourceGroupName - Name $IotHubName
@@ -102,7 +147,7 @@ function Test-AzureRmIotHubLifecycle
102
147
Assert-True { $eventubConsumerGroup.Count -eq 1 }
103
148
104
149
# 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
106
151
107
152
# Get Keys
108
153
$keys = Get-AzureRmIotHubKey - ResourceGroupName $ResourceGroupName - Name $IotHubName
@@ -136,6 +181,51 @@ function Test-AzureRmIotHubLifecycle
136
181
$iotHubUpdated = Set-AzureRmIotHub - ResourceGroupName $ResourceGroupName - Name $IotHubName - OperationsMonitoringProperties $op
137
182
Assert-True { $iothubUpdated.Properties.OperationsMonitoringProperties.OperationMonitoringEvents [" Connections" ] -eq " Information" }
138
183
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
+
139
229
# Remove IotHub
140
230
Remove-AzureRmIotHub - ResourceGroupName $ResourceGroupName - Name $IotHubName
141
231
}
0 commit comments