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

fix(iot-serv): Fix bug where device scope and parent scopes set to device weren't used in bulk add operations #2189

Merged
merged 2 commits into from
Oct 4, 2021
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
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