Restores automatic log download on test failure
This commit is contained in:
parent
7eab4840ef
commit
31e034ab67
|
@ -7,15 +7,6 @@ namespace CodexDistTestCore
|
||||||
void Log(Stream log);
|
void Log(Stream log);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
|
||||||
public class DontDownloadLogsAndMetricsOnFailureAttribute : PropertyAttribute
|
|
||||||
{
|
|
||||||
public DontDownloadLogsAndMetricsOnFailureAttribute()
|
|
||||||
: base(Timing.UseLongTimeoutsKey)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PodLogDownloader
|
public class PodLogDownloader
|
||||||
{
|
{
|
||||||
public const string DontDownloadLogsOnFailureKey = "DontDownloadLogsOnFailure";
|
public const string DontDownloadLogsOnFailureKey = "DontDownloadLogsOnFailure";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using Logging;
|
using Logging;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DistTestCore.CodexLogs
|
namespace DistTestCore.CodexLogsAndMetrics
|
||||||
{
|
{
|
||||||
public interface ICodexNodeLog
|
public interface ICodexNodeLog
|
||||||
{
|
{
|
|
@ -0,0 +1,15 @@
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DistTestCore.CodexLogsAndMetrics
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||||
|
public class DontDownloadLogsAndMetricsOnFailureAttribute : PropertyAttribute
|
||||||
|
{
|
||||||
|
public const string DontDownloadKey = "DontDownloadLogsAndMetrics";
|
||||||
|
|
||||||
|
public DontDownloadLogsAndMetricsOnFailureAttribute()
|
||||||
|
: base(DontDownloadKey)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using KubernetesWorkflow;
|
using KubernetesWorkflow;
|
||||||
using Logging;
|
using Logging;
|
||||||
|
|
||||||
namespace DistTestCore.CodexLogs
|
namespace DistTestCore.CodexLogsAndMetrics
|
||||||
{
|
{
|
||||||
public class LogDownloadHandler : ILogHandler
|
public class LogDownloadHandler : ILogHandler
|
||||||
{
|
{
|
|
@ -32,15 +32,14 @@ namespace DistTestCore
|
||||||
|
|
||||||
public ICodexSetup BringOffline()
|
public ICodexSetup BringOffline()
|
||||||
{
|
{
|
||||||
var result = Setup;
|
lifecycle.CodexStarter.BringOffline(this);
|
||||||
var containers = Containers;
|
|
||||||
|
|
||||||
|
var result = Setup;
|
||||||
// Clear everything. Prevent accidental use.
|
// Clear everything. Prevent accidental use.
|
||||||
Setup = null!;
|
Setup = null!;
|
||||||
Containers = null!;
|
|
||||||
Nodes = Array.Empty<OnlineCodexNode>();
|
Nodes = Array.Empty<OnlineCodexNode>();
|
||||||
|
Containers = null!;
|
||||||
|
|
||||||
lifecycle.CodexStarter.BringOffline(containers);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using DistTestCore.Codex;
|
using DistTestCore.Codex;
|
||||||
using DistTestCore.CodexLogs;
|
|
||||||
using KubernetesWorkflow;
|
using KubernetesWorkflow;
|
||||||
using Nethereum.Merkle.Patricia;
|
|
||||||
|
|
||||||
namespace DistTestCore
|
namespace DistTestCore
|
||||||
{
|
{
|
||||||
|
@ -16,27 +14,40 @@ namespace DistTestCore
|
||||||
this.lifecycle = lifecycle;
|
this.lifecycle = lifecycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<CodexNodeGroup> RunningGroups { get; } = new List<CodexNodeGroup>();
|
||||||
|
|
||||||
public ICodexNodeGroup BringOnline(CodexSetup codexSetup)
|
public ICodexNodeGroup BringOnline(CodexSetup codexSetup)
|
||||||
{
|
{
|
||||||
|
Log($"Starting {codexSetup.Describe()}...");
|
||||||
|
|
||||||
var workflow = CreateWorkflow();
|
var workflow = CreateWorkflow();
|
||||||
var startupConfig = new StartupConfig();
|
var startupConfig = new StartupConfig();
|
||||||
startupConfig.Add(codexSetup);
|
startupConfig.Add(codexSetup);
|
||||||
|
|
||||||
var runningContainers = workflow.Start(codexSetup.NumberOfNodes, codexSetup.Location, new CodexContainerRecipe(), startupConfig);
|
var runningContainers = workflow.Start(codexSetup.NumberOfNodes, codexSetup.Location, new CodexContainerRecipe(), startupConfig);
|
||||||
|
|
||||||
return new CodexNodeGroup(lifecycle, codexSetup, runningContainers);
|
var group = new CodexNodeGroup(lifecycle, codexSetup, runningContainers);
|
||||||
|
RunningGroups.Add(group);
|
||||||
|
|
||||||
|
Log($"Started at '{group.Containers.RunningPod.Ip}'");
|
||||||
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BringOffline(RunningContainers runningContainers)
|
public void BringOffline(CodexNodeGroup group)
|
||||||
{
|
{
|
||||||
|
Log($"Stopping {group.Describe()}...");
|
||||||
var workflow = CreateWorkflow();
|
var workflow = CreateWorkflow();
|
||||||
workflow.Stop(runningContainers);
|
workflow.Stop(group.Containers);
|
||||||
|
RunningGroups.Remove(group);
|
||||||
|
Log("Stopped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteAllResources()
|
public void DeleteAllResources()
|
||||||
{
|
{
|
||||||
var workflow = CreateWorkflow();
|
var workflow = CreateWorkflow();
|
||||||
workflow.DeleteAllResources();
|
workflow.DeleteAllResources();
|
||||||
|
|
||||||
|
RunningGroups.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DownloadLog(RunningContainer container, ILogHandler logHandler)
|
public void DownloadLog(RunningContainer container, ILogHandler logHandler)
|
||||||
|
@ -49,5 +60,10 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
return workflowCreator.CreateWorkflow();
|
return workflowCreator.CreateWorkflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Log(string msg)
|
||||||
|
{
|
||||||
|
lifecycle.Log.Log(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using NUnit.Framework;
|
using DistTestCore.CodexLogsAndMetrics;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DistTestCore
|
namespace DistTestCore
|
||||||
{
|
{
|
||||||
|
@ -68,20 +69,20 @@ namespace DistTestCore
|
||||||
|
|
||||||
private void IncludeLogsAndMetricsOnTestFailure()
|
private void IncludeLogsAndMetricsOnTestFailure()
|
||||||
{
|
{
|
||||||
//var result = TestContext.CurrentContext.Result;
|
var result = TestContext.CurrentContext.Result;
|
||||||
//if (result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed)
|
if (result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed)
|
||||||
//{
|
{
|
||||||
// if (IsDownloadingLogsAndMetricsEnabled())
|
if (IsDownloadingLogsAndMetricsEnabled())
|
||||||
// {
|
{
|
||||||
// log.Log("Downloading all CodexNode logs and metrics because of test failure...");
|
Log("Downloading all CodexNode logs and metrics because of test failure...");
|
||||||
// k8sManager.ForEachOnlineGroup(DownloadLogs);
|
DownloadAllLogs();
|
||||||
// k8sManager.DownloadAllMetrics();
|
//k8sManager.DownloadAllMetrics();
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// log.Log("Skipping download of all CodexNode logs and metrics due to [DontDownloadLogsAndMetricsOnFailure] attribute.");
|
Log("Skipping download of all CodexNode logs and metrics due to [DontDownloadLogsAndMetricsOnFailure] attribute.");
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Log(string msg)
|
private void Log(string msg)
|
||||||
|
@ -99,21 +100,20 @@ namespace DistTestCore
|
||||||
lifecycle = new TestLifecycle(new Configuration());
|
lifecycle = new TestLifecycle(new Configuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DownloadLogs(CodexNodeGroup group)
|
private void DownloadAllLogs()
|
||||||
{
|
{
|
||||||
//foreach (var node in group)
|
var allNodes = lifecycle.CodexStarter.RunningGroups.SelectMany(g => g.Nodes);
|
||||||
//{
|
foreach (var node in allNodes)
|
||||||
// var downloader = new PodLogDownloader(log, k8sManager);
|
{
|
||||||
// var n = (OnlineCodexNode)node;
|
lifecycle.DownloadLog(node);
|
||||||
// downloader.DownloadLog(n);
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//private bool IsDownloadingLogsAndMetricsEnabled()
|
private bool IsDownloadingLogsAndMetricsEnabled()
|
||||||
//{
|
{
|
||||||
// var testProperties = TestContext.CurrentContext.Test.Properties;
|
var testProperties = TestContext.CurrentContext.Test.Properties;
|
||||||
// return !testProperties.ContainsKey(PodLogDownloader.DontDownloadLogsOnFailureKey);
|
return !testProperties.ContainsKey(DontDownloadLogsAndMetricsOnFailureAttribute.DontDownloadKey);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GlobalTestFailure
|
public static class GlobalTestFailure
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using DistTestCore.Codex;
|
using DistTestCore.Codex;
|
||||||
using DistTestCore.CodexLogs;
|
using DistTestCore.CodexLogsAndMetrics;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DistTestCore
|
namespace DistTestCore
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using DistTestCore.CodexLogs;
|
using DistTestCore.CodexLogsAndMetrics;
|
||||||
using Logging;
|
using Logging;
|
||||||
|
|
||||||
namespace DistTestCore
|
namespace DistTestCore
|
||||||
|
@ -28,6 +28,7 @@ namespace DistTestCore
|
||||||
var description = node.Describe();
|
var description = node.Describe();
|
||||||
var handler = new LogDownloadHandler(description, subFile);
|
var handler = new LogDownloadHandler(description, subFile);
|
||||||
|
|
||||||
|
Log.Log($"Downloading logs for {description} to file {subFile.FilenameWithoutPath}");
|
||||||
CodexStarter.DownloadLog(node.CodexAccess.Container, handler);
|
CodexStarter.DownloadLog(node.CodexAccess.Container, handler);
|
||||||
|
|
||||||
return new CodexNodeLog(subFile);
|
return new CodexNodeLog(subFile);
|
||||||
|
|
Loading…
Reference in New Issue