-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage distributed settings per-device
- Loading branch information
Showing
19 changed files
with
1,933 additions
and
17 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/IotHub/IotHub.Test/ScenarioTests/IotHubDPTracingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 IotHubDPTracingTests : RMTestBase | ||
{ | ||
public XunitTracingInterceptor _logger; | ||
|
||
public IotHubDPTracingTests(ITestOutputHelper output) | ||
{ | ||
_logger = new XunitTracingInterceptor(output); | ||
XunitTracingInterceptor.AddToContext(_logger); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.LiveOnly)] | ||
public void TestAzureIotHubTracing() | ||
{ | ||
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubTracing"); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/IotHub/IotHub.Test/ScenarioTests/IotHubDPTracingTests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# 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 Tracing Cmdlets ## | ||
################################# | ||
|
||
<# | ||
.SYNOPSIS | ||
Test all iothub device tracing cmdlets | ||
#> | ||
function Test-AzureRmIotHubTracing | ||
{ | ||
$Location = Get-Location "Microsoft.Devices" "IotHubs" "WEST US 2" | ||
$IotHubName = getAssetName | ||
$ResourceGroupName = getAssetName | ||
$Sku = "S1" | ||
$device1 = 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 } | ||
|
||
# Get device tracing detail | ||
$deviceTracing = Get-AzIotHubDistributedTracing -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 | ||
Assert-True { $deviceTracing.DeviceId -eq $device1} | ||
Assert-True { $deviceTracing.TracingOption.SamplingMode -eq 'Disabled'} | ||
Assert-True { $deviceTracing.TracingOption.SamplingRate -eq ''} | ||
Assert-False { $deviceTracing.IsSynced} | ||
|
||
# Set device tracing option | ||
$updatedDeviceTracing = Set-AzIotHubDistributedTracing -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -mode 'Enabled' -rate 45 | ||
Assert-True { $updatedDeviceTracing.DeviceId -eq $device1} | ||
Assert-True { $updatedDeviceTracing.TracingOption.SamplingMode -eq 'Enabled'} | ||
Assert-True { $updatedDeviceTracing.TracingOption.SamplingRate -eq 45} | ||
Assert-False { $updatedDeviceTracing.IsSynced} | ||
|
||
# Delete all devices | ||
$result = Remove-AzIotHubDevice -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -Passthru | ||
Assert-True { $result } | ||
} |
1,008 changes: 1,008 additions & 0 deletions
1,008
...Azure.Commands.IotHub.Test.ScenarioTests.IotHubDPTracingTests/TestAzureIotHubTracing.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/IotHub/IotHub/IotHub/DataPlane/DistributedTracing/GetAzIotHubDistributedTracing.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// 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. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.Management.IotHub | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using Microsoft.Azure.Commands.Management.IotHub.Common; | ||
using Microsoft.Azure.Commands.Management.IotHub.Models; | ||
using Microsoft.Azure.Devices; | ||
using Microsoft.Azure.Devices.Shared; | ||
using Microsoft.Azure.Management.IotHub; | ||
using Microsoft.Azure.Management.IotHub.Models; | ||
using ResourceManager.Common.ArgumentCompleters; | ||
|
||
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "IotHubDistributedTracing", DefaultParameterSetName = ResourceParameterSet)] | ||
[Alias("Get-" + ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "IotHubTracing")] | ||
[OutputType(typeof(PSDeviceTracing))] | ||
public class GetAzIotHubDistributedTracing : IotHubBaseCmdlet | ||
{ | ||
private const string ResourceIdParameterSet = "ResourceIdSet"; | ||
private const string ResourceParameterSet = "ResourceSet"; | ||
private const string InputObjectParameterSet = "InputObjectSet"; | ||
|
||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = InputObjectParameterSet, ValueFromPipeline = true, HelpMessage = "IotHub object")] | ||
[ValidateNotNullOrEmpty] | ||
public PSIotHub InputObject { get; set; } | ||
|
||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Name of the Resource Group")] | ||
[ValidateNotNullOrEmpty] | ||
[ResourceGroupCompleter] | ||
public string ResourceGroupName { get; set; } | ||
|
||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = ResourceIdParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "IotHub Resource Id")] | ||
[ValidateNotNullOrEmpty] | ||
[ResourceIdCompleter("Microsoft.Devices/IotHubs")] | ||
public string ResourceId { get; set; } | ||
|
||
[Parameter(Position = 1, Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Name of the Iot Hub")] | ||
[ValidateNotNullOrEmpty] | ||
public string IotHubName { get; set; } | ||
|
||
[Parameter(Position = 1, Mandatory = true, ParameterSetName = InputObjectParameterSet, HelpMessage = "Target Device Id.")] | ||
[Parameter(Position = 1, Mandatory = true, ParameterSetName = ResourceIdParameterSet, HelpMessage = "Target Device Id.")] | ||
[Parameter(Position = 2, Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Target Device Id.")] | ||
[ValidateNotNullOrEmpty] | ||
public string DeviceId { get; set; } | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
IotHubDescription iotHubDescription; | ||
if (ParameterSetName.Equals(InputObjectParameterSet)) | ||
{ | ||
this.ResourceGroupName = this.InputObject.Resourcegroup; | ||
this.IotHubName = this.InputObject.Name; | ||
iotHubDescription = IotHubUtils.ConvertObject<PSIotHub, IotHubDescription>(this.InputObject); | ||
} | ||
else | ||
{ | ||
if (ParameterSetName.Equals(ResourceIdParameterSet)) | ||
{ | ||
this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId); | ||
this.IotHubName = IotHubUtils.GetIotHubName(this.ResourceId); | ||
} | ||
|
||
iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.IotHubName); | ||
} | ||
|
||
IEnumerable<SharedAccessSignatureAuthorizationRule> authPolicies = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.IotHubName); | ||
SharedAccessSignatureAuthorizationRule policy = IotHubUtils.GetPolicy(authPolicies, PSAccessRights.RegistryWrite); | ||
PSIotHubConnectionString psIotHubConnectionString = IotHubUtils.ToPSIotHubConnectionString(policy, iotHubDescription.Properties.HostName); | ||
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(psIotHubConnectionString.PrimaryConnectionString); | ||
|
||
Twin deviceTwin = registryManager.GetTwinAsync(this.DeviceId).GetAwaiter().GetResult(); | ||
|
||
if (deviceTwin == null) | ||
{ | ||
throw new ArgumentException($"The entered non-edge device \"{this.DeviceId}\" doesn't exist."); | ||
} | ||
|
||
IotHubDataPlaneUtils.Validate_Device_Tracing(this.DeviceId, iotHubDescription.Sku.Tier.Value.ToString(), iotHubDescription.Location, deviceTwin.Capabilities.IotEdge); | ||
|
||
this.WriteObject(IotHubDataPlaneUtils.GetDeviceTracing(this.DeviceId, deviceTwin)); | ||
} | ||
} | ||
} |
Oops, something went wrong.