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.Codex;
using KubernetesWorkflow;
using Logging;
using Utils;
namespace ContinuousTests
{
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 host = url.Substring(0, cutIndex);
var port = url.Substring(cutIndex + 1);
var address = new Address(host, Convert.ToInt32(port));
var address = container.ClusterInternalAddress;
return new CodexNode(log, timeSet, address);
}).ToArray();
}

View File

@ -1,11 +1,12 @@
using Newtonsoft.Json;
using DistTestCore.Codex;
using Newtonsoft.Json;
namespace ContinuousTests
{
public class Configuration
{
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 SleepSecondsPerAllTests { get; set; }
public bool KeepPassedTestLogs { get; set; }
@ -37,32 +38,30 @@ namespace ContinuousTests
}
var logPath = Environment.GetEnvironmentVariable("LOGPATH");
var codexUrls = Environment.GetEnvironmentVariable("CODEXURLS");
var codexDeploymentJson = Environment.GetEnvironmentVariable("CODEXDEPLOYMENT");
var sleepPerSingle = Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST");
var sleepPerAll = Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS");
var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS");
if (!string.IsNullOrEmpty(logPath) &&
!string.IsNullOrEmpty(codexUrls) &&
!string.IsNullOrEmpty(codexDeploymentJson) &&
!string.IsNullOrEmpty(sleepPerSingle) &&
!string.IsNullOrEmpty(sleepPerAll))
{
var urls = codexUrls.Split(';', StringSplitOptions.RemoveEmptyEntries);
int secondsSingle;
int secondsAll;
if (int.TryParse(sleepPerSingle, out secondsSingle) && int.TryParse(sleepPerAll, out secondsAll))
try
{
if (urls.Length > 0)
{
return new Configuration
{
LogPath = logPath,
CodexUrls = urls,
SleepSecondsPerSingleTest = secondsSingle,
SleepSecondsPerAllTests = secondsAll,
KeepPassedTestLogs = keep == "1"
};
}
return new Configuration
{
LogPath = logPath,
CodexDeployment = ParseCodexDeploymentJson(codexDeploymentJson),
SleepSecondsPerSingleTest = Convert.ToInt32(sleepPerSingle),
SleepSecondsPerAllTests = Convert.ToInt32(sleepPerAll),
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 " +
"unable to load configuration from environment variables. " + 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 +
"'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 +
@ -95,10 +94,17 @@ namespace ContinuousTests
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()
{
var config = //configLoader.Load();
new Configuration
{
CodexUrls =new[] { "http://localhost:8080", "http://localhost:8081" },
LogPath = "logs",
KeepPassedTestLogs = false,
SleepSecondsPerAllTests = 1,
SleepSecondsPerSingleTest = 1,
};
var config = configLoader.Load();
StartupChecks(config);
while (true)
@ -73,9 +65,9 @@ namespace ContinuousTests
var errors = new List<string>();
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)
{
var nodes = codexNodeFactory.Create(config.CodexUrls, log, new DefaultTimeSet());
var nodes = codexNodeFactory.Create(config.CodexDeployment.CodexContainers, log, new DefaultTimeSet());
var pass = true;
foreach (var n in nodes)
{

View File

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