2023-09-12 13:32:06 +02:00
|
|
|
|
using Core;
|
2023-09-13 10:03:11 +02:00
|
|
|
|
using FileUtils;
|
2023-09-13 15:10:19 +02:00
|
|
|
|
using KubernetesWorkflow;
|
2023-04-13 11:30:19 +02:00
|
|
|
|
using Logging;
|
2023-05-03 14:55:26 +02:00
|
|
|
|
using Utils;
|
2023-04-12 13:53:55 +02:00
|
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
|
{
|
2023-09-13 15:10:19 +02:00
|
|
|
|
public class TestLifecycle : IK8sHooks
|
2023-04-12 13:53:55 +02:00
|
|
|
|
{
|
2023-07-31 11:51:29 +02:00
|
|
|
|
private readonly DateTime testStart;
|
2023-09-13 10:03:11 +02:00
|
|
|
|
private readonly EntryPoint entryPoint;
|
2023-09-13 15:10:19 +02:00
|
|
|
|
private readonly List<RunningContainers> runningContainers = new List<RunningContainers>();
|
2023-04-13 14:36:17 +02:00
|
|
|
|
|
2023-09-12 10:31:55 +02:00
|
|
|
|
public TestLifecycle(TestLog log, Configuration configuration, ITimeSet timeSet, string testNamespace)
|
2023-04-12 13:53:55 +02:00
|
|
|
|
{
|
2023-04-14 14:53:39 +02:00
|
|
|
|
Log = log;
|
2023-06-01 09:35:18 +02:00
|
|
|
|
Configuration = configuration;
|
2023-05-04 08:55:20 +02:00
|
|
|
|
TimeSet = timeSet;
|
2023-05-03 14:55:26 +02:00
|
|
|
|
testStart = DateTime.UtcNow;
|
2023-07-18 14:26:21 +02:00
|
|
|
|
|
2023-09-13 15:10:19 +02:00
|
|
|
|
entryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(timeSet, this, testNamespace), configuration.GetFileManagerFolder(), timeSet);
|
2023-09-13 10:03:11 +02:00
|
|
|
|
CoreInterface = entryPoint.CreateInterface();
|
2023-09-11 16:57:57 +02:00
|
|
|
|
|
2023-09-12 10:31:55 +02:00
|
|
|
|
log.WriteLogTag();
|
2023-04-12 16:06:04 +02:00
|
|
|
|
}
|
2023-04-12 13:53:55 +02:00
|
|
|
|
|
2023-09-12 10:31:55 +02:00
|
|
|
|
public TestLog Log { get; }
|
2023-06-01 09:35:18 +02:00
|
|
|
|
public Configuration Configuration { get; }
|
2023-05-04 08:55:20 +02:00
|
|
|
|
public ITimeSet TimeSet { get; }
|
2023-09-13 08:55:04 +02:00
|
|
|
|
public CoreInterface CoreInterface { get; }
|
2023-09-12 10:31:55 +02:00
|
|
|
|
|
|
|
|
|
|
public void DeleteAllResources()
|
|
|
|
|
|
{
|
2023-09-13 10:03:11 +02:00
|
|
|
|
entryPoint.Tools.CreateWorkflow().DeleteNamespace();
|
|
|
|
|
|
entryPoint.Tools.GetFileManager().DeleteAllFiles();
|
|
|
|
|
|
entryPoint.Decommission();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TrackedFile GenerateTestFile(ByteSize size, string label = "")
|
|
|
|
|
|
{
|
|
|
|
|
|
return entryPoint.Tools.GetFileManager().GenerateFile(size, label);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 14:24:43 +02:00
|
|
|
|
public IFileManager GetFileManager()
|
2023-09-13 10:03:11 +02:00
|
|
|
|
{
|
2023-09-13 14:24:43 +02:00
|
|
|
|
return entryPoint.Tools.GetFileManager();
|
2023-05-03 14:55:26 +02:00
|
|
|
|
}
|
2023-07-31 11:51:29 +02:00
|
|
|
|
|
2023-09-12 10:31:55 +02:00
|
|
|
|
public string GetTestDuration()
|
2023-08-10 13:58:50 +02:00
|
|
|
|
{
|
2023-09-12 10:31:55 +02:00
|
|
|
|
var testDuration = DateTime.UtcNow - testStart;
|
|
|
|
|
|
return Time.FormatDuration(testDuration);
|
2023-08-10 13:58:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-13 15:10:19 +02:00
|
|
|
|
public void OnContainersStarted(RunningContainers rc)
|
|
|
|
|
|
{
|
|
|
|
|
|
runningContainers.Add(rc);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnContainersStopped(RunningContainers rc)
|
|
|
|
|
|
{
|
|
|
|
|
|
runningContainers.Remove(rc);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DownloadAllLogs()
|
|
|
|
|
|
{
|
|
|
|
|
|
var workflow = entryPoint.Tools.CreateWorkflow();
|
|
|
|
|
|
foreach (var rc in runningContainers)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var c in rc.Containers)
|
|
|
|
|
|
{
|
|
|
|
|
|
DownloadContainerLog(workflow, c);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DownloadContainerLog(IStartupWorkflow workflow, RunningContainer c)
|
|
|
|
|
|
{
|
|
|
|
|
|
var file = Log.CreateSubfile();
|
|
|
|
|
|
Log.Log($"Downloading container log for '{c.Name}' to file '{file.FullFilename}'...");
|
|
|
|
|
|
var handler = new LogDownloadHandler(c.Name, file);
|
|
|
|
|
|
workflow.DownloadContainerLog(c, handler);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-12 10:31:55 +02:00
|
|
|
|
//public ApplicationIds GetApplicationIds()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// //return new ApplicationIds(
|
|
|
|
|
|
// // codexId: GetCodexId(),
|
|
|
|
|
|
// // gethId: new GethContainerRecipe().Image,
|
|
|
|
|
|
// // prometheusId: new PrometheusContainerRecipe().Image,
|
|
|
|
|
|
// // codexContractsId: new CodexContractsContainerRecipe().Image,
|
|
|
|
|
|
// // grafanaId: new GrafanaContainerRecipe().Image
|
|
|
|
|
|
// //);
|
|
|
|
|
|
// return null!;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//private string GetCodexId()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return "";
|
|
|
|
|
|
// //var v = CodexVersion;
|
|
|
|
|
|
// //if (v == null) return new CodexContainerRecipe().Image;
|
|
|
|
|
|
// //if (v.version != "untagged build") return v.version;
|
|
|
|
|
|
// //return v.revision;
|
|
|
|
|
|
//}
|
2023-04-12 13:53:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|