Specify credentials for multiple container registries in the tests (#1411)

* Specify credentials for multiple container registries in the tests
* Add test project back into SLN
This commit is contained in:
Damon Barry 2019-07-03 16:27:01 -07:00 коммит произвёл GitHub
Родитель 3ea68a91ae
Коммит 9704bb79d9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 58 добавлений и 33 удалений

Просмотреть файл

@ -175,8 +175,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2300ED4C-1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Test.Common", "test\Microsoft.Azure.Devices.Edge.Test.Common\Microsoft.Azure.Devices.Edge.Test.Common.csproj", "{950DACB0-B011-41AF-B0FB-245F749B01AB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Test.TempSensor", "test\Microsoft.Azure.Devices.Edge.Test.TempSensor\Microsoft.Azure.Devices.Edge.Test.TempSensor.csproj", "{FCF94FF4-A608-4CC1-8D1D-215B6F88F203}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Kubernetes", "edge-agent\src\Microsoft.Azure.Devices.Edge.Agent.Kubernetes\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.csproj", "{B63C506E-5CB5-4DE8-8275-F7BA8354799E}"
ProjectSection(ProjectDependencies) = postProject
{B0F37919-0D16-490F-B7A1-665BB93B9A62} = {B0F37919-0D16-490F-B7A1-665BB93B9A62}
@ -186,6 +184,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edg
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test", "edge-agent\test\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test\Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test.csproj", "{A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Devices.Edge.Test", "test\Microsoft.Azure.Devices.Edge.Test\Microsoft.Azure.Devices.Edge.Test.csproj", "{08986FED-9283-47F1-B938-86D9C6E753E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CheckInBuild|Any CPU = CheckInBuild|Any CPU
@ -586,6 +586,14 @@ Global
{A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE}.Release|Any CPU.Build.0 = Release|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.CheckInBuild|Any CPU.ActiveCfg = CheckInBuild|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.CheckInBuild|Any CPU.Build.0 = CheckInBuild|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.CodeCoverage|Any CPU.ActiveCfg = CodeCoverage|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.CodeCoverage|Any CPU.Build.0 = CodeCoverage|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08986FED-9283-47F1-B938-86D9C6E753E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -657,6 +665,7 @@ Global
{950DACB0-B011-41AF-B0FB-245F749B01AB} = {2300ED4C-1D5A-460F-8691-7C85E1162E0C}
{B63C506E-5CB5-4DE8-8275-F7BA8354799E} = {54351E51-19CB-4DE3-8302-99846AB216CF}
{A5DFFB52-D8EA-4E1A-BF4F-8B9665C7DAFE} = {F5E37327-3AA9-4CC2-9FE3-B28271ADB5E3}
{08986FED-9283-47F1-B938-86D9C6E753E1} = {2300ED4C-1D5A-460F-8691-7C85E1162E0C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D71830F5-3AF5-46B4-8A9E-1DCE4F2253AC}

Просмотреть файл

@ -9,18 +9,18 @@ namespace Microsoft.Azure.Devices.Edge.Test.Common.Config
{
readonly string deviceId;
readonly Dictionary<string, IModuleConfigBuilder> moduleBuilders;
Option<(string address, string username, string password)> registry;
readonly List<(string address, string username, string password)> registries;
public EdgeConfigBuilder(string deviceId)
{
this.deviceId = deviceId;
this.moduleBuilders = new Dictionary<string, IModuleConfigBuilder>();
this.registry = Option.None<(string, string, string)>();
this.registries = new List<(string, string, string)>();
}
public void AddRegistryCredentials(string address, string username, string password)
{
this.registry = Option.Some((address, username, password));
this.registries.Add((address, username, password));
}
public IModuleConfigBuilder AddEdgeAgent(string image = null)
@ -95,19 +95,22 @@ namespace Microsoft.Azure.Devices.Edge.Test.Common.Config
};
// Registry credentials under settings
this.registry.ForEach(
r =>
if (this.registries.Count != 0)
{
var credentials = new Dictionary<string, object>();
for (int i = 0; i < this.registries.Count; ++i)
{
settings["registryCredentials"] = new
(string address, string username, string password) = this.registries[i];
credentials.Add($"reg{i}", new
{
reg1 = new
{
r.username,
r.password,
r.address
}
};
});
username,
password,
address
});
}
settings["registryCredentials"] = credentials;
}
// Deployment info for edge agent
var systemModules = new Dictionary<string, object>()

Просмотреть файл

@ -2,7 +2,9 @@
namespace Microsoft.Azure.Devices.Edge.Test
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Microsoft.Azure.Devices.Edge.Util;
using Microsoft.Extensions.Configuration;
@ -21,25 +23,32 @@ namespace Microsoft.Azure.Devices.Edge.Test
string GetOrDefault(string name, string defaultValue) => context.GetValue(name, defaultValue);
Option<(string, string, string)> GetAndValidateRegistry()
IEnumerable<(string, string, string)> GetAndValidateRegistries()
{
// If any container registry arguments (server, username, password)
// are given, then they must *all* be given, otherwise throw an error.
string registry = Get("registry");
string username = Get("user");
string password = Get("CONTAINER_REGISTRY_PASSWORD");
var result = new List<(string, string, string)>();
if (!string.IsNullOrWhiteSpace(registry) ||
!string.IsNullOrWhiteSpace(username) ||
!string.IsNullOrWhiteSpace(password))
var registries = context.GetSection("registries").GetChildren().ToArray();
foreach (var reg in registries)
{
string registry = reg.GetValue<string>("address");
string username = reg.GetValue<string>("username");
// To specify a password as an environment variable instead of in the
// JSON file (so it's not stored in the clear on the filesystem), name
// the variable like this: E2E_REGISTRIES__<index>__PASSWORD, where
// <index> is the 0-based number corresponding to an element in the
// "registries" JSON array.
string password = reg.GetValue<string>("PASSWORD");
// If any container registry arguments (server, username, password)
// are given, then they must *all* be given, otherwise throw an error.
Preconditions.CheckNonWhiteSpace(registry, nameof(registry));
Preconditions.CheckNonWhiteSpace(username, nameof(username));
Preconditions.CheckNonWhiteSpace(password, nameof(password));
return Option.Some((registry, username, password));
result.Add((registry, username, password));
}
return Option.None<(string, string, string)>();
return result;
}
this.ConnectionString = Get("IOT_HUB_CONNECTION_STRING");
@ -48,7 +57,7 @@ namespace Microsoft.Azure.Devices.Edge.Test
this.InstallerPath = Option.Maybe(Get("installerPath"));
this.PackagePath = Option.Maybe(Get("packagePath"));
this.Proxy = Option.Maybe(context.GetValue<Uri>("proxy"));
this.Registry = GetAndValidateRegistry();
this.Registries = GetAndValidateRegistries();
this.EdgeAgentImage = Option.Maybe(Get("edgeAgentImage"));
this.EdgeHubImage = Option.Maybe(Get("edgeHubImage"));
this.TempSensorImage = Option.Maybe(Get("tempSensorImage"));
@ -78,7 +87,7 @@ namespace Microsoft.Azure.Devices.Edge.Test
public Option<Uri> Proxy { get; }
public Option<(string address, string username, string password)> Registry { get; }
public IEnumerable<(string address, string username, string password)> Registries { get; }
public Option<string> EdgeAgentImage { get; }

Просмотреть файл

@ -75,8 +75,10 @@ namespace Microsoft.Azure.Devices.Edge.Test
token)).Expect(() => new Exception("Device should have already been created in setup fixture"));
var builder = new EdgeConfigBuilder(device.Id);
Context.Current.Registry.ForEach(
r => builder.AddRegistryCredentials(r.address, r.username, r.password));
foreach ((string address, string username, string password) in Context.Current.Registries)
{
builder.AddRegistryCredentials(address, username, password);
}
builder.AddEdgeAgent(agentImage).WithProxy(proxy);
builder.AddEdgeHub(hubImage, optimizeForPerformance).WithProxy(proxy);
builder.AddModule("tempSensor", sensorImage);
@ -160,8 +162,10 @@ namespace Microsoft.Azure.Devices.Edge.Test
string clientTransport = protocol.ToTransportType().ToString();
var builder = new EdgeConfigBuilder(device.Id);
Context.Current.Registry.ForEach(
r => builder.AddRegistryCredentials(r.address, r.username, r.password));
foreach ((string address, string username, string password) in Context.Current.Registries)
{
builder.AddRegistryCredentials(address, username, password);
}
builder.AddEdgeAgent(agentImage).WithProxy(proxy);
builder.AddEdgeHub(hubImage, optimizeForPerformance).WithProxy(proxy);
builder.AddModule(methodSender, senderImage)