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 tempfilter with multi stage deployments #2248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2984625
deploy routes before modules
and-rewsmith Dec 31, 2019
f3b9d49
make configurations ienumerable
and-rewsmith Dec 31, 2019
b1eaa65
Merge branch 'master' into andsmi/new-e2e-tempfilter
and-rewsmith Dec 31, 2019
6f4db94
revert timeout change
and-rewsmith Jan 1, 2020
df57317
Merge branch 'andsmi/new-e2e-tempfilter' of github.com:and-rewsmith/i…
and-rewsmith Jan 1, 2020
cdf6ff2
attempt to fix failed configuration deployment
and-rewsmith Jan 2, 2020
5342ec1
revert all changes
and-rewsmith Jan 2, 2020
95db229
make separate deployment for edgeHub only
and-rewsmith Jan 2, 2020
1af24f6
add comment explaining design decisions
and-rewsmith Jan 2, 2020
11898f8
Merge branch 'master' into andsmi/new-e2e-tempfilter
and-rewsmith Jan 2, 2020
1285094
clean up logic
and-rewsmith Jan 3, 2020
96b300f
cleanup logic
and-rewsmith Jan 3, 2020
66974d2
comment clarity
and-rewsmith Jan 3, 2020
4c12fb6
remove useless comment
and-rewsmith Jan 3, 2020
eac6b83
Merge branch 'master' into andsmi/e2e-tempfilter-enumerable
and-rewsmith Jan 6, 2020
10e4939
deep copy necessary elements
and-rewsmith Jan 6, 2020
dd92e77
Merge branch 'andsmi/e2e-tempfilter-enumerable' of github.com:and-rew…
and-rewsmith Jan 6, 2020
ac5ef0e
Merge branch 'master' into andsmi/e2e-tempfilter-enumerable
and-rewsmith Jan 6, 2020
e823fd9
fix enumerable approach
and-rewsmith Jan 7, 2020
cc6ff22
clean up logic around edgeHub/Agent detection
and-rewsmith Jan 7, 2020
8122c2f
update comment
and-rewsmith Jan 7, 2020
5f29619
clean up wait for status arg generation
and-rewsmith Jan 7, 2020
aabdc80
Merge branch 'master' into andsmi/e2e-tempfilter-enumerable
and-rewsmith Jan 7, 2020
b75c9d1
eliminate boolean dup
and-rewsmith Jan 7, 2020
10cf79b
Merge branch 'andsmi/e2e-tempfilter-enumerable' of github.com:and-rew…
and-rewsmith Jan 7, 2020
2909c99
Merge branch 'master' into andsmi/e2e-tempfilter-enumerable
and-rewsmith Jan 7, 2020
26f8847
Merge branch 'master' into andsmi/e2e-tempfilter-enumerable
and-rewsmith Jan 7, 2020
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
14 changes: 9 additions & 5 deletions test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ public async Task<EdgeDeployment> DeployConfigurationAsync(Action<EdgeConfigBuil
addConfig(builder);

DateTime deployTime = DateTime.Now;
EdgeConfiguration config = builder.Build();
IEnumerable<EdgeConfiguration> configs = builder.BuildConfigurationStages();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think of this name change

foreach (EdgeConfiguration edgeConfiguration in configs)
{
await edgeConfiguration.DeployAsync(this.iotHub, token);
await Task.Delay(TimeSpan.FromSeconds(10));
}

await config.DeployAsync(this.iotHub, token);

IEnumerable<EdgeModule> modules = config.ModuleNames
// The last configuration will contain all modules including $edgeHub and $edgeAgent
List<EdgeModule> modules = configs.Last().ModuleNames
.Select(id => new EdgeModule(id, this.deviceId, this.iotHub))
.ToArray();
.ToList();
await EdgeModule.WaitForStatusAsync(modules, EdgeModuleStatus.Running, token);

return new EdgeDeployment(deployTime, modules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public IModuleConfigBuilder AddModule(string name, string image)
return builder;
}

public EdgeConfiguration Build()
/* Will output edgeHub and edgeAgent configurations, then a full configuration at the end.
This is done to assure routes are set up for the most recent $edgeHub deployment before the test modules start sending messages (i.e. assure messages won't get dropped).
Another way to handle this is to define all possible routes at the very beginning of the test, but there is added complexity as module names are assigned dynamically. */
public IEnumerable<EdgeConfiguration> BuildConfigurationStages()
{
// Build all modules *except* edge agent
List<ModuleConfiguration> modules = this.moduleBuilders
Expand All @@ -63,7 +66,7 @@ public EdgeConfiguration Build()
// Build edge agent
modules.Insert(0, this.BuildEdgeAgent(modules));

// Compose edge configuration
// Find the $edgeAgent and $edgeHub match, then immediately compose and return a configuration
var config = new ConfigurationContent
{
ModulesContent = new Dictionary<string, IDictionary<string, object>>()
Expand All @@ -72,21 +75,22 @@ public EdgeConfiguration Build()
var moduleNames = new List<string>();
var moduleImages = new List<string>();

foreach (ModuleConfiguration module in modules)
// Return a configuration for $edgeHub and $edgeAgent
foreach (ModuleConfiguration module in modules.Where(m => this.IsSystemModule(m)))
{
moduleNames.Add(module.Name);
moduleImages.Add(module.Image);
this.AddModuleToConfiguration(module, moduleNames, moduleImages, config);
}

if (module.DesiredProperties.Count != 0)
{
config.ModulesContent[module.Name] = new Dictionary<string, object>
{
["properties.desired"] = module.DesiredProperties
};
}
Dictionary<string, IDictionary<string, object>> copyModulesContent = config.ModulesContent.ToDictionary(entry => entry.Key, entry => entry.Value);
yield return new EdgeConfiguration(this.deviceId, new List<string>(moduleNames), new List<string>(moduleImages), new ConfigurationContent { ModulesContent = copyModulesContent });

// Return a configuration for other modules
foreach (ModuleConfiguration module in modules.Where(m => !this.IsSystemModule(m)))
{
this.AddModuleToConfiguration(module, moduleNames, moduleImages, config);
}

return new EdgeConfiguration(this.deviceId, moduleNames, moduleImages, config);
yield return new EdgeConfiguration(this.deviceId, moduleNames, moduleImages, config);
}

ModuleConfiguration BuildEdgeAgent(IEnumerable<ModuleConfiguration> configs)
Expand Down Expand Up @@ -167,6 +171,25 @@ ModuleConfiguration BuildEdgeAgent(IEnumerable<ModuleConfiguration> configs)
return agentBuilder.Build();
}

bool IsSystemModule(ModuleConfiguration module)
{
return module.Name.Equals("$edgeHub") || module.Name.Equals("$edgeAgent");
and-rewsmith marked this conversation as resolved.
Show resolved Hide resolved
}

void AddModuleToConfiguration(ModuleConfiguration module, List<string> moduleNames, List<string> moduleImages, ConfigurationContent config)
{
moduleNames.Add(module.Name);
moduleImages.Add(module.Image);

if (module.DesiredProperties.Count != 0)
{
config.ModulesContent[module.Name] = new Dictionary<string, object>
{
["properties.desired"] = module.DesiredProperties
};
}
}

public IModuleConfigBuilder GetModule(string name)
{
return this.moduleBuilders[name];
Expand Down