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

Enable import/export of configurations #2322

Merged
merged 4 commits into from
May 12, 2022
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
50 changes: 25 additions & 25 deletions e2e/test/iothub/service/RegistryManagerExportDevicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ public async Task RegistryManager_ExportDevices(StorageAuthenticationType storag
})
.ConfigureAwait(false);

//Configuration configuration = await registryManager
// .AddConfigurationAsync(
// new Configuration(configurationId)
// {
// Priority = 2,
// Labels = { { "labelName", "labelValue" } },
// TargetCondition = "*",
// Content =
// {
// DeviceContent = { { "properties.desired.x", 4L } },
// },
// Metrics =
// {
// Queries = { { "successfullyConfigured", "select deviceId from devices where properties.reported.x = 4" } }
// },
// })
// .ConfigureAwait(false);
Configuration configuration = await registryManager
.AddConfigurationAsync(
new Configuration(configurationId)
{
Priority = 2,
Labels = { { "labelName", "labelValue" } },
TargetCondition = "*",
Content =
{
DeviceContent = { { "properties.desired.x", 4L } },
},
Metrics =
{
Queries = { { "successfullyConfigured", "select deviceId from devices where properties.reported.x = 4" } }
},
})
.ConfigureAwait(false);

// act

Expand All @@ -143,11 +143,11 @@ await ValidateDevicesAsync(
edge2,
device)
.ConfigureAwait(false);
//await ValidateConfigurationsAsync(
// configsFileName,
// storageContainer,
// configuration)
// .ConfigureAwait(false);
await ValidateConfigurationsAsync(
configsFileName,
storageContainer,
configuration)
.ConfigureAwait(false);
}
finally
{
Expand Down Expand Up @@ -178,8 +178,8 @@ private async Task<JobProperties> CreateAndWaitForJobAsync(
devicesFileName,
storageAuthenticationType,
identity);
//exportJobResponse.IncludeConfigurations = true;
//exportJobResponse.ConfigurationsBlobName = configsFileName;
exportJobResponse.IncludeConfigurations = true;
exportJobResponse.ConfigurationsBlobName = configsFileName;

while (tryCount < MaxIterationWait)
{
Expand Down Expand Up @@ -315,7 +315,7 @@ private async Task CleanUpDevicesAsync(
await registryManager.RemoveDeviceAsync(deviceId).ConfigureAwait(false);
await registryManager.RemoveDeviceAsync(edgeId2).ConfigureAwait(false);
await registryManager.RemoveDeviceAsync(edgeId1).ConfigureAwait(false);
//await registryManager.RemoveConfigurationAsync(configurationId).ConfigureAwait(false);
await registryManager.RemoveConfigurationAsync(configurationId).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
58 changes: 29 additions & 29 deletions e2e/test/iothub/service/RegistryManagerImportDevicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@ public async Task RegistryManager_ImportDevices(StorageAuthenticationType storag
});
await UploadFileAndConfirmAsync(storageContainer, devicesStream, devicesFileName).ConfigureAwait(false);

//using Stream configsStream = ImportExportHelpers.BuildImportStream(
// new List<ImportConfiguration>
// {
// new ImportConfiguration(configId)
// {
// ImportMode = ConfigurationImportMode.CreateOrUpdateIfMatchETag,
// Priority = 3,
// Labels = { { "labelName", "labelValue" } },
// TargetCondition = "*",
// Content =
// {
// DeviceContent = { { "properties.desired.x", 5L } },
// },
// Metrics =
// {
// Queries = { { "successfullyConfigured", "select deviceId from devices where properties.reported.x = 5" } }
// },
// },
// });
//await UploadFileAndConfirmAsync(storageContainer, configsStream, configsFileName).ConfigureAwait(false);
using Stream configsStream = ImportExportHelpers.BuildImportStream(
new List<ImportConfiguration>
{
new ImportConfiguration(configId)
{
ImportMode = ConfigurationImportMode.CreateOrUpdateIfMatchETag,
Priority = 3,
Labels = { { "labelName", "labelValue" } },
TargetCondition = "*",
Content =
{
DeviceContent = { { "properties.desired.x", 5L } },
},
Metrics =
{
Queries = { { "successfullyConfigured", "select deviceId from devices where properties.reported.x = 5" } }
},
},
});
await UploadFileAndConfirmAsync(storageContainer, configsStream, configsFileName).ConfigureAwait(false);

ManagedIdentity identity = isUserAssignedMsi
? new ManagedIdentity
Expand All @@ -126,14 +126,14 @@ public async Task RegistryManager_ImportDevices(StorageAuthenticationType storag

// should not throw due to 404, but device may not immediately appear in registry
Device device = null;
//Configuration config = null;
Configuration config = null;
for (int i = 0; i < MaxIterationWait; ++i)
{
await Task.Delay(s_waitDuration).ConfigureAwait(false);
try
{
device = await registryManager.GetDeviceAsync(deviceId).ConfigureAwait(false);
//config = await registryManager.GetConfigurationAsync(configId).ConfigureAwait(false);
config = await registryManager.GetConfigurationAsync(configId).ConfigureAwait(false);
break;
}
catch (Exception ex)
Expand All @@ -145,17 +145,17 @@ public async Task RegistryManager_ImportDevices(StorageAuthenticationType storag
{
Assert.Fail($"Device {deviceId} not found in registry manager");
}
//if (config == null)
//{
// Assert.Fail($"Config {configId} not found in registry manager");
//}
if (config == null)
{
Assert.Fail($"Config {configId} not found in registry manager");
}
}
finally
{
try
{
await registryManager.RemoveDeviceAsync(deviceId).ConfigureAwait(false);
//await registryManager.RemoveConfigurationAsync(configId).ConfigureAwait(false);
await registryManager.RemoveConfigurationAsync(configId).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -200,8 +200,8 @@ private async Task<JobProperties> CreateAndWaitForJobAsync(
devicesFileName,
storageAuthenticationType,
identity);
//jobProperties.ConfigurationsBlobName = configsFileName;
//jobProperties.IncludeConfigurations = true;
jobProperties.ConfigurationsBlobName = configsFileName;
jobProperties.IncludeConfigurations = true;

while (tryCount < MaxIterationWait)
{
Expand Down
4 changes: 2 additions & 2 deletions iothub/service/src/JobProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public JobProperties()
/// The service assumes this is false, if not specified. If true, then configurations are included in the data export/import.
/// </remarks>
[JsonProperty(PropertyName = "includeConfigurations", NullValueHandling = NullValueHandling.Ignore)]
private bool? IncludeConfigurations { get; set; } // waiting for bug fix before publicizing
public bool? IncludeConfigurations { get; set; }

/// <summary>
/// Specifies the name of the blob to use when exporting/importing configurations.
Expand All @@ -141,7 +141,7 @@ public JobProperties()
/// The service assumes this is configurations.txt, if not specified.
/// </remarks>
[JsonProperty(PropertyName = "configurationsBlobName", NullValueHandling = NullValueHandling.Ignore)]
private string ConfigurationsBlobName { get; set; } // waiting for bug fix before publicizing
public string ConfigurationsBlobName { get; set; }

#pragma warning disable CA1054 // Uri parameters should not be strings

Expand Down