2023-09-20 11:33:58 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Logging;
|
2023-06-28 10:01:20 +00:00
|
|
|
|
using Utils;
|
2023-09-20 11:33:58 +00:00
|
|
|
|
using Core;
|
|
|
|
|
using CodexPlugin;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
|
|
|
|
namespace ContinuousTests
|
|
|
|
|
{
|
|
|
|
|
public class NodeRunner
|
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
private readonly EntryPointFactory entryPointFactory = new EntryPointFactory();
|
|
|
|
|
private readonly ICodexNode[] nodes;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
private readonly Configuration config;
|
2023-09-20 11:33:58 +00:00
|
|
|
|
private readonly ILog log;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
private readonly string customNamespace;
|
|
|
|
|
|
2023-09-20 11:33:58 +00:00
|
|
|
|
public NodeRunner(ICodexNode[] nodes, Configuration config, ILog log, string customNamespace)
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-06-28 10:01:20 +00:00
|
|
|
|
this.nodes = nodes;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
this.config = config;
|
|
|
|
|
this.log = log;
|
|
|
|
|
this.customNamespace = customNamespace;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 11:33:58 +00:00
|
|
|
|
public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
|
2023-06-28 10:01:20 +00:00
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
var entryPoint = CreateEntryPoint();
|
|
|
|
|
return entryPoint.CreateInterface().DownloadLog(container, tailLines);
|
2023-06-28 10:01:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 11:33:58 +00:00
|
|
|
|
public void RunNode(Action<ICodexSetup> setup, Action<ICodexNode> operation)
|
2023-08-18 08:31:20 +00:00
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
RunNode(nodes.ToList().PickOneRandom(), setup, operation);
|
2023-08-18 08:31:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 11:33:58 +00:00
|
|
|
|
public void RunNode(ICodexNode bootstrapNode, Action<ICodexSetup> setup, Action<ICodexNode> operation)
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
var entryPoint = CreateEntryPoint();
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var debugInfo = bootstrapNode.GetDebugInfo();
|
|
|
|
|
Assert.That(!string.IsNullOrEmpty(debugInfo.spr));
|
|
|
|
|
|
2023-09-20 11:33:58 +00:00
|
|
|
|
var node = entryPoint.CreateInterface().StartCodexNode(s =>
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
setup(s);
|
|
|
|
|
s.WithBootstrapNode(bootstrapNode);
|
|
|
|
|
});
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
2023-06-29 14:03:45 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
operation(node);
|
2023-06-29 14:03:45 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
DownloadLog(node.Container);
|
2023-06-29 14:03:45 +00:00
|
|
|
|
throw;
|
|
|
|
|
}
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
entryPoint.Tools.CreateWorkflow().DeleteNamespace();
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 11:33:58 +00:00
|
|
|
|
private EntryPoint CreateEntryPoint()
|
2023-06-28 09:48:05 +00:00
|
|
|
|
{
|
2023-09-20 11:33:58 +00:00
|
|
|
|
return entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, customNamespace, log);
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|