2023-05-31 11:34:12 +00:00
|
|
|
|
using DistTestCore.Codex;
|
|
|
|
|
using KubernetesWorkflow;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore
|
|
|
|
|
{
|
|
|
|
|
public class Configuration
|
|
|
|
|
{
|
2023-06-02 07:03:46 +00:00
|
|
|
|
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");
|
|
|
|
|
logDebug = GetEnvVarOrDefault("LOGDEBUG", "false").ToLowerInvariant() == "true";
|
|
|
|
|
dataFilesPath = GetEnvVarOrDefault("DATAFILEPATH", "TestDataFiles");
|
|
|
|
|
codexLogLevel = ParseEnum<CodexLogLevel>(GetEnvVarOrDefault("LOGLEVEL", nameof(CodexLogLevel.Trace)));
|
|
|
|
|
runnerLocation = ParseEnum<TestRunnerLocation>(GetEnvVarOrDefault("RUNNERLOCATION", nameof(TestRunnerLocation.ExternalToCluster)));
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 06:55:20 +00:00
|
|
|
|
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-",
|
2023-06-02 07:03:46 +00:00
|
|
|
|
kubeConfigFile: kubeConfigFile,
|
2023-05-04 06:55:20 +00:00
|
|
|
|
operationTimeout: timeSet.K8sOperationTimeout(),
|
|
|
|
|
retryDelay: timeSet.WaitForK8sServiceDelay(),
|
2023-04-12 14:06:04 +00:00
|
|
|
|
locationMap: new[]
|
|
|
|
|
{
|
|
|
|
|
new ConfigurationLocationEntry(Location.BensOldGamingMachine, "worker01"),
|
|
|
|
|
new ConfigurationLocationEntry(Location.BensLaptop, "worker02"),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Logging.LogConfig GetLogConfig()
|
|
|
|
|
{
|
2023-06-02 07:03:46 +00:00
|
|
|
|
return new Logging.LogConfig(logPath, debugEnabled: logDebug);
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetFileManagerFolder()
|
|
|
|
|
{
|
2023-06-02 07:03:46 +00:00
|
|
|
|
return dataFilesPath;
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
2023-05-31 11:34:12 +00:00
|
|
|
|
|
|
|
|
|
public CodexLogLevel GetCodexLogLevel()
|
|
|
|
|
{
|
2023-06-02 07:03:46 +00:00
|
|
|
|
return codexLogLevel;
|
2023-05-31 11:34:12 +00:00
|
|
|
|
}
|
2023-06-01 07:35:18 +00:00
|
|
|
|
|
|
|
|
|
public TestRunnerLocation GetTestRunnerLocation()
|
|
|
|
|
{
|
2023-06-02 07:03:46 +00:00
|
|
|
|
return runnerLocation;
|
2023-06-01 07:35:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RunningContainerAddress GetAddress(RunningContainer container)
|
|
|
|
|
{
|
|
|
|
|
if (GetTestRunnerLocation() == TestRunnerLocation.InternalToCluster)
|
|
|
|
|
{
|
|
|
|
|
return container.ClusterInternalAddress;
|
|
|
|
|
}
|
|
|
|
|
return container.ClusterExternalAddress;
|
|
|
|
|
}
|
2023-06-02 07:03:46 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static T ParseEnum<T>(string value)
|
|
|
|
|
{
|
|
|
|
|
return (T)Enum.Parse(typeof(T), value, true);
|
|
|
|
|
}
|
2023-06-01 07:35:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum TestRunnerLocation
|
|
|
|
|
{
|
|
|
|
|
ExternalToCluster,
|
|
|
|
|
InternalToCluster,
|
2023-04-12 14:06:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|