Wires in codex-deployment json.

This commit is contained in:
benbierens 2023-06-23 10:14:16 +02:00
parent 8bceba0182
commit 091eae36cc
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 44 additions and 48 deletions

View File

@ -1,20 +1,17 @@
using DistTestCore; using DistTestCore;
using DistTestCore.Codex; using DistTestCore.Codex;
using KubernetesWorkflow;
using Logging; using Logging;
using Utils;
namespace ContinuousTests namespace ContinuousTests
{ {
public class CodexNodeFactory public class CodexNodeFactory
{ {
public CodexNode[] Create(string[] urls, BaseLog log, ITimeSet timeSet) public CodexNode[] Create(RunningContainer[] containers, BaseLog log, ITimeSet timeSet)
{ {
return urls.Select(url => return containers.Select(container =>
{ {
var cutIndex = url.LastIndexOf(':'); var address = container.ClusterInternalAddress;
var host = url.Substring(0, cutIndex);
var port = url.Substring(cutIndex + 1);
var address = new Address(host, Convert.ToInt32(port));
return new CodexNode(log, timeSet, address); return new CodexNode(log, timeSet, address);
}).ToArray(); }).ToArray();
} }

View File

@ -1,11 +1,12 @@
using Newtonsoft.Json; using DistTestCore.Codex;
using Newtonsoft.Json;
namespace ContinuousTests namespace ContinuousTests
{ {
public class Configuration public class Configuration
{ {
public string LogPath { get; set; } = string.Empty; public string LogPath { get; set; } = string.Empty;
public string[] CodexUrls { get; set; } = Array.Empty<string>(); public CodexDeployment CodexDeployment { get; set; } = null!;
public int SleepSecondsPerSingleTest { get; set; } public int SleepSecondsPerSingleTest { get; set; }
public int SleepSecondsPerAllTests { get; set; } public int SleepSecondsPerAllTests { get; set; }
public bool KeepPassedTestLogs { get; set; } public bool KeepPassedTestLogs { get; set; }
@ -37,32 +38,30 @@ namespace ContinuousTests
} }
var logPath = Environment.GetEnvironmentVariable("LOGPATH"); var logPath = Environment.GetEnvironmentVariable("LOGPATH");
var codexUrls = Environment.GetEnvironmentVariable("CODEXURLS"); var codexDeploymentJson = Environment.GetEnvironmentVariable("CODEXDEPLOYMENT");
var sleepPerSingle = Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST"); var sleepPerSingle = Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST");
var sleepPerAll = Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS"); var sleepPerAll = Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS");
var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS"); var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS");
if (!string.IsNullOrEmpty(logPath) && if (!string.IsNullOrEmpty(logPath) &&
!string.IsNullOrEmpty(codexUrls) && !string.IsNullOrEmpty(codexDeploymentJson) &&
!string.IsNullOrEmpty(sleepPerSingle) && !string.IsNullOrEmpty(sleepPerSingle) &&
!string.IsNullOrEmpty(sleepPerAll)) !string.IsNullOrEmpty(sleepPerAll))
{ {
var urls = codexUrls.Split(';', StringSplitOptions.RemoveEmptyEntries); try
int secondsSingle;
int secondsAll;
if (int.TryParse(sleepPerSingle, out secondsSingle) && int.TryParse(sleepPerAll, out secondsAll))
{ {
if (urls.Length > 0) return new Configuration
{ {
return new Configuration LogPath = logPath,
{ CodexDeployment = ParseCodexDeploymentJson(codexDeploymentJson),
LogPath = logPath, SleepSecondsPerSingleTest = Convert.ToInt32(sleepPerSingle),
CodexUrls = urls, SleepSecondsPerAllTests = Convert.ToInt32(sleepPerAll),
SleepSecondsPerSingleTest = secondsSingle, KeepPassedTestLogs = keep == "1"
SleepSecondsPerAllTests = secondsAll, };
KeepPassedTestLogs = keep == "1" }
}; catch (Exception ex)
} {
Console.WriteLine("Exception: " + ex);
} }
} }
@ -70,7 +69,7 @@ namespace ContinuousTests
throw new Exception($"Unable to load configuration from '{filename}', and " + throw new Exception($"Unable to load configuration from '{filename}', and " +
"unable to load configuration from environment variables. " + nl + "unable to load configuration from environment variables. " + nl +
"'LOGPATH' = Path where log files will be saved." + nl + "'LOGPATH' = Path where log files will be saved." + nl +
"'CODEXURLS' = Semi-colon separated URLs to codex APIs. e.g. 'https://hostaddr_one:port;https://hostaddr_two:port'" + nl + "'CODEXDEPLOYMENT' = Path to codex-deployment JSON file." + nl +
"'SLEEPSECONDSPERSINGLETEST' = Seconds to sleep after each individual test." + nl + "'SLEEPSECONDSPERSINGLETEST' = Seconds to sleep after each individual test." + nl +
"'SLEEPSECONDSPERALLTESTS' = Seconds to sleep after all tests, before starting again." + nl + "'SLEEPSECONDSPERALLTESTS' = Seconds to sleep after all tests, before starting again." + nl +
"'KEEPPASSEDTESTLOGS' = (Optional, default: 0) Set to '1' to keep log files of tests that passed." + nl + "'KEEPPASSEDTESTLOGS' = (Optional, default: 0) Set to '1' to keep log files of tests that passed." + nl +
@ -95,10 +94,17 @@ namespace ContinuousTests
throw new Exception($"Unvalid logpath set: '{configuration.LogPath}'"); throw new Exception($"Unvalid logpath set: '{configuration.LogPath}'");
} }
if (!configuration.CodexUrls.Any()) if (configuration.CodexDeployment != null && configuration.CodexDeployment.CodexContainers.Any())
{ {
throw new Exception("No Codex URLs found."); throw new Exception("No Codex deployment found.");
} }
} }
private CodexDeployment ParseCodexDeploymentJson(string filename)
{
var d = JsonConvert.DeserializeObject<CodexDeployment>(File.ReadAllText(filename))!;
if (d == null) throw new Exception("Unable to parse " + filename);
return d;
}
} }
} }

