2023-11-12 09:07:23 +00:00
|
|
|
|
using NUnit.Framework;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
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-11-12 09:07:23 +00:00
|
|
|
|
using KubernetesWorkflow.Types;
|
2024-08-01 08:39:06 +00:00
|
|
|
|
using KubernetesWorkflow;
|
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-09-29 08:19:59 +00:00
|
|
|
|
// We have to be sure that the transient node we start is using the same image as whatever's already in the deployed network.
|
|
|
|
|
// Therefore, we use the image of the bootstrap node.
|
|
|
|
|
CodexContainerRecipe.DockerImageOverride = bootstrapNode.Container.Recipe.Image;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var debugInfo = bootstrapNode.GetDebugInfo();
|
2024-04-01 06:29:55 +00:00
|
|
|
|
Assert.That(!string.IsNullOrEmpty(debugInfo.Spr));
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
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
|
|
|
|
|
{
|
2024-06-06 13:09:52 +00:00
|
|
|
|
entryPoint.Tools.CreateWorkflow().DeleteNamespace(wait: false);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|