Skip to content

Commit

Permalink
Merged PR 928556: Update IotEdgeQuickstart smoke test
Browse files Browse the repository at this point in the history
- Get Resharper clean
- If the test fails, leave the bootstrapper config alone so it can be investigated; don't reset it
- In iotedgectl mode, don't throw when `docker ps` returns an empty result
- Default to mcr.microsoft.com (1.0) images instead of dockerhub (1.0-preview) if user doesn't pass `-t` option
- Add a workaround for using iotedgectl until Azure/iot-edge-v1#632 is fixed and released
  • Loading branch information
damonbarry committed Jun 28, 2018
1 parent cc7e142 commit 12bdbab
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
6 changes: 3 additions & 3 deletions smoke/IotEdgeQuickstart/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Option Default value
--eventhub-endpoint get the value from Key Vault
--leave-running none (or 'all' if given as a switch)
--password anonymous, or Key Vault if --registry is specified
--registry DockerHub (anonymous)
--tag '1.0-preview'
--registry mcr.microsoft.com (anonymous)
--tag '1.0'
--use-http if --bootstrapper=iotedged then use Unix Domain
Sockets, otherwise N/A
switch form uses local IP address as hostname
Expand Down Expand Up @@ -142,7 +142,7 @@ async Task<int> OnExecuteAsync()
string endpoint = this.EventHubCompatibleEndpointWithEntityPath ??
await SecretsHelper.GetSecretFromConfigKey("eventHubConnStrKey");

string tag = this.ImageTag ?? "1.0-preview";
string tag = this.ImageTag ?? "1.0";

var test = new Quickstart(
bootstrapper,
Expand Down
2 changes: 1 addition & 1 deletion smoke/IotEdgeQuickstart/Quickstart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public async Task RunAsync()
if (this.leaveRunning == LeaveRunning.None)
{
await StopBootstrapper();
await ResetBootstrapper();
}
}
finally
{
if (this.leaveRunning == LeaveRunning.None)
{
await this.ResetBootstrapper();
// only remove the identity if we created it; if it already existed in IoT Hub then leave it alone
await MaybeDeleteEdgeDeviceIdentity();
}
Expand Down
16 changes: 9 additions & 7 deletions smoke/IotEdgeQuickstart/details/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace IotEdgeQuickstart.Details
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -272,23 +271,23 @@ protected Task MaybeDeleteEdgeDeviceIdentity()

string EdgeAgentImage()
{
return this.BuildImageName("microsoft/azureiotedge-agent");
return this.BuildImageName("azureiotedge-agent");
}

string EdgeHubImage()
{
return this.BuildImageName("microsoft/azureiotedge-hub");
return this.BuildImageName("azureiotedge-hub");
}

string TempSensorImage()
{
return this.BuildImageName("microsoft/azureiotedge-simulated-temperature-sensor");
return this.BuildImageName("azureiotedge-simulated-temperature-sensor");
}

string BuildImageName(string name)
{
string registry = this.credentials.Match(c => $"{c.Address}/", () => string.Empty);
return $"{registry}{name}:{this.imageTag}";
string prefix = this.credentials.Match(c => $"{c.Address}/microsoft", () => "mcr.microsoft.com");
return $"{prefix}/{name}:{this.imageTag}";
}

(string, string[]) DeploymentJson()
Expand Down Expand Up @@ -317,6 +316,9 @@ string BuildImageName(string name)
return (deployJson, new [] { edgeAgentImage, edgeHubImage, tempSensorImage });
}

