Skip to content

Commit

Permalink
Reprovision device for all protocols when the connection status chang…
Browse files Browse the repository at this point in the history
…e reason is Bad_Credential (#2198)
  • Loading branch information
shantanu1singh authored Jan 10, 2020
1 parent de7e789 commit 3601a56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,22 @@ async void OnConnectionStatusChanged(ConnectionStatus status, ConnectionStatusCh
this.ModuleConnection.GetModuleClient().Map(x => x.UpstreamProtocol).GetOrElse(UpstreamProtocol.Amqp);
Events.ConnectionStatusChanged(status, reason);

// Notify the IoT Edge daemon that a device has been deprovisioned and it should check
// if the device has been provisioned to a different IoT hub instead.
// We want to notify the IoT Edge daemon in the following two cases -
// 1. The device has been deprovisioned and might have been reprovisioned on another IoT hub.
// 2. The IoT Hub that the device belongs to is no longer in existence and the device might have been
// moved to a different IoT hub.
//
// When the Amqp or AmqpWs protocol is used, the SDK returns a connection status change reason of
// Device_Disabled when a device is either disabled or deleted in IoT hub.
// For the Mqtt and MqttWs protocol however, the SDK returns a Bad_Credential status as it's not
// possible for IoT hub to distinguish between 'device does not exist', 'device is disabled' and
// 'device exists but wrong credentials were supplied' cases.
//
// When an IoT hub is no longer in existence (i.e., it has been deleted), the SDK returns the
// connection status change reason of Bad_Credential for all the Amqp and Mqtt protocols.
if ((reason == ConnectionStatusChangeReason.Device_Disabled &&
(protocol == UpstreamProtocol.Amqp || protocol == UpstreamProtocol.AmqpWs)) ||
(reason == ConnectionStatusChangeReason.Bad_Credential &&
(protocol == UpstreamProtocol.Mqtt || protocol == UpstreamProtocol.MqttWs)))
reason == ConnectionStatusChangeReason.Bad_Credential)
{
await this.deviceManager.ReprovisionDeviceAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,13 @@ public async Task GetDeploymentConfigInfoAsyncIncludesExceptionWhenDeserializeTh
[InlineData(UpstreamProtocol.AmqpWs, ConnectionStatusChangeReason.Device_Disabled, true)]
[InlineData(UpstreamProtocol.Mqtt, ConnectionStatusChangeReason.Bad_Credential, true)]
[InlineData(UpstreamProtocol.MqttWs, ConnectionStatusChangeReason.Bad_Credential, true)]
[InlineData(UpstreamProtocol.Amqp, ConnectionStatusChangeReason.Bad_Credential, true)]
[InlineData(UpstreamProtocol.AmqpWs, ConnectionStatusChangeReason.Bad_Credential, true)]
[InlineData(UpstreamProtocol.Amqp, ConnectionStatusChangeReason.Communication_Error, false)]
[InlineData(UpstreamProtocol.AmqpWs, ConnectionStatusChangeReason.Communication_Error, false)]
[InlineData(UpstreamProtocol.Mqtt, ConnectionStatusChangeReason.Communication_Error, false)]
[InlineData(UpstreamProtocol.MqttWs, ConnectionStatusChangeReason.Communication_Error, false)]
internal async Task ConnectionStatusChangeReasonToDeviceNotFoundReprovisionsDevice(
internal async Task ConnectionStatusChangeReasonReprovisionsDevice(
UpstreamProtocol protocol, ConnectionStatusChangeReason connectionStatusChangeReason, bool shouldReprovision)
{
// Arrange
Expand Down

0 comments on commit 3601a56

Please sign in to comment.