Skip to content

Commit

Permalink
fix(iot-serv): Fix bug where device scope and parent scopes set to de…
Browse files Browse the repository at this point in the history
…vice weren't used in bulk add operations (#2189)

#2184
  • Loading branch information
timtay-microsoft authored Oct 4, 2021
1 parent 3d19c62 commit 57629ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions e2e/test/iothub/service/RegistryManagerE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public async Task RegistryManager_BulkLifecycle()
var devices = new List<Device>();
for (int i = 0; i < bulkCount; i++)
{
devices.Add(new Device(_devicePrefix + Guid.NewGuid()));
var device = new Device(_devicePrefix + Guid.NewGuid());
device.Scope = "someScope" + Guid.NewGuid();
device.ParentScopes.Add("someParentScope" + Guid.NewGuid());
devices.Add(device);
}

using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString);
Expand All @@ -133,7 +136,11 @@ public async Task RegistryManager_BulkLifecycle()
foreach (Device device in devices)
{
// After a bulk add, every device should be able to be retrieved
Assert.IsNotNull(await registryManager.GetDeviceAsync(device.Id).ConfigureAwait(false));
Device retrievedDevice = await registryManager.GetDeviceAsync(device.Id).ConfigureAwait(false);
Assert.IsNotNull(retrievedDevice.Id);
Assert.AreEqual(device.Scope, retrievedDevice.Scope);
Assert.AreEqual(1, retrievedDevice.ParentScopes.Count);
Assert.AreEqual(device.ParentScopes.ElementAt(0), retrievedDevice.ParentScopes.ElementAt(0));
}

var twins = new List<Twin>();
Expand Down
18 changes: 18 additions & 0 deletions iothub/service/src/ExportImportDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ---------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Azure.Devices.Shared;
using Newtonsoft.Json;
Expand Down Expand Up @@ -64,6 +65,8 @@ public ExportImportDevice(Device device, ImportMode importmode)
StatusReason = device.StatusReason;
Authentication = device.Authentication;
Capabilities = device.Capabilities;
DeviceScope = device.Scope;
ParentScopes = device.ParentScopes;
}

/// <summary>
Expand Down Expand Up @@ -152,6 +155,21 @@ public string TwinETag
[JsonProperty(PropertyName = "deviceScope", NullValueHandling = NullValueHandling.Include)]
public string DeviceScope { get; set; }

/// <summary>
/// The scopes of the upper level edge devices if applicable.
/// </summary>
/// <remarks>
/// For edge devices, the value to set a parent edge device can be retrieved from the parent edge device's <see cref="DeviceScope"/> property.
///
/// For leaf devices, this could be set to the same value as <see cref="DeviceScope"/> or left for the service to copy over.
///
/// For now, this list can only have 1 element in the collection.
///
/// For more information, see <see href="https://docs.microsoft.com/azure/iot-edge/iot-edge-as-gateway?view=iotedge-2020-11#parent-and-child-relationships"/>.
/// </remarks>
[JsonProperty(PropertyName = "parentScopes", NullValueHandling = NullValueHandling.Ignore)]
public IList<string> ParentScopes { get; internal set; } = new List<string>();

private static string SanitizeETag(string eTag)
{
if (!string.IsNullOrWhiteSpace(eTag))
Expand Down

0 comments on commit 57629ff

Please sign in to comment.