protected async Task AfterEachTestAsync() { this.profiler.Stop("Completed test '{Name}'", TestContext.CurrentContext.Test.Name); await Profiler.Run( async() => { this.cts.Dispose(); if ((!Context.Current.ISA95Tag) && (TestContext.CurrentContext.Result.Outcome != ResultState.Ignored)) { using var cts = new CancellationTokenSource(Context.Current.TeardownTimeout); await NUnitLogs.CollectAsync(this.testStartTime, cts.Token); if (Context.Current.GetSupportBundle) { try { var supportBundlePath = Context.Current.LogFile.Match((file) => Path.GetDirectoryName(file), () => AppDomain.CurrentDomain.BaseDirectory); await Process.RunAsync( "iotedge", $"support-bundle -o {supportBundlePath}/supportbundle-{TestContext.CurrentContext.Test.Name} --since \"{this.testStartTime:yyyy-MM-ddTHH:mm:ssZ}\"", cts.Token); } catch (Exception ex) { Log.Error($"Failed to Get Support Bundle Log with Error:{ex}"); } } } }, "Completed test teardown"); await this.AfterTestTimerEnds(); }
public async Task ManuallyProvisionEdgeAsync() { await Profiler.Run( async() => { using (var cts = new CancellationTokenSource(Context.Current.SetupTimeout)) { // NUnit's [Timeout] attribute isn't supported in .NET Standard // and even if it were, it doesn't run the teardown method when // a test times out. We need teardown to run, to remove the // device registration from IoT Hub and stop the daemon. So // we have our own timeout mechanism. DateTime startTime = DateTime.Now; CancellationToken token = cts.Token; EdgeDevice device = await EdgeDevice.GetOrCreateIdentityAsync( Context.Current.DeviceId, this.iotHub, token); Context.Current.DeleteList.TryAdd(device.Id, device); IotHubConnectionStringBuilder builder = IotHubConnectionStringBuilder.Create(device.ConnectionString); await this.daemon.ConfigureAsync( config => { config.SetDeviceConnectionString(device.ConnectionString); config.Update(); return(Task.FromResult(( "with connection string for device '{Identity}'", new object[] { builder.DeviceId }))); }, token); try { await this.daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token); var agent = new EdgeAgent(device.Id, this.iotHub); await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token); await agent.PingAsync(token); } // ReSharper disable once RedundantCatchClause catch { throw; } finally { await NUnitLogs.CollectAsync(startTime, token); } } }, "Completed edge manual provisioning"); }
public async Task SetUpCertificatesAsync() { await Profiler.Run( () => this.SasProvisionEdgeAsync(), "Completed edge manual provisioning with SAS token"); await Profiler.Run( async() => { (string, string, string)rootCa = Context.Current.RootCaKeys.Expect(() => new InvalidOperationException("Missing root CA keys")); string caCertScriptPath = Context.Current.CaCertScriptPath.Expect(() => new InvalidOperationException("Missing CA cert script path")); using (var cts = new CancellationTokenSource(Context.Current.SetupTimeout)) { DateTime startTime = DateTime.Now; CancellationToken token = cts.Token; string deviceId = this.runtime.DeviceId; try { this.ca = await CertificateAuthority.CreateAsync( deviceId, rootCa, caCertScriptPath, token); CaCertificates caCert = await this.ca.GenerateCaCertificatesAsync(deviceId, token); this.ca.EdgeCertificates = caCert; await this.daemon.ConfigureAsync( config => { config.SetCertificates(caCert); config.Update(); return(Task.FromResult(("with edge certificates", Array.Empty <object>()))); }, token); await this.runtime.DeployConfigurationAsync(token); } // ReSharper disable once RedundantCatchClause catch { throw; } finally { await NUnitLogs.CollectAsync(startTime, token); } } }, "Completed custom certificate setup"); }
protected async Task AfterEachTestAsync() { this.profiler.Stop("Completed test '{Name}'", TestContext.CurrentContext.Test.Name); await Profiler.Run( async() => { this.cts.Dispose(); if (TestContext.CurrentContext.Result.Outcome != ResultState.Ignored) { using var cts = new CancellationTokenSource(Context.Current.TeardownTimeout); await NUnitLogs.CollectAsync(this.testStartTime, cts.Token); } }, "Completed test teardown"); }
private async Task WaitForConfiguredStatusAsync(EdgeDevice device, DateTime startTime, CancellationToken token) { try { await this.daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token); var agent = new EdgeAgent(device.Id, this.iotHub); await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token); await agent.PingAsync(token); } // ReSharper disable once RedundantCatchClause catch { throw; } finally { await NUnitLogs.CollectAsync(startTime, token); } }
public async Task BeforeAllAsync() { await Profiler.Run( async() => { (string, string, string)rootCa = Context.Current.RootCaKeys.Expect(() => new ArgumentException()); Option <Uri> proxy = Context.Current.Proxy; string deviceId = Context.Current.DeviceId; using (var cts = new CancellationTokenSource(Context.Current.SetupTimeout)) { DateTime startTime = DateTime.Now; CancellationToken token = cts.Token; this.iotHub = new IotHub( Context.Current.ConnectionString, Context.Current.EventHubEndpoint, proxy); try { this.ca = await CertificateAuthority.CreateAsync( deviceId, rootCa, Context.Current.CaCertScriptPath, token); this.daemon = OsPlatform.Current.CreateEdgeDaemon(Context.Current.InstallerPath); await this.daemon.ConfigureAsync( config => { config.SetCertificates(this.ca.Certificates); config.Update(); return(Task.FromResult(("with edge certificates", Array.Empty <object>()))); }, token); var runtime = new EdgeRuntime( deviceId, Context.Current.EdgeAgentImage, Context.Current.EdgeHubImage, proxy, Context.Current.Registries, Context.Current.OptimizeForPerformance, this.iotHub); await runtime.DeployConfigurationAsync(token); } // ReSharper disable once RedundantCatchClause catch { throw; } finally { await NUnitLogs.CollectAsync(startTime, token); } } }, "Completed custom certificate setup"); }