cs-codex-dist-tests/Tests/CodexContinuousTests/NodeRunner.cs

77 lines
2.5 KiB
C#
Raw Normal View History

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;
using KubernetesWorkflow.Types;
namespace ContinuousTests
{
public class NodeRunner
{
2023-09-20 11:33:58 +00:00
private readonly EntryPointFactory entryPointFactory = new EntryPointFactory();
private readonly ICodexNode[] nodes;
private readonly Configuration config;
2023-09-20 11:33:58 +00:00
private readonly ILog log;
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 10:01:20 +00:00
this.nodes = nodes;
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-09-20 11:33:58 +00:00
RunNode(nodes.ToList().PickOneRandom(), setup, operation);
}
2023-09-20 11:33:58 +00:00
public void RunNode(ICodexNode bootstrapNode, Action<ICodexSetup> setup, Action<ICodexNode> operation)
{
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;
try
{
var debugInfo = bootstrapNode.GetDebugInfo();
2024-04-01 06:29:55 +00:00
Assert.That(!string.IsNullOrEmpty(debugInfo.Spr));
2023-09-20 11:33:58 +00:00
var node = entryPoint.CreateInterface().StartCodexNode(s =>
{
2023-09-20 11:33:58 +00:00
setup(s);
s.WithBootstrapNode(bootstrapNode);
});
try
{
2023-09-20 11:33:58 +00:00
operation(node);
}
catch
{
2023-09-20 11:33:58 +00:00
DownloadLog(node.Container);
throw;
}
}
finally
{
entryPoint.Tools.CreateWorkflow().DeleteNamespace(wait: false);
}
}
2023-09-20 11:33:58 +00:00
private EntryPoint CreateEntryPoint()
{
2023-09-20 11:33:58 +00:00
return entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, customNamespace, log);
}
}
}