Skip to content

Commit

Permalink
Fix for Windows E2E tests (#531)
Browse files Browse the repository at this point in the history
explicitly add IOTEDGE_HOST environment variable in current session; in order to avoid hyper error when running "iotedge list" in e2e tests; and handle runtime log level in iotedgedWindows.cs.
  • Loading branch information
philipktlin authored Nov 13, 2018
1 parent 5547161 commit c71ef72
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions edge-modules/DirectMethodSender/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static async Task<int> MainAsync()

(CancellationTokenSource cts, ManualResetEventSlim completed, Option<object> handler)
= ShutdownHandler.Init(TimeSpan.FromSeconds(5), null);
Console.WriteLine($"Target device Id = [{targetDeviceId}], Target module Id = [{targetModuleId}]");
await CallDirectMethod(moduleClient, dmDelay, targetDeviceId, targetModuleId, cts).ConfigureAwait(false);
await moduleClient.CloseAsync();
completed.Set();
Expand Down
6 changes: 5 additions & 1 deletion smoke/IotEdgeQuickstart/details/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ string BuildImageName(string name)
string edgeHubImage = this.EdgeHubImage();
string tempSensorImage = this.TempSensorImage();
string deployJson = this.DeploymentFileName.Match(
f => JObject.Parse(File.ReadAllText(f)).ToString(),
f =>
{
Console.WriteLine($"Deployment file used: {f}");
return JObject.Parse(File.ReadAllText(f)).ToString();
},
() => {
string deployJsonRegistry = this.credentials.Match(
c =>
Expand Down
46 changes: 45 additions & 1 deletion smoke/IotEdgeQuickstart/details/IotedgedWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ namespace IotEdgeQuickstart.Details
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Util;

class IotedgedWindows : IBootstrapper
{
const string ConfigYamlFile = @"C:\ProgramData\iotedge\config.yaml";

readonly string archivePath;
readonly Option<RegistryCredentials> credentials;
readonly Option<string> proxy;
Expand Down Expand Up @@ -130,12 +133,50 @@ await Process.RunAsync("powershell",
}

// note: ignore hostname for now

Console.WriteLine($"Run command to configure: {args}");
string[] result = await Process.RunAsync("powershell", args, cts.Token);
WriteToConsole("Output from Configure iotedge windows service", result);

UpdateConfigYamlFile(runtimeLogLevel);

// Explicitly set IOTEDGE_HOST environment variable to current process
SetEnvironmentVariable();
}
}

static void UpdateConfigYamlFile(LogLevel runtimeLogLevel)
{
string config = File.ReadAllText(ConfigYamlFile);
var doc = new YamlDocument(config);
doc.ReplaceOrAdd("agent.env.RuntimeLogLevel", runtimeLogLevel.ToString());

FileAttributes attr = 0;
attr = File.GetAttributes(ConfigYamlFile);
File.SetAttributes(ConfigYamlFile, attr & ~FileAttributes.ReadOnly);

File.WriteAllText(ConfigYamlFile, doc.ToString());

if (attr != 0)
{
File.SetAttributes(ConfigYamlFile, attr);
}
}

static void SetEnvironmentVariable()
{
string config = File.ReadAllText(ConfigYamlFile);
var managementUriRegex = new Regex(@"connect:\s*management_uri:\s*""(.*)""");
Match result = managementUriRegex.Match(config);

if (result.Groups.Count != 2)
{
throw new Exception("can't find management Uri in config file.");
}

Console.WriteLine($"Explicitly set environment variable [IOTEDGE_HOST={result.Groups[1].Value}]");
Environment.SetEnvironmentVariable("IOTEDGE_HOST", result.Groups[1].Value);
}

public Task Start()
{
Console.WriteLine("Starting up iotedge service on Windows");
Expand Down Expand Up @@ -163,7 +204,10 @@ public Task Start()
throw new Exception($"Error starting iotedged: {e}");
}

// Add delay to ensure iotedge service is completely started up.
Task.Delay(new TimeSpan(0, 0, 0, 5));
Console.WriteLine("iotedge service started on Windows");

return Task.CompletedTask;
}

Expand Down

0 comments on commit c71ef72

Please sign in to comment.