Extracts configurable components to config folder
This commit is contained in:
parent
496673c882
commit
3359b10929
|
@ -1,4 +1,5 @@
|
|||
using k8s.Models;
|
||||
using CodexDistTestCore.Config;
|
||||
using k8s.Models;
|
||||
using System.Collections;
|
||||
|
||||
namespace CodexDistTestCore
|
||||
|
@ -63,7 +64,7 @@ namespace CodexDistTestCore
|
|||
return new V1ObjectMeta
|
||||
{
|
||||
Name = "codex-test-entrypoint-" + OrderNumber,
|
||||
NamespaceProperty = K8sOperations.K8sNamespace
|
||||
NamespaceProperty = K8sCluster.K8sNamespace
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -72,7 +73,7 @@ namespace CodexDistTestCore
|
|||
return new V1ObjectMeta
|
||||
{
|
||||
Name = "codex-test-node-" + OrderNumber,
|
||||
NamespaceProperty = K8sOperations.K8sNamespace
|
||||
NamespaceProperty = K8sCluster.K8sNamespace
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using k8s.Models;
|
||||
|
||||
namespace CodexDistTestCore
|
||||
namespace CodexDistTestCore.Config
|
||||
{
|
||||
public class CodexDockerImage
|
||||
{
|
|
@ -0,0 +1,7 @@
|
|||
namespace CodexDistTestCore.Config
|
||||
{
|
||||
public class FileManagerConfig
|
||||
{
|
||||
public const string Folder = "TestDataFiles";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
using k8s;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CodexDistTestCore.Config
|
||||
{
|
||||
public class K8sCluster
|
||||
{
|
||||
public const string K8sNamespace = "codex-test-namespace";
|
||||
|
||||
public KubernetesClientConfiguration GetK8sClientConfig()
|
||||
{
|
||||
// todo: If the default KubeConfig file does not suffice, change it here:
|
||||
return KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
}
|
||||
|
||||
public string GetIp()
|
||||
{
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
public string GetNodeLabelForLocation(Location location)
|
||||
{
|
||||
switch (location)
|
||||
{
|
||||
case Location.Unspecified:
|
||||
return string.Empty;
|
||||
case Location.BensLaptop:
|
||||
return "worker01";
|
||||
case Location.BensOldGamingMachine:
|
||||
return "worker02";
|
||||
}
|
||||
|
||||
Assert.Fail("Unknown location selected: " + location);
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace CodexDistTestCore.Config
|
||||
{
|
||||
public class LogConfig
|
||||
{
|
||||
public const string LogRoot = "D:/CodexTestLogs";
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using NUnit.Framework;
|
||||
using CodexDistTestCore.Config;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CodexDistTestCore
|
||||
{
|
||||
|
@ -12,20 +13,19 @@ namespace CodexDistTestCore
|
|||
public class FileManager : IFileManager
|
||||
{
|
||||
public const int ChunkSize = 1024 * 1024;
|
||||
private const string Folder = "TestDataFiles";
|
||||
private readonly Random random = new Random();
|
||||
private readonly List<TestFile> activeFiles = new List<TestFile>();
|
||||
private readonly TestLog log;
|
||||
|
||||
public FileManager(TestLog log)
|
||||
{
|
||||
if (!Directory.Exists(Folder)) Directory.CreateDirectory(Folder);
|
||||
if (!Directory.Exists(FileManagerConfig.Folder)) Directory.CreateDirectory(FileManagerConfig.Folder);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public TestFile CreateEmptyTestFile()
|
||||
{
|
||||
var result = new TestFile(Path.Combine(Folder, Guid.NewGuid().ToString() + "_test.bin"));
|
||||
var result = new TestFile(Path.Combine(FileManagerConfig.Folder, Guid.NewGuid().ToString() + "_test.bin"));
|
||||
File.Create(result.Filename).Close();
|
||||
activeFiles.Add(result);
|
||||
return result;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using k8s;
|
||||
using CodexDistTestCore.Config;
|
||||
using k8s;
|
||||
using k8s.Models;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
@ -6,9 +7,8 @@ namespace CodexDistTestCore
|
|||
{
|
||||
public class K8sOperations
|
||||
{
|
||||
public const string K8sNamespace = "codex-test-namespace";
|
||||
|
||||
private readonly CodexDockerImage dockerImage = new CodexDockerImage();
|
||||
private readonly K8sCluster k8SCluster = new K8sCluster();
|
||||
private readonly Kubernetes client;
|
||||
private readonly KnownK8sPods knownPods;
|
||||
|
||||
|
@ -16,9 +16,7 @@ namespace CodexDistTestCore
|
|||
{
|
||||
this.knownPods = knownPods;
|
||||
|
||||
// todo: If the default KubeConfig file does not suffice, change it here:
|
||||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
||||
client = new Kubernetes(config);
|
||||
client = new Kubernetes(k8SCluster.GetK8sClientConfig());
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
@ -220,18 +218,12 @@ namespace CodexDistTestCore
|
|||
|
||||
private IDictionary<string, string> CreateNodeSelector(OfflineCodexNodes offline)
|
||||
{
|
||||
switch (offline.Location)
|
||||
{
|
||||
case Location.Unspecified:
|
||||
return new Dictionary<string, string>();
|
||||
case Location.BensLaptop:
|
||||
return new Dictionary<string, string> { { "codex-test-location", "worker01" } };
|
||||
case Location.BensOldGamingMachine:
|
||||
return new Dictionary<string, string> { { "codex-test-location", "worker02" } };
|
||||
}
|
||||
if (offline.Location == Location.Unspecified) return new Dictionary<string, string>();
|
||||
|
||||
Assert.Fail("Unknown location selected: " + offline.Location);
|
||||
throw new InvalidOperationException();
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ "codex-test-location", k8SCluster.GetNodeLabelForLocation(offline.Location) }
|
||||
};
|
||||
}
|
||||
|
||||
private List<V1Container> CreateDeploymentContainers(CodexNodeGroup online, OfflineCodexNodes offline)
|
||||
|
@ -293,6 +285,11 @@ namespace CodexDistTestCore
|
|||
}
|
||||
}
|
||||
|
||||
private string K8sNamespace
|
||||
{
|
||||
get { return K8sCluster.K8sNamespace; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private bool IsTestNamespaceOnline()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using NUnit.Framework;
|
||||
using CodexDistTestCore.Config;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CodexDistTestCore
|
||||
{
|
||||
|
@ -15,6 +16,7 @@ namespace CodexDistTestCore
|
|||
private const string SuccessfullyConnectedMessage = "Successfully connected to peer";
|
||||
private const string UploadFailedMessage = "Unable to store block";
|
||||
|
||||
private readonly K8sCluster k8SCluster = new K8sCluster();
|
||||
private readonly TestLog log;
|
||||
private readonly IFileManager fileManager;
|
||||
|
||||
|
@ -101,7 +103,7 @@ namespace CodexDistTestCore
|
|||
|
||||
private Http Http()
|
||||
{
|
||||
return new Http(ip: "127.0.0.1", port: Container.ServicePort, baseUrl: "/api/codex/v1");
|
||||
return new Http(ip: k8SCluster.GetIp(), port: Container.ServicePort, baseUrl: "/api/codex/v1");
|
||||
}
|
||||
|
||||
private void Log(string msg)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using NUnit.Framework;
|
||||
using CodexDistTestCore.Config;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CodexDistTestCore
|
||||
{
|
||||
public class TestLog
|
||||
{
|
||||
public const string LogRoot = "D:/CodexTestLogs";
|
||||
private readonly LogFile file;
|
||||
|
||||
public TestLog()
|
||||
|
@ -105,7 +105,7 @@ namespace CodexDistTestCore
|
|||
var now = DateTime.UtcNow;
|
||||
|
||||
filepath = Path.Join(
|
||||
TestLog.LogRoot,
|
||||
LogConfig.LogRoot,
|
||||
$"{now.Year}-{Pad(now.Month)}",
|
||||
Pad(now.Day));
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using CodexDistTestCore;
|
||||
using CodexDistTestCore.Config;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests.BasicTests
|
||||
|
|
Loading…
Reference in New Issue