mirror of
https://github.com/vacp2p/cs-codex-dist-tests.git
synced 2025-02-23 15:58:21 +00:00
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;
|
using System.Collections;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore
|
||||||
@ -63,7 +64,7 @@ namespace CodexDistTestCore
|
|||||||
return new V1ObjectMeta
|
return new V1ObjectMeta
|
||||||
{
|
{
|
||||||
Name = "codex-test-entrypoint-" + OrderNumber,
|
Name = "codex-test-entrypoint-" + OrderNumber,
|
||||||
NamespaceProperty = K8sOperations.K8sNamespace
|
NamespaceProperty = K8sCluster.K8sNamespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ namespace CodexDistTestCore
|
|||||||
return new V1ObjectMeta
|
return new V1ObjectMeta
|
||||||
{
|
{
|
||||||
Name = "codex-test-node-" + OrderNumber,
|
Name = "codex-test-node-" + OrderNumber,
|
||||||
NamespaceProperty = K8sOperations.K8sNamespace
|
NamespaceProperty = K8sCluster.K8sNamespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using k8s.Models;
|
using k8s.Models;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore.Config
|
||||||
{
|
{
|
||||||
public class CodexDockerImage
|
public class CodexDockerImage
|
||||||
{
|
{
|
7
CodexDistTestCore/Config/FileManagerConfig.cs
Normal file
7
CodexDistTestCore/Config/FileManagerConfig.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace CodexDistTestCore.Config
|
||||||
|
{
|
||||||
|
public class FileManagerConfig
|
||||||
|
{
|
||||||
|
public const string Folder = "TestDataFiles";
|
||||||
|
}
|
||||||
|
}
|
37
CodexDistTestCore/Config/K8sCluster.cs
Normal file
37
CodexDistTestCore/Config/K8sCluster.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
CodexDistTestCore/Config/LogConfig.cs
Normal file
7
CodexDistTestCore/Config/LogConfig.cs
Normal file
@ -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
|
namespace CodexDistTestCore
|
||||||
{
|
{
|
||||||
@ -12,20 +13,19 @@ namespace CodexDistTestCore
|
|||||||
public class FileManager : IFileManager
|
public class FileManager : IFileManager
|
||||||
{
|
{
|
||||||
public const int ChunkSize = 1024 * 1024;
|
public const int ChunkSize = 1024 * 1024;
|
||||||
private const string Folder = "TestDataFiles";
|
|
||||||
private readonly Random random = new Random();
|
private readonly Random random = new Random();
|
||||||
private readonly List<TestFile> activeFiles = new List<TestFile>();
|
private readonly List<TestFile> activeFiles = new List<TestFile>();
|
||||||
private readonly TestLog log;
|
private readonly TestLog log;
|
||||||
|
|
||||||
public FileManager(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;
|
this.log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestFile CreateEmptyTestFile()
|
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();
|
File.Create(result.Filename).Close();
|
||||||
activeFiles.Add(result);
|
activeFiles.Add(result);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using k8s;
|
using CodexDistTestCore.Config;
|
||||||
|
using k8s;
|
||||||
using k8s.Models;
|
using k8s.Models;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
@ -6,9 +7,8 @@ namespace CodexDistTestCore
|
|||||||
{
|
{
|
||||||
public class K8sOperations
|
public class K8sOperations
|
||||||
{
|
{
|
||||||
public const string K8sNamespace = "codex-test-namespace";
|
|
||||||
|
|
||||||
private readonly CodexDockerImage dockerImage = new CodexDockerImage();
|
private readonly CodexDockerImage dockerImage = new CodexDockerImage();
|
||||||
|
private readonly K8sCluster k8SCluster = new K8sCluster();
|
||||||
private readonly Kubernetes client;
|
private readonly Kubernetes client;
|
||||||
private readonly KnownK8sPods knownPods;
|
private readonly KnownK8sPods knownPods;
|
||||||
|
|
||||||
@ -16,9 +16,7 @@ namespace CodexDistTestCore
|
|||||||
{
|
{
|
||||||
this.knownPods = knownPods;
|
this.knownPods = knownPods;
|
||||||
|
|
||||||
// todo: If the default KubeConfig file does not suffice, change it here:
|
client = new Kubernetes(k8SCluster.GetK8sClientConfig());
|
||||||
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
|
|
||||||
client = new Kubernetes(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
@ -220,18 +218,12 @@ namespace CodexDistTestCore
|
|||||||
|
|
||||||
private IDictionary<string, string> CreateNodeSelector(OfflineCodexNodes offline)
|
private IDictionary<string, string> CreateNodeSelector(OfflineCodexNodes offline)
|
||||||
{
|
{
|
||||||
switch (offline.Location)
|
if (offline.Location == Location.Unspecified) return new Dictionary<string, string>();
|
||||||
{
|
|
||||||
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" } };
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.Fail("Unknown location selected: " + offline.Location);
|
return new Dictionary<string, string>
|
||||||
throw new InvalidOperationException();
|
{
|
||||||
|
{ "codex-test-location", k8SCluster.GetNodeLabelForLocation(offline.Location) }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<V1Container> CreateDeploymentContainers(CodexNodeGroup online, OfflineCodexNodes offline)
|
private List<V1Container> CreateDeploymentContainers(CodexNodeGroup online, OfflineCodexNodes offline)
|
||||||
@ -293,6 +285,11 @@ namespace CodexDistTestCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string K8sNamespace
|
||||||
|
{
|
||||||
|
get { return K8sCluster.K8sNamespace; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private bool IsTestNamespaceOnline()
|
private bool IsTestNamespaceOnline()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using NUnit.Framework;
|
using CodexDistTestCore.Config;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore
|
||||||
{
|
{
|
||||||
@ -15,6 +16,7 @@ namespace CodexDistTestCore
|
|||||||
private const string SuccessfullyConnectedMessage = "Successfully connected to peer";
|
private const string SuccessfullyConnectedMessage = "Successfully connected to peer";
|
||||||
private const string UploadFailedMessage = "Unable to store block";
|
private const string UploadFailedMessage = "Unable to store block";
|
||||||
|
|
||||||
|
private readonly K8sCluster k8SCluster = new K8sCluster();
|
||||||
private readonly TestLog log;
|
private readonly TestLog log;
|
||||||
private readonly IFileManager fileManager;
|
private readonly IFileManager fileManager;
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ namespace CodexDistTestCore
|
|||||||
|
|
||||||
private Http Http()
|
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)
|
private void Log(string msg)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using NUnit.Framework;
|
using CodexDistTestCore.Config;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace CodexDistTestCore
|
namespace CodexDistTestCore
|
||||||
{
|
{
|
||||||
public class TestLog
|
public class TestLog
|
||||||
{
|
{
|
||||||
public const string LogRoot = "D:/CodexTestLogs";
|
|
||||||
private readonly LogFile file;
|
private readonly LogFile file;
|
||||||
|
|
||||||
public TestLog()
|
public TestLog()
|
||||||
@ -105,7 +105,7 @@ namespace CodexDistTestCore
|
|||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
|
|
||||||
filepath = Path.Join(
|
filepath = Path.Join(
|
||||||
TestLog.LogRoot,
|
LogConfig.LogRoot,
|
||||||
$"{now.Year}-{Pad(now.Month)}",
|
$"{now.Year}-{Pad(now.Month)}",
|
||||||
Pad(now.Day));
|
Pad(now.Day));
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using CodexDistTestCore;
|
using CodexDistTestCore;
|
||||||
|
using CodexDistTestCore.Config;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace Tests.BasicTests
|
namespace Tests.BasicTests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user