// TODO: Remove Env (SSL_CERTIFICATE_PATH and SSL_CERTIFICATE_NAME) from
// modulesContent.$edgeAgent.systemModules.edgeHub.settings.createOptions
// once Azure/iot-edge-v1#632 is fixed and available on mcr.microsoft.com
const string DeployJson = @"
{
""modulesContent"": {
Expand Down Expand Up @@ -344,7 +346,7 @@ string BuildImageName(string name)
""restartPolicy"": ""always"",
""settings"": {
""image"": ""<image-edge-hub>"",
""createOptions"": ""{\""HostConfig\"":{\""PortBindings\"":{\""8883/tcp\"":[{\""HostPort\"":\""8883\""}],\""443/tcp\"":[{\""HostPort\"":\""443\""}]}}}""
""createOptions"": ""{\""HostConfig\"":{\""PortBindings\"":{\""8883/tcp\"":[{\""HostPort\"":\""8883\""}],\""443/tcp\"":[{\""HostPort\"":\""443\""}]}},\""Env\"":[\""SSL_CERTIFICATE_PATH=/mnt/edgehub\"",\""SSL_CERTIFICATE_NAME=edge-hub-server.cert.pfx\""]}""
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions smoke/IotEdgeQuickstart/details/Iotedgectl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task VerifyModuleIsRunning(string name)
$"ps --quiet --filter \"name = {name}\"",
cts.Token);

if (status.First().Trim() != string.Empty) break;
if (!string.IsNullOrWhiteSpace(status.FirstOrDefault())) break;

errorMessage = "Not found";
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public Task Install()

public async Task Configure(string connectionString, string image, string hostname)
{
Console.WriteLine($"Setting up iotedgectl with container registry '{this.credentials.Match(c => c.Address, () => "<none>")}'");
Console.WriteLine($"Setting up iotedgectl with agent image '{image}'");

string registryArgs = this.credentials.Match(
c => $"--docker-registries {c.Address} {c.User} {c.Password}",
Expand Down
61 changes: 29 additions & 32 deletions smoke/IotEdgeQuickstart/details/Iotedged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
namespace IotEdgeQuickstart.Details
{
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Util;

public class HttpUris
{
const int managementPort = 15580;
const int workloadPort = 15581;
const int ManagementPort = 15580;
const int WorkloadPort = 15581;

public string ConnectManagement { get; }
public string ConnectWorkload { get; }
Expand All @@ -27,10 +25,10 @@ public HttpUris() : this(GetIpAddress()) {}

public HttpUris(string hostname)
{
this.ConnectManagement = $"http://{hostname}:{managementPort}";
this.ConnectWorkload = $"http://{hostname}:{workloadPort}";
this.ListenManagement = $"http://0.0.0.0:{managementPort}";
this.ListenWorkload = $"http://0.0.0.0:{workloadPort}";
this.ConnectManagement = $"http://{hostname}:{ManagementPort}";
this.ConnectWorkload = $"http://{hostname}:{WorkloadPort}";
this.ListenManagement = $"http://0.0.0.0:{ManagementPort}";
this.ListenWorkload = $"http://0.0.0.0:{WorkloadPort}";
}

static string GetIpAddress()
Expand All @@ -39,20 +37,20 @@ static string GetIpAddress()
// of the public-facing address. The output of this command would be
// a good candidate:
// docker network inspect --format='{{(index .IPAM.Config 0).Gateway}}' bridge
const string server = "microsoft.com";
const int port = 443;
const string Server = "microsoft.com";
const int Port = 443;

IPHostEntry entry = Dns.GetHostEntry(server);
IPHostEntry entry = Dns.GetHostEntry(Server);

foreach (IPAddress address in entry.AddressList)
{
IPEndPoint endpoint = new IPEndPoint(address, port);
using (Socket s = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
var endpoint = new IPEndPoint(address, Port);
using (var s = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
s.Connect(endpoint);
if (s.Connected)
{
return (s.LocalEndPoint as IPEndPoint).Address.ToString();
return (s.LocalEndPoint as IPEndPoint)?.Address.ToString();
}
}
}
Expand Down Expand Up @@ -104,7 +102,7 @@ public async Task VerifyModuleIsRunning(string name)
$"{options}list",
cts.Token);

var status = result
string status = result
.Where(ln => ln.Split(null as char[], StringSplitOptions.RemoveEmptyEntries).First() == name)
.DefaultIfEmpty("name status")
.Single()
Expand Down Expand Up @@ -141,7 +139,7 @@ public Task Install()

public async Task Configure(string connectionString, string image, string hostname)
{
Console.WriteLine($"Setting up iotedged with container registry '{this.credentials.Match(c => c.Address, () => "<none>")}'");
Console.WriteLine($"Setting up iotedged with agent image '{image}'");

const string YamlPath = "/etc/iotedge/config.yaml";
Task<string> text = File.ReadAllTextAsync(YamlPath);
Expand All @@ -158,22 +156,21 @@ public async Task Configure(string connectionString, string image, string hostna
doc.Replace("agent.config.auth.password", c.Password);
}

this.httpUris.Match<int>(
some: uris => {
doc.Replace("connect.management_uri", uris.ConnectManagement);
doc.Replace("connect.workload_uri", uris.ConnectWorkload);
doc.Replace("listen.management_uri", uris.ListenManagement);
doc.Replace("listen.workload_uri", uris.ListenWorkload);
return 0;
},
none: () => {
doc.Replace("connect.management_uri", "unix:///var/run/iotedge/mgmt.sock");
doc.Replace("connect.workload_uri", "unix:///var/run/iotedge/workload.sock");
doc.Replace("listen.management_uri", "fd://iotedge.mgmt.socket");
doc.Replace("listen.workload_uri", "fd://iotedge.socket");
return 0;
}
);
if (this.httpUris.HasValue)
{
HttpUris uris = this.httpUris.OrDefault();
doc.Replace("connect.management_uri", uris.ConnectManagement);
doc.Replace("connect.workload_uri", uris.ConnectWorkload);
doc.Replace("listen.management_uri", uris.ListenManagement);
doc.Replace("listen.workload_uri", uris.ListenWorkload);
}
else
{
doc.Replace("connect.management_uri", "unix:///var/run/iotedge/mgmt.sock");
doc.Replace("connect.workload_uri", "unix:///var/run/iotedge/workload.sock");
doc.Replace("listen.management_uri", "fd://iotedge.mgmt.socket");
doc.Replace("listen.workload_uri", "fd://iotedge.socket");
}

string result = doc.ToString();

Expand Down
2 changes: 2 additions & 0 deletions smoke/docker/linux/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ RUN apt-get update && \
apt-get --yes --no-install-recommends install \
# .NET Core dependencies, see https://github.com/dotnet/dotnet-docker/blob/d5c80ab/2.1/runtime-deps/bionic/amd64/Dockerfile
libc6 libgcc1 libgssapi-krb5-2 libicu60 liblttng-ust0 libssl1.0.0 libstdc++6 zlib1g \
# Used when adding Microsoft's repository to the Apt sources list (when installing iotedged)
curl \
# Needed to install iotedged
ca-certificates \
# Needed to get the IP address used for iotedged's management endpoint
Expand Down

0 comments on commit 12bdbab

Please sign in to comment.