Skip to content
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

[Iot Hub] Manage IoT automatic device management configuration #11516

Merged
merged 1 commit into from
Apr 9, 2020
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
40 changes: 40 additions & 0 deletions src/IotHub/IotHub.Test/ScenarioTests/IotHubDPConfigurationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
{
public class IotHubDPConfigurationTests : RMTestBase
{
public XunitTracingInterceptor _logger;

public IotHubDPConfigurationTests(ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAzureIotHubConfigurationLifecycle()
{
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubConfigurationLifecycle");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------


####################################
## IotHub Configuration Cmdlets ##
####################################

<#
.SYNOPSIS
Test all iothub configuration cmdlets
#>
function Test-AzureRmIotHubConfigurationLifecycle
{
$Location = Get-Location "Microsoft.Devices" "IotHubs"
$IotHubName = getAssetName
$ResourceGroupName = getAssetName
$Sku = "S1"
$device1 = getAssetName
$config1 = getAssetName
$config2 = getAssetName

# Create Resource Group
$resourceGroup = New-AzResourceGroup -Name $ResourceGroupName -Location $Location

# Create Iot Hub
$iothub = New-AzIotHub -Name $IotHubName -ResourceGroupName $ResourceGroupName -Location $Location -SkuName $Sku -Units 1

# Add iot device
$newDevice1 = Add-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -AuthMethod 'shared_private_key'
Assert-True { $newDevice1.Id -eq $device1 }
Assert-False { $newDevice1.Capabilities.IotEdge }

# Assign device configuration parameters
$labels = @{}
$labels.add("key0","value0")
$metrics = @{}
$metrics.add("query1", "select deviceId from devices where tags.location='US'")
$prop = @{}
$prop.add("Location", "US")
$content = @{}
$content.add("properties.desired.Region", $prop)
$condition = "tags.location ='US'"
$priority = 10
$updatedPriority = 8

# Add device configuration
$newConfiguration = Add-AzIotHubConfiguration -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -Name $config1 -Priority $priority -TargetCondition $condition -Label $labels -Metric $metrics -DeviceContent $content
Assert-True { $newConfiguration.Id -eq $config1}

# Get device configuration details
$configuration = Get-AzIotHubConfiguration -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -Name $config1
Assert-True { $configuration.Id -eq $config1}
Assert-True { $configuration.TargetCondition -eq $condition}
Assert-True { $configuration.Priority -eq $priority}
Assert-True { $configuration.Labels.Count -eq 1}
Assert-True { $configuration.Metrics.Count -eq 1}

# Set device configuration
$updatedConfiguration = Set-AzIotHubConfiguration -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -Name $config1 -Priority $updatedPriority
Assert-True { $updatedConfiguration.Id -eq $config1}
Assert-True { $updatedConfiguration.Priority -eq $updatedPriority}

# Delete all configuration
$result = Remove-AzIotHubConfiguration -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -Passthru
Assert-True { $result }

# Remove IotHub
Remove-AzIotHub -ResourceGroupName $ResourceGroupName -Name $IotHubName
}
Loading