Skip to content

Commit 10b3462

Browse files
authored
Merge pull request #10960 from anusapan/manage-device
[IoT] Add support to manage devices in an Iot Hub.
2 parents 812c204 + 420a731 commit 10b3462

File tree

35 files changed

+7299
-2438
lines changed

35 files changed

+7299
-2438
lines changed

src/DeviceProvisioningServices/DeviceProvisioningServices.Test/DeviceProvisioningServices.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.Devices" Version="1.18.2" />
1415
<PackageReference Include="Microsoft.Azure.Management.DeviceProvisioningServices" Version="0.10.0-preview" />
1516
<PackageReference Include="Microsoft.Azure.Management.IotHub" Version="2.10.0-preview" />
1617
</ItemGroup>

src/IotHub/IotHub.Test/IotHub.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.Devices" Version="1.18.2" />
1415
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="2.5.0" />
1516
<PackageReference Include="Microsoft.Azure.Management.IotHub" Version="2.10.0-preview" />
1617
</ItemGroup>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.ServiceManagement.Common.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
21+
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
22+
{
23+
public class IotHubDPDeviceTests : RMTestBase
24+
{
25+
public XunitTracingInterceptor _logger;
26+
27+
public IotHubDPDeviceTests(ITestOutputHelper output)
28+
{
29+
_logger = new XunitTracingInterceptor(output);
30+
XunitTracingInterceptor.AddToContext(_logger);
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
35+
public void TestAzureIotHubDeviceLifecycle()
36+
{
37+
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubDeviceLifecycle");
38+
}
39+
}
40+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 Device Cmdlets ##
18+
#################################
19+
20+
<#
21+
.SYNOPSIS
22+
Test all iothub device cmdlets
23+
#>
24+
function Test-AzureRmIotHubDeviceLifecycle
25+
{
26+
$Location = Get-Location "Microsoft.Devices" "IotHubs"
27+
$IotHubName = getAssetName
28+
$ResourceGroupName = getAssetName
29+
$Sku = "S1"
30+
$device1 = getAssetName
31+
$device2 = getAssetName
32+
$device3 = getAssetName
33+
$primaryThumbprint = '38303FC7371EC78DDE3E18D732C8414EE50969C7'
34+
$secondaryThumbprint = 'F54465586FBAF4AC269851424A592254C8861BE7'
35+
36+
# Create Resource Group
37+
$resourceGroup = New-AzResourceGroup -Name $ResourceGroupName -Location $Location
38+
39+
# Create Iot Hub
40+
$iothub = New-AzIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1
41+
42+
# Get all devices
43+
$devices = Get-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName
44+
Assert-True { $devices.Count -eq 0 }
45+
46+
# Add iot device with symmetric authentication
47+
$newDevice1 = Add-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -AuthMethod 'shared_private_key'
48+
Assert-True { $newDevice1.Id -eq $device1 }
49+
Assert-True { $newDevice1.Authentication.Type -eq 'Sas' }
50+
Assert-False { $newDevice1.Capabilities.IotEdge }
51+
52+
# Add iot device with selfsigned authentication
53+
$newDevice2 = Add-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device2 -AuthMethod 'x509_thumbprint' -PrimaryThumbprint $primaryThumbprint -SecondaryThumbprint $secondaryThumbprint
54+
Assert-True { $newDevice2.Id -eq $device2 }
55+
Assert-True { $newDevice2.Authentication.Type -eq 'SelfSigned' }
56+
Assert-False { $newDevice2.Capabilities.IotEdge }
57+
58+
# Add iot device with certifictae authority authentication
59+
$newDevice3 = Add-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device3 -AuthMethod 'x509_ca'
60+
Assert-True { $newDevice3.Id -eq $device3 }
61+
Assert-True { $newDevice3.Authentication.Type -eq 'CertificateAuthority' }
62+
Assert-False { $newDevice3.Capabilities.IotEdge }
63+
64+
# Get all devices
65+
$devices = Get-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName
66+
Assert-True { $devices.Count -eq 3}
67+
68+
# Update Device
69+
$updatedDevice1 = Set-AzIoTHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -Status 'Disabled' -StatusReason 'Reason1'
70+
Assert-True { $updatedDevice1.Id -eq $device1 }
71+
Assert-True { $updatedDevice1.Status -eq 'Disabled' }
72+
Assert-True { $updatedDevice1.StatusReason -eq 'Reason1' }
73+
74+
# Update iot device to edge device
75+
$updatedDevice2 = Set-AzIoTHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device3 -EdgeEnabled $true
76+
Assert-True { $updatedDevice2.Capabilities.IotEdge }
77+
78+
# Get device detail
79+
$iotDevice = Get-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1
80+
Assert-True { $iotDevice.Id -eq $device1 }
81+
Assert-True { $iotDevice.Authentication.Type -eq 'Sas' }
82+
Assert-False { $iotDevice.Capabilities.IotEdge }
83+
Assert-True { $iotDevice.Status -eq 'Disabled' }
84+
Assert-True { $iotDevice.StatusReason -eq 'Reason1' }
85+
86+
# Delete iot device
87+
$result = Remove-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -Passthru
88+
Assert-True { $result }
89+
90+
# Delete all devices
91+
$result = Remove-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -Passthru
92+
Assert-True { $result }
93+
}

0 commit comments

Comments
 (0)