2023-09-12 11:32:06 +00:00
|
|
|
|
using Core;
|
2023-09-20 08:51:47 +00:00
|
|
|
|
using DistTestCore.Logs;
|
2023-09-13 08:03:11 +00:00
|
|
|
|
using FileUtils;
|
2023-09-13 13:10:19 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-11-12 09:07:23 +00:00
|
|
|
|
using KubernetesWorkflow.Recipe;
|
|
|
|
|
using KubernetesWorkflow.Types;
|
2023-05-03 12:55:26 +00:00
|
|
|
|
using Utils;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
2023-09-13 13:10:19 +00:00
|
|
|
|
public class TestLifecycle : IK8sHooks
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-09-13 14:06:05 +00:00
|
|
|
|
private const string TestsType = "dist-tests";
|
2023-09-13 08:03:11 +00:00
|
|
|
|
private readonly EntryPoint entryPoint;
|
2024-02-22 13:41:07 +00:00
|
|
|
|
private readonly Dictionary<string, string> metadata;
|
2024-04-13 14:09:17 +00:00
|
|
|
|
private readonly List<RunningPod> runningContainers = new();
|
2024-02-22 13:41:07 +00:00
|
|
|
|
private readonly string deployId;
|
2023-04-13 12:36:17 +00:00
|
|
|
|
|
2024-06-06 13:09:52 +00:00
|
|
|
|
public TestLifecycle(TestLog log, Configuration configuration, ITimeSet timeSet, string testNamespace, string deployId, bool waitForCleanup)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-14 12:53:39 +00:00
|
|
|
|
Log = log;
|
2023-06-01 07:35:18 +00:00
|
|
|
|
Configuration = configuration;
|
2023-05-04 06:55:20 +00:00
|
|
|
|
TimeSet = timeSet;
|
2023-12-20 08:48:22 +00:00
|
|
|
|
TestStart = DateTime.UtcNow;
|
2023-07-18 12:26:21 +00:00
|
|
|
|
|
2023-09-13 13:10:19 +00:00
|
|
|
|
entryPoint = new EntryPoint(log, configuration.GetK8sConfiguration(timeSet, this, testNamespace), configuration.GetFileManagerFolder(), timeSet);
|
2023-09-26 12:32:28 +00:00
|
|
|
|
metadata = entryPoint.GetPluginMetadata();
|
2023-09-13 08:03:11 +00:00
|
|
|
|
CoreInterface = entryPoint.CreateInterface();
|
2024-02-22 13:41:07 +00:00
|
|
|
|
this.deployId = deployId;
|
2024-06-06 13:09:52 +00:00
|
|
|
|
WaitForCleanup = waitForCleanup;
|
2023-09-12 08:31:55 +00:00
|
|
|
|
log.WriteLogTag();
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
2023-12-20 08:48:22 +00:00
|
|
|
|
public DateTime TestStart { get; }
|
2023-09-12 08:31:55 +00:00
|
|
|
|
public TestLog Log { get; }
|
2023-06-01 07:35:18 +00:00
|
|
|
|
public Configuration Configuration { get; }
|
2023-05-04 06:55:20 +00:00
|
|
|
|
public ITimeSet TimeSet { get; }
|
2024-06-06 13:09:52 +00:00
|
|
|
|
public bool WaitForCleanup { get; }
|
2023-09-13 06:55:04 +00:00
|
|
|
|
public CoreInterface CoreInterface { get; }
|
2023-09-12 08:31:55 +00:00
|
|
|
|
|
|
|
|
|
public void DeleteAllResources()
|
|
|
|
|
{
|
2023-09-21 08:33:09 +00:00
|
|
|
|
entryPoint.Decommission(
|
|
|
|
|
deleteKubernetesResources: true,
|
2024-06-06 13:09:52 +00:00
|
|
|
|
deleteTrackedFiles: true,
|
|
|
|
|
waitTillDone: WaitForCleanup
|
2023-09-21 08:33:09 +00:00
|
|
|
|
);
|
2023-09-13 08:03:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TrackedFile GenerateTestFile(ByteSize size, string label = "")
|
|
|
|
|
{
|
|
|
|
|
return entryPoint.Tools.GetFileManager().GenerateFile(size, label);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 12:24:43 +00:00
|
|
|
|
public IFileManager GetFileManager()
|
2023-09-13 08:03:11 +00:00
|
|
|
|
{
|
2023-09-13 12:24:43 +00:00
|
|
|
|
return entryPoint.Tools.GetFileManager();
|
2023-05-03 12:55:26 +00:00
|
|
|
|
}
|
2023-07-31 09:51:29 +00:00
|
|
|
|
|
2023-09-13 14:06:05 +00:00
|
|
|
|
public Dictionary<string, string> GetPluginMetadata()
|
|
|
|
|
{
|
|
|
|
|
return entryPoint.GetPluginMetadata();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 11:56:47 +00:00
|
|
|
|
public TimeSpan GetTestDuration()
|
2023-08-10 11:58:50 +00:00
|
|
|
|
{
|
2023-12-20 08:48:22 +00:00
|
|
|
|
return DateTime.UtcNow - TestStart;
|
2023-08-10 11:58:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
|
public void OnContainersStarted(RunningPod rc)
|
2023-09-13 13:10:19 +00:00
|
|
|
|
{
|
|
|
|
|
runningContainers.Add(rc);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-13 14:09:17 +00:00
|
|
|
|
public void OnContainersStopped(RunningPod rc)
|
2023-09-13 13:10:19 +00:00
|
|
|
|
{
|
|
|
|
|
runningContainers.Remove(rc);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 14:06:05 +00:00
|
|
|
|
public void OnContainerRecipeCreated(ContainerRecipe recipe)
|
|
|
|
|
{
|
|
|
|
|
recipe.PodLabels.Add("tests-type", TestsType);
|
2024-02-22 13:41:07 +00:00
|
|
|
|
recipe.PodLabels.Add("deployid", deployId);
|
2023-09-13 14:06:05 +00:00
|
|
|
|
recipe.PodLabels.Add("testid", NameUtils.GetTestId());
|
|
|
|
|
recipe.PodLabels.Add("category", NameUtils.GetCategoryName());
|
|
|
|
|
recipe.PodLabels.Add("fixturename", NameUtils.GetRawFixtureName());
|
|
|
|
|
recipe.PodLabels.Add("testname", NameUtils.GetTestMethodName());
|
2023-11-13 10:56:02 +00:00
|
|
|
|
recipe.PodLabels.Add("testframeworkrevision", GitInfo.GetStatus());
|
2023-09-26 12:32:28 +00:00
|
|
|
|
|
|
|
|
|
foreach (var pair in metadata)
|
|
|
|
|
{
|
|
|
|
|
recipe.PodLabels.Add(pair.Key, pair.Value);
|
|
|
|
|
}
|
2023-09-13 14:06:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 13:10:19 +00:00
|
|
|
|
public void DownloadAllLogs()
|
|
|
|
|
{
|
2024-04-15 09:37:14 +00:00
|
|
|
|
try
|
2023-09-13 13:10:19 +00:00
|
|
|
|
{
|
2024-04-15 09:37:14 +00:00
|
|
|
|
foreach (var rc in runningContainers)
|
2023-09-13 13:10:19 +00:00
|
|
|
|
{
|
2024-04-15 09:37:14 +00:00
|
|
|
|
foreach (var c in rc.Containers)
|
|
|
|
|
{
|
|
|
|
|
CoreInterface.DownloadLog(c);
|
|
|
|
|
}
|
2023-09-13 13:10:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-15 09:37:14 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("Exception during log download: " + ex);
|
|
|
|
|
}
|
2023-09-13 13:10:19 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|