From c348ca98490e4d4d84e3251a7e8eeafa0b7c490d Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 31 Oct 2023 11:22:59 +0100 Subject: [PATCH] sets up test starter tool --- Tools/TestClusterStarter/ClusterTestSpec.cs | 42 ++++++++++++++++ Tools/TestClusterStarter/Configuration.cs | 10 ++++ Tools/TestClusterStarter/Program.cs | 50 +++++++++++++++++++ .../TestClusterStarter.csproj | 21 ++++++++ cs-codex-dist-testing.sln | 14 ++++++ docker/build-deployandrun.bat | 2 + 6 files changed, 139 insertions(+) create mode 100644 Tools/TestClusterStarter/ClusterTestSpec.cs create mode 100644 Tools/TestClusterStarter/Configuration.cs create mode 100644 Tools/TestClusterStarter/Program.cs create mode 100644 Tools/TestClusterStarter/TestClusterStarter.csproj create mode 100644 docker/build-deployandrun.bat diff --git a/Tools/TestClusterStarter/ClusterTestSpec.cs b/Tools/TestClusterStarter/ClusterTestSpec.cs new file mode 100644 index 00000000..88b18c2e --- /dev/null +++ b/Tools/TestClusterStarter/ClusterTestSpec.cs @@ -0,0 +1,42 @@ +using KubernetesWorkflow; + +namespace TestClusterStarter +{ + public class ClusterTestSetup + { + public ClusterTestSetup(ClusterTestSpec[] specs) + { + Specs = specs; + } + + public ClusterTestSpec[] Specs { get; } + } + + public class ClusterTestSpec + { + public ClusterTestSpec(string name, string filter, int replication, int durationSeconds, string? codexImageOverride) + { + Name = name; + Filter = filter; + Replication = replication; + DurationSeconds = durationSeconds; + CodexImageOverride = codexImageOverride; + } + + public string Name { get; } + public string Filter { get; } + public int Replication { get; } + public int DurationSeconds { get; } + public string? CodexImageOverride { get; } + } + + public class ClusterTestDeployment + { + public ClusterTestDeployment(RunningContainer[] containers) + { + Containers = containers; + } + + public RunningContainer[] Containers { get; } + } +} diff --git a/Tools/TestClusterStarter/Configuration.cs b/Tools/TestClusterStarter/Configuration.cs new file mode 100644 index 00000000..8e30d93c --- /dev/null +++ b/Tools/TestClusterStarter/Configuration.cs @@ -0,0 +1,10 @@ +using ArgsUniform; + +namespace TestClusterStarter +{ + public class Configuration + { + [Uniform("kube-config", "kc", "KUBECONFIG", true, "Path to Kubeconfig file. Use 'null' (default) to use local cluster.")] + public string KubeConfigFile { get; set; } = "null"; + } +} diff --git a/Tools/TestClusterStarter/Program.cs b/Tools/TestClusterStarter/Program.cs new file mode 100644 index 00000000..13dacfca --- /dev/null +++ b/Tools/TestClusterStarter/Program.cs @@ -0,0 +1,50 @@ +using ArgsUniform; +using Core; +using DeployAndRunPlugin; +using KubernetesWorkflow; +using Logging; +using Newtonsoft.Json; +using TestClusterStarter; + +public class Program +{ + private const string SpecsFile = "TestSpecs.json"; + + public static void Main(string[] args) + { + var argsUniform = new ArgsUniform(() => { }, args); + var config = argsUniform.Parse(); + + ProjectPlugin.Load(); + + if (!File.Exists(SpecsFile)) + { + File.WriteAllText(SpecsFile, JsonConvert.SerializeObject(new ClusterTestSetup(new[] + { + new ClusterTestSpec("example", "peer", 2, Convert.ToInt32(TimeSpan.FromDays(2).TotalSeconds), "imageoverride") + }))); + return; + } + var specs = JsonConvert.DeserializeObject(File.ReadAllText(SpecsFile))!; + + var kConfig = new KubernetesWorkflow.Configuration(config.KubeConfigFile, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10), "codex-continuous-test-runners"); + var entryPoint = new EntryPoint(new ConsoleLog(), kConfig, "datafolder"); + var ci = entryPoint.CreateInterface(); + + var rcs = new List(); + foreach (var spec in specs.Specs) + { + var rc = ci.DeployAndRunContinuousTests(new RunConfig( + name: spec.Name, + filter: spec.Filter, + duration: TimeSpan.FromSeconds(spec.DurationSeconds), + replications: spec.Replication, + codexImageOverride: spec.CodexImageOverride)); + + rcs.Add(rc); + } + + var deployment = new ClusterTestDeployment(rcs.ToArray()); + File.WriteAllText("clustertest-deployment.json", JsonConvert.SerializeObject(deployment, Formatting.Indented)); + } +} diff --git a/Tools/TestClusterStarter/TestClusterStarter.csproj b/Tools/TestClusterStarter/TestClusterStarter.csproj new file mode 100644 index 00000000..5522cbed --- /dev/null +++ b/Tools/TestClusterStarter/TestClusterStarter.csproj @@ -0,0 +1,21 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + + + + + + + diff --git a/cs-codex-dist-testing.sln b/cs-codex-dist-testing.sln index 585e0026..944f83bc 100644 --- a/cs-codex-dist-testing.sln +++ b/cs-codex-dist-testing.sln @@ -47,6 +47,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BiblioTech", "Tools\BiblioT EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodexDiscordBotPlugin", "ProjectPlugins\CodexDiscordBotPlugin\CodexDiscordBotPlugin.csproj", "{FB96A58B-F7F0-490A-9A85-72A96A018042}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestClusterStarter", "Tools\TestClusterStarter\TestClusterStarter.csproj", "{3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeployAndRunPlugin", "ProjectPlugins\DeployAndRunPlugin\DeployAndRunPlugin.csproj", "{1CC5AF82-8924-4C7E-BFF1-3125D86E53FB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -125,6 +129,14 @@ Global {FB96A58B-F7F0-490A-9A85-72A96A018042}.Debug|Any CPU.Build.0 = Debug|Any CPU {FB96A58B-F7F0-490A-9A85-72A96A018042}.Release|Any CPU.ActiveCfg = Release|Any CPU {FB96A58B-F7F0-490A-9A85-72A96A018042}.Release|Any CPU.Build.0 = Release|Any CPU + {3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA}.Release|Any CPU.Build.0 = Release|Any CPU + {1CC5AF82-8924-4C7E-BFF1-3125D86E53FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1CC5AF82-8924-4C7E-BFF1-3125D86E53FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1CC5AF82-8924-4C7E-BFF1-3125D86E53FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1CC5AF82-8924-4C7E-BFF1-3125D86E53FB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -148,6 +160,8 @@ Global {3417D508-E2F4-4974-8988-BB124046D9E2} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} {078ABA6D-A04E-4F62-A44C-EA66F1B66548} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} {FB96A58B-F7F0-490A-9A85-72A96A018042} = {8F1F1C2A-E313-4E0C-BE40-58FB0BA91124} + {3E38A906-C2FC-43DC-8CA2-FC07C79CF3CA} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3} + {1CC5AF82-8924-4C7E-BFF1-3125D86E53FB} = {8F1F1C2A-E313-4E0C-BE40-58FB0BA91124} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {237BF0AA-9EC4-4659-AD9A-65DEB974250C} diff --git a/docker/build-deployandrun.bat b/docker/build-deployandrun.bat new file mode 100644 index 00000000..8af14b00 --- /dev/null +++ b/docker/build-deployandrun.bat @@ -0,0 +1,2 @@ +docker build -f deployandrun.Dockerfile -t thatbenbierens/dist-tests-deployandrun:initial .. +docker push thatbenbierens/dist-tests-deployandrun:initial