View File

@ -12,15 +12,7 @@ namespace ContinuousTests
public void Run() public void Run()
{ {
var config = //configLoader.Load(); var config = configLoader.Load();
new Configuration
{
CodexUrls =new[] { "http://localhost:8080", "http://localhost:8081" },
LogPath = "logs",
KeepPassedTestLogs = false,
SleepSecondsPerAllTests = 1,
SleepSecondsPerSingleTest = 1,
};
StartupChecks(config); StartupChecks(config);
while (true) while (true)
@ -73,9 +65,9 @@ namespace ContinuousTests
var errors = new List<string>(); var errors = new List<string>();
foreach (var test in tests) foreach (var test in tests)
{ {
if (test.RequiredNumberOfNodes > config.CodexUrls.Length) if (test.RequiredNumberOfNodes > config.CodexDeployment.CodexContainers.Length)
{ {
errors.Add($"Test '{test.Name}' requires {test.RequiredNumberOfNodes} nodes. Configuration only has {config.CodexUrls.Length}"); errors.Add($"Test '{test.Name}' requires {test.RequiredNumberOfNodes} nodes. Deployment only has {config.CodexDeployment.CodexContainers.Length}");
} }
} }
@ -92,7 +84,7 @@ namespace ContinuousTests
private void CheckCodexNodes(BaseLog log, Configuration config) private void CheckCodexNodes(BaseLog log, Configuration config)
{ {
var nodes = codexNodeFactory.Create(config.CodexUrls, log, new DefaultTimeSet()); var nodes = codexNodeFactory.Create(config.CodexDeployment.CodexContainers, log, new DefaultTimeSet());
var pass = true; var pass = true;
foreach (var n in nodes) foreach (var n in nodes)
{ {

View File

@ -2,6 +2,7 @@
using DistTestCore; using DistTestCore;
using Logging; using Logging;
using Utils; using Utils;
using KubernetesWorkflow;
namespace ContinuousTests namespace ContinuousTests
{ {
@ -37,18 +38,18 @@ namespace ContinuousTests
private CodexNode[] CreateRandomNodes(int number, BaseLog testLog) private CodexNode[] CreateRandomNodes(int number, BaseLog testLog)
{ {
var urls = SelectRandomUrls(number); var containers = SelectRandomContainers(number);
testLog.Log("Selected nodes: " + string.Join(",", urls)); testLog.Log("Selected nodes: " + string.Join(",", containers.Select(c => c.Name)));
return codexNodeFactory.Create(urls, testLog, test.TimeSet); return codexNodeFactory.Create(containers, testLog, test.TimeSet);
} }
private string[] SelectRandomUrls(int number) private RunningContainer[] SelectRandomContainers(int number)
{ {
var urls = config.CodexUrls.ToList(); var containers = config.CodexDeployment.CodexContainers.ToList();
var result = new string[number]; var result = new RunningContainer[number];
for (var i = 0; i < number; i++) for (var i = 0; i < number; i++)
{ {
result[i] = urls.PickOneRandom(); result[i] = containers.PickOneRandom();
} }
return result; return result;
} }