cs-codex-dist-tests/CodexNetDeployer/Configuration.cs

82 lines
3.3 KiB
C#
Raw Normal View History

2023-06-26 11:58:41 +00:00
using ArgsUniform;
using DistTestCore;
2023-06-22 08:33:21 +00:00
using DistTestCore.Codex;
2023-06-26 11:58:41 +00:00
using DistTestCore.Marketplace;
2023-06-22 08:17:12 +00:00
namespace CodexNetDeployer
2023-06-22 07:51:25 +00:00
{
public class Configuration
{
2023-06-26 11:58:41 +00:00
[Uniform("codex-image", "ci", "CODEXIMAGE", true, "Docker image of Codex.")]
2023-06-27 06:29:39 +00:00
public string CodexImage { get; set; } = CodexContainerRecipe.DockerImage;
2023-06-26 11:58:41 +00:00
[Uniform("geth-image", "gi", "GETHIMAGE", true, "Docker image of Geth.")]
2023-06-27 06:29:39 +00:00
public string GethImage { get; set; } = GethContainerRecipe.DockerImage;
2023-06-26 11:58:41 +00:00
[Uniform("contracts-image", "oi", "CONTRACTSIMAGE", true, "Docker image of Codex Contracts.")]
2023-06-27 06:29:39 +00:00
public string ContractsImage { get; set; } = CodexContractsContainerRecipe.DockerImage;
2023-06-26 11:58:41 +00:00
2023-06-27 06:29:39 +00:00
[Uniform("kube-config", "kc", "KUBECONFIG", false, "Path to Kubeconfig file. Use 'null' (default) to use local cluster.")]
public string KubeConfigFile { get; set; } = "null";
2023-06-26 11:58:41 +00:00
[Uniform("kube-namespace", "kn", "KUBENAMESPACE", true, "Kubernetes namespace to be used for deployment.")]
public string KubeNamespace { get; set; } = string.Empty;
[Uniform("nodes", "n", "NODES", true, "Number of Codex nodes to be created.")]
public int? NumberOfCodexNodes { get; set; }
[Uniform("validators", "v", "VALIDATORS", true, "Number of Codex nodes that will be validating.")]
public int? NumberOfValidators { get; set; }
[Uniform("storage-quota", "s", "STORAGEQUOTA", true, "Storage quota in megabytes used by each Codex node.")]
public int? StorageQuota { get; set; }
2023-06-22 07:51:25 +00:00
2023-06-26 11:58:41 +00:00
[Uniform("log-level", "l", "LOGLEVEL", true, "Log level used by each Codex node. [Trace, Debug*, Info, Warn, Error]")]
2023-06-27 06:29:39 +00:00
public CodexLogLevel CodexLogLevel { get; set; } = CodexLogLevel.Debug;
2023-06-26 11:58:41 +00:00
public TestRunnerLocation RunnerLocation { get; set; } = TestRunnerLocation.InternalToCluster;
2023-06-22 07:51:25 +00:00
public List<string> Validate()
{
var errors = new List<string>();
ForEachProperty(
onString: (n, v) => StringIsSet(n, v, errors),
onInt: (n, v) => IntIsOverZero(n, v, errors));
2023-06-22 13:58:18 +00:00
if (NumberOfValidators > NumberOfCodexNodes)
{
errors.Add($"{nameof(NumberOfValidators)} ({NumberOfValidators}) may not be greater than {nameof(NumberOfCodexNodes)} ({NumberOfCodexNodes}).");
}
2023-06-22 07:51:25 +00:00
return errors;
}
private void ForEachProperty(Action<string, string> onString, Action<string, int?> onInt)
{
var properties = GetType().GetProperties();
foreach (var p in properties)
{
if (p.PropertyType == typeof(string)) onString(p.Name, (string)p.GetValue(this)!);
if (p.PropertyType == typeof(int?)) onInt(p.Name, (int?)p.GetValue(this)!);
}
}
private static void IntIsOverZero(string variable, int? value, List<string> errors)
{
if (value == null || value.Value < 1)
{
2023-06-27 06:29:39 +00:00
errors.Add($"{variable} must be set and must be greater than 0.");
2023-06-22 07:51:25 +00:00
}
}
private static void StringIsSet(string variable, string value, List<string> errors)
{
if (string.IsNullOrWhiteSpace(value))
{
2023-06-27 06:29:39 +00:00
errors.Add($"{variable} must be set.");
2023-06-22 07:51:25 +00:00
}
}
}
}