2023-06-26 12:44:21 +00:00
using ArgsUniform ;
2023-06-30 07:43:20 +00:00
using DistTestCore ;
2023-06-26 12:44:21 +00:00
using DistTestCore.Codex ;
2023-06-23 08:14:16 +00:00
using Newtonsoft.Json ;
2023-06-21 06:28:40 +00:00
namespace ContinuousTests
{
public class Configuration
{
2023-06-26 12:44:21 +00:00
[Uniform("log-path", "l", "LOGPATH", true, "Path where log files will be written.")]
public string LogPath { get ; set ; } = "logs" ;
2023-06-21 06:28:40 +00:00
2023-06-26 12:44:21 +00:00
[Uniform("data-path", "d", "DATAPATH", true, "Path where temporary data files will be written.")]
public string DataPath { get ; set ; } = "data" ;
2023-06-21 06:28:40 +00:00
2023-06-26 12:44:21 +00:00
[Uniform("codex-deployment", "c", "CODEXDEPLOYMENT", true, "Path to codex-deployment JSON file.")]
public string CodexDeploymentJson { get ; set ; } = string . Empty ;
2023-06-21 06:28:40 +00:00
2023-06-26 12:44:21 +00:00
[Uniform("keep", "k", "KEEP", false, "Set to '1' to retain logs of successful tests.")]
public bool KeepPassedTestLogs { get ; set ; } = false ;
2023-06-21 06:28:40 +00:00
2023-06-27 08:16:59 +00:00
[Uniform("kube-config", "kc", "KUBECONFIG", true, "Path to Kubeconfig file. Use 'null' (default) to use local cluster.")]
public string KubeConfigFile { get ; set ; } = "null" ;
2023-06-26 13:37:16 +00:00
2023-06-30 07:09:59 +00:00
[Uniform("stop", "s", "STOPONFAIL", false, "If true, runner will stop on first test failure and download all cluster container logs. False by default.")]
public bool StopOnFailure { get ; set ; } = false ;
2023-07-20 11:37:11 +00:00
[Uniform("dl-logs", "dl", "DLLOGS", false, "If true, runner will periodically download and save/append container logs to the log path.")]
public bool DownloadContainerLogs { get ; set ; } = false ;
2023-06-26 12:44:21 +00:00
public CodexDeployment CodexDeployment { get ; set ; } = null ! ;
2023-06-30 07:09:59 +00:00
public TestRunnerLocation RunnerLocation { get ; set ; } = TestRunnerLocation . InternalToCluster ;
2023-06-26 12:44:21 +00:00
}
2023-06-21 06:28:40 +00:00
2023-06-26 12:44:21 +00:00
public class ConfigLoader
{
public Configuration Load ( string [ ] args )
2023-06-21 06:28:40 +00:00
{
2023-06-30 07:09:59 +00:00
var uniformArgs = new ArgsUniform < Configuration > ( PrintHelp , args ) ;
2023-06-25 08:50:01 +00:00
2023-06-27 08:16:59 +00:00
var result = uniformArgs . Parse ( true ) ;
2023-06-26 12:44:21 +00:00
result . CodexDeployment = ParseCodexDeploymentJson ( result . CodexDeploymentJson ) ;
2023-06-30 07:09:59 +00:00
if ( args . Any ( a = > a = = "--external" ) )
{
result . RunnerLocation = TestRunnerLocation . ExternalToCluster ;
}
2023-06-21 06:28:40 +00:00
2023-06-26 12:44:21 +00:00
return result ;
2023-06-21 06:28:40 +00:00
}
2023-06-26 12:44:21 +00:00
2023-06-23 08:14:16 +00:00
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 ;
}
2023-06-30 07:09:59 +00:00
private static void PrintHelp ( )
{
var nl = Environment . NewLine ;
2023-07-18 07:47:44 +00:00
Console . WriteLine ( "ContinuousTests will run a set of tests against a codex deployment given a codex-deployment.json file." + nl +
"The tests will run in an endless loop unless otherwise specified, using the test-specific timing values." + nl ) ;
2023-06-30 07:09:59 +00:00
2023-07-18 07:47:44 +00:00
Console . WriteLine ( "ContinuousTests assumes you are running this tool from *inside* the Kubernetes cluster. " +
2023-06-30 07:09:59 +00:00
"If you are not running this from a container inside the cluster, add the argument '--external'." + nl ) ;
}
2023-06-21 06:28:40 +00:00
}
}