2023-06-26 12:44:21 +00:00
using ArgsUniform ;
2023-09-20 11:33:58 +00:00
using CodexPlugin ;
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-10-04 07:19:45 +00:00
[Uniform("keep", "k", "KEEP", false, "Set to 1 or 'true' to retain logs of successful tests.")]
2023-06-26 12:44:21 +00:00
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-08-30 07:23:13 +00:00
[Uniform("stop", "s", "STOPONFAIL", false, "If greater than zero, runner will stop after this many test failures and download all cluster container logs. 0 by default.")]
public int StopOnFailure { get ; set ; } = 0 ;
2023-06-30 07:09:59 +00:00
2023-09-27 09:33:54 +00:00
[Uniform("target-duration", "td", "TARGETDURATION", false, "If greater than zero, runner will run for this many seconds before stopping.")]
public int TargetDurationSeconds { get ; set ; } = 0 ;
2023-10-03 07:53:02 +00:00
[Uniform("filter", "f", "FILTER", false, "If set, runs only tests whose names contain any of the filter strings. Comma-separated. Case sensitive.")]
public string Filter { get ; set ; } = string . Empty ;
2023-10-04 07:19:45 +00:00
[Uniform("cleanup", "cl", "CLEANUP", false, "If set to 1 or 'true', the kubernetes namespace will be deleted after the test run has finished.")]
2023-10-03 07:53:02 +00:00
public bool Cleanup { get ; set ; } = false ;
2023-10-08 17:11:31 +00:00
[ Uniform ( "full-container-logs" , "fcl" , "FULLCONTAINERLOGS" , false , "If set to 1 or 'true', container logs downloaded on test failure will download from" +
" the timestamp of the start of the network deployment. Otherwise, logs will start from the test start timestamp." ) ]
public bool FullContainerLogs { get ; set ; } = false ;
2023-06-26 12:44:21 +00:00
public CodexDeployment CodexDeployment { get ; set ; } = null ! ;
}
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 ) ;
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 +
2023-09-29 08:19:59 +00:00
"The tests will run in an endless loop unless otherwise specified." + nl ) ;
2023-06-30 07:09:59 +00:00
}
2023-06-21 06:28:40 +00:00
}
}