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

74 lines
2.2 KiB
C#
Raw Normal View History

2023-09-20 11:33:58 +00:00
using KubernetesWorkflow;
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;
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();
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-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
{
2023-09-20 11:33:58 +00:00
entryPoint.Tools.CreateWorkflow().DeleteNamespace();
}
}
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);
}
}
}