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

96 lines
3.2 KiB
C#
Raw Normal View History

2023-05-31 11:34:12 +00:00
using DistTestCore.Codex;
using KubernetesWorkflow;
using Utils;
2023-04-12 14:06:04 +00:00
namespace DistTestCore
{
public class Configuration
{
private readonly string? kubeConfigFile;
private readonly string logPath;
private readonly bool logDebug;
private readonly string dataFilesPath;
private readonly CodexLogLevel codexLogLevel;
private readonly TestRunnerLocation runnerLocation;
public Configuration()
{
kubeConfigFile = GetNullableEnvVarOrDefault("KUBECONFIG", null);
logPath = GetEnvVarOrDefault("LOGPATH", "CodexTestLogs");
2023-06-22 12:37:37 +00:00
logDebug = GetEnvVarOrDefault("LOGDEBUG", "true").ToLowerInvariant() == "true";
dataFilesPath = GetEnvVarOrDefault("DATAFILEPATH", "TestDataFiles");
2023-06-22 08:17:12 +00:00
codexLogLevel = ParseEnum.Parse<CodexLogLevel>(GetEnvVarOrDefault("LOGLEVEL", nameof(CodexLogLevel.Trace)));
runnerLocation = ParseEnum.Parse<TestRunnerLocation>(GetEnvVarOrDefault("RUNNERLOCATION", nameof(TestRunnerLocation.ExternalToCluster)));
}
public Configuration(string? kubeConfigFile, string logPath, bool logDebug, string dataFilesPath, CodexLogLevel codexLogLevel, TestRunnerLocation runnerLocation)
{
this.kubeConfigFile = kubeConfigFile;
this.logPath = logPath;
this.logDebug = logDebug;
this.dataFilesPath = dataFilesPath;
this.codexLogLevel = codexLogLevel;
this.runnerLocation = runnerLocation;
}
public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet)
2023-04-12 14:06:04 +00:00
{
return new KubernetesWorkflow.Configuration(
2023-05-03 12:18:37 +00:00
k8sNamespacePrefix: "ct-",
kubeConfigFile: kubeConfigFile,
operationTimeout: timeSet.K8sOperationTimeout(),
retryDelay: timeSet.WaitForK8sServiceDelay()
2023-04-12 14:06:04 +00:00
);
}
public Logging.LogConfig GetLogConfig()
{
return new Logging.LogConfig(logPath, debugEnabled: logDebug);
2023-04-12 14:06:04 +00:00
}
public string GetFileManagerFolder()
{
return dataFilesPath;
2023-04-12 14:06:04 +00:00
}
2023-05-31 11:34:12 +00:00
public CodexLogLevel GetCodexLogLevel()
{
return codexLogLevel;
2023-05-31 11:34:12 +00:00
}
public TestRunnerLocation GetTestRunnerLocation()
{
return runnerLocation;
}
public Address GetAddress(RunningContainer container)
{
if (GetTestRunnerLocation() == TestRunnerLocation.InternalToCluster)
{
return container.ClusterInternalAddress;
}
return container.ClusterExternalAddress;
}
private static string GetEnvVarOrDefault(string varName, string defaultValue)
{
var v = Environment.GetEnvironmentVariable(varName);
if (v == null) return defaultValue;
return v;
}
private static string? GetNullableEnvVarOrDefault(string varName, string? defaultValue)
{
var v = Environment.GetEnvironmentVariable(varName);
if (v == null) return defaultValue;
return v;
}
}
public enum TestRunnerLocation
{
ExternalToCluster,
InternalToCluster,
2023-04-12 14:06:04 +00:00
}
}