Skip to content

Commit

Permalink
fix mismatch tag name between configuration and IoT Edge (#445)
Browse files Browse the repository at this point in the history
* fix #301

* unit test fix
  • Loading branch information
Sben65 authored Mar 11, 2022
1 parent 54f66e0 commit 0073b9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) CGI France. All rights reserved.
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Server.Tests.Unit.Controllers.V10
Expand Down Expand Up @@ -57,7 +57,7 @@ public async Task GetAllDevicesShouldReturnListOfEdgeDevices()
{
// Arrange
var twin = new Twin("aaa");
twin.Tags["purpose"] = "test";
twin.Tags["type"] = "test";

_ = this.mockDeviceService.Setup(x => x.GetAllEdgeDevice())
.ReturnsAsync(new[]
Expand Down Expand Up @@ -102,7 +102,7 @@ public async Task WhenSpecifyingIdGetShouldReturnTheEdgeDevice()
var deviceId = Guid.NewGuid().ToString();

var twin = new Twin(deviceId);
twin.Tags["purpose"] = "bbb";
twin.Tags[nameof(IoTEdgeDevice.Type)] = "bbb";
twin.Tags["env"] = "fake";

_ = this.mockDeviceService.Setup(c => c.GetDeviceTwin(It.Is<string>(x => x == deviceId)))
Expand Down Expand Up @@ -174,7 +174,7 @@ public async Task GetEnrollmentCredentialsShouldReturnEnrollmentCredentials()
};

var mockTwin = new Twin("aaa");
mockTwin.Tags["purpose"] = "bbb";
mockTwin.Tags["type"] = "bbb";

_ = this.mockProvisioningServiceManager.Setup(c => c.GetEnrollmentCredentialsAsync("aaa", "bbb"))
.ReturnsAsync(mockRegistrationCredentials);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) CGI France. All rights reserved.
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Server.Controllers.V10
Expand Down Expand Up @@ -96,7 +96,7 @@ public async Task<IActionResult> Get()
{
DeviceId = deviceTwin.DeviceId,
Status = twin.Status?.ToString(),
Type = DeviceHelper.RetrieveTagValue(twin, "purpose"),
Type = DeviceHelper.RetrieveTagValue(twin, nameof(IoTEdgeDevice.Type)) ?? "Undefined",
NbDevices = DeviceHelper.RetrieveConnectedDeviceCount(deviceTwin)
};

Expand Down Expand Up @@ -127,7 +127,7 @@ public async Task<IActionResult> Get(string deviceId)
Scope = deviceTwin.DeviceScope,
ConnectionState = deviceTwin.ConnectionState?.ToString(),
// We retrieve the values of tags
Type = DeviceHelper.RetrieveTagValue(deviceTwin, "purpose"),
Type = DeviceHelper.RetrieveTagValue(deviceTwin, nameof(IoTEdgeDevice.Type)) ?? "Undefined",
Environment = DeviceHelper.RetrieveTagValue(deviceTwin, "env"),
// We retrieve the number of connected device
NbDevices = await this.RetrieveNbConnectedDevice(deviceTwin.DeviceId),
Expand Down Expand Up @@ -162,7 +162,7 @@ public async Task<ActionResult<EnrollmentCredentials>> GetCredentials(string dev
return this.NotFound($"IoT Edge {deviceId} doesn' exist.");
}

var deviceType = DeviceHelper.RetrieveTagValue(deviceTwin, "purpose");
var deviceType = DeviceHelper.RetrieveTagValue(deviceTwin, nameof(IoTEdgeDevice.Type));

var credentials = await this.deviceProvisioningServiceManager.GetEnrollmentCredentialsAsync(deviceId, deviceType);

Expand All @@ -183,7 +183,7 @@ public async Task<IActionResult> CreateGatewayAsync(IoTEdgeDevice gateway)
var deviceTwin = new Twin(gateway.DeviceId);

deviceTwin.Tags["env"] = gateway.Environment;
deviceTwin.Tags["purpose"] = gateway.Type;
deviceTwin.Tags["type"] = gateway.Type;

var result = await this.devicesService.CreateDeviceWithTwin(gateway.DeviceId, true, deviceTwin, DeviceStatus.Enabled);
this.logger.LogInformation($"Created edge device {gateway.DeviceId}");
Expand Down

0 comments on commit 0073b9e

Please sign in to comment.