wip: setting up access to geth and contracts for transient nodes

This commit is contained in:
Ben 2024-03-21 08:31:00 +01:00
parent 32807f3f8c
commit 760d0211c6
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
6 changed files with 101 additions and 102 deletions

View File

@ -9,7 +9,7 @@ namespace CodexPlugin
public CodexDeployment(CodexInstance[] codexInstances, GethDeployment gethDeployment,
CodexContractsDeployment codexContractsDeployment, RunningContainers? prometheusContainer,
RunningContainers? discordBotContainer, DeploymentMetadata metadata,
String id)
string id)
{
Id = id;
CodexInstances = codexInstances;
@ -20,7 +20,7 @@ namespace CodexPlugin
Metadata = metadata;
}
public String Id { get; }
public string Id { get; }
public CodexInstance[] CodexInstances { get; }
public GethDeployment GethDeployment { get; }
public CodexContractsDeployment CodexContractsDeployment { get; }

View File

@ -1,6 +1,8 @@
using CodexPlugin;
using CodexContractsPlugin;
using CodexPlugin;
using Core;
using FileUtils;
using GethPlugin;
using Logging;
using MetricsPlugin;
@ -31,7 +33,7 @@ namespace ContinuousTests
if (nodes != null)
{
NodeRunner = new NodeRunner(Nodes, configuration, Log, CustomK8sNamespace);
NodeRunner = new NodeRunner(Nodes, configuration, Log);
}
else
{
@ -56,15 +58,23 @@ namespace ContinuousTests
{
if (Configuration.CodexDeployment.PrometheusContainer == null) throw new Exception("Expected prometheus to be part of Codex deployment.");
var entryPointFactory = new EntryPointFactory();
var entryPoint = entryPointFactory.CreateEntryPoint(Configuration.KubeConfigFile, Configuration.DataPath, Configuration.CodexDeployment.Metadata.KubeNamespace, Log);
return entryPoint.CreateInterface().WrapMetricsCollector(Configuration.CodexDeployment.PrometheusContainer, target);
var ci = CreateCi();
return ci.WrapMetricsCollector(Configuration.CodexDeployment.PrometheusContainer, target);
}
public (IGethNode, ICodexContracts) CreateMarketplaceAccess()
{
var ci = CreateCi();
var geth = ci.WrapGethDeployment(Configuration.CodexDeployment.GethDeployment);
var contracts = ci.WrapCodexContractsDeployment(geth, Configuration.CodexDeployment.CodexContractsDeployment);
return (geth, contracts);
}
public abstract int RequiredNumberOfNodes { get; }
public abstract TimeSpan RunTestEvery { get; }
public abstract TestFailMode TestFailMode { get; }
public virtual string CustomK8sNamespace { get { return string.Empty; } }
public string Name
{
@ -73,6 +83,13 @@ namespace ContinuousTests
return GetType().Name;
}
}
private CoreInterface CreateCi()
{
var entryPointFactory = new EntryPointFactory();
var entryPoint = entryPointFactory.CreateEntryPoint(Configuration.KubeConfigFile, Configuration.DataPath, Configuration.CodexDeployment.Metadata.KubeNamespace, Log);
return entryPoint.CreateInterface();
}
}
public enum TestFailMode

View File

@ -51,8 +51,6 @@ namespace ContinuousTests
overviewLog.Log("");
var allTests = testFactory.CreateTests();
ClearAllCustomNamespaces(allTests, overviewLog);
var filteredTests = FilterTests(allTests, overviewLog);
if (!filteredTests.Any())
{
@ -136,21 +134,6 @@ namespace ContinuousTests
return result;
}
private void ClearAllCustomNamespaces(ContinuousTest[] allTests, ILog log)
{
foreach (var test in allTests) ClearAllCustomNamespaces(test, log);
}
private void ClearAllCustomNamespaces(ContinuousTest test, ILog log)
{
if (string.IsNullOrEmpty(test.CustomK8sNamespace)) return;
log.Log($"Clearing namespace '{test.CustomK8sNamespace}'...");
var entryPoint = entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, test.CustomK8sNamespace, log);
entryPoint.Tools.CreateWorkflow().DeleteNamespacesStartingWith(test.CustomK8sNamespace);
}
private void PerformCleanup(ILog log)
{
if (!config.Cleanup) return;

View File

@ -25,7 +25,6 @@ namespace ContinuousTests
);
return new EntryPoint(log, lifecycleConfig, dataFilePath);
//DefaultContainerRecipe.TestsType = "continuous-tests";
}
private static string? GetKubeConfig(string kubeConfigFile)

View File

@ -13,14 +13,12 @@ namespace ContinuousTests
private readonly ICodexNode[] nodes;
private readonly Configuration config;
private readonly ILog log;
private readonly string customNamespace;
public NodeRunner(ICodexNode[] nodes, Configuration config, ILog log, string customNamespace)
public NodeRunner(ICodexNode[] nodes, Configuration config, ILog log)
{
this.nodes = nodes;
this.config = config;
this.log = log;
this.customNamespace = customNamespace;
}
public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null)
@ -41,8 +39,6 @@ namespace ContinuousTests
// Therefore, we use the image of the bootstrap node.
CodexContainerRecipe.DockerImageOverride = bootstrapNode.Container.Recipe.Image;
try
{
var debugInfo = bootstrapNode.GetDebugInfo();
Assert.That(!string.IsNullOrEmpty(debugInfo.spr));
@ -59,18 +55,18 @@ namespace ContinuousTests
catch
{
DownloadLog(node.Container);
node.Stop();
throw;
}
}
finally
{
entryPoint.Tools.CreateWorkflow().DeleteNamespace();
node.Stop();
}
}
private EntryPoint CreateEntryPoint()
{
return entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, customNamespace, log);
return entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, config.CodexDeployment.Metadata.KubeNamespace, log);
}
}
}

View File

@ -1,64 +1,68 @@
//using DistTestCore;
//using DistTestCore.Codex;
//using Newtonsoft.Json;
//using NUnit.Framework;
//using Utils;
using CodexContractsPlugin;
using CodexPlugin;
using FileUtils;
using NUnit.Framework;
using Utils;
//namespace ContinuousTests.Tests
//{
// public class MarketplaceTest : ContinuousTest
// {
// public override int RequiredNumberOfNodes => 1;
// public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(10);
// public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure;
// public override int EthereumAccountIndex => 200;
// public override string CustomK8sNamespace => "codex-continuous-marketplace";
// private readonly uint numberOfSlots = 3;
// private readonly ByteSize fileSize = 10.MB();
// private readonly TestToken pricePerSlotPerSecond = 10.TestTokens();
/// manual test locally.
// private TestFile file = null!;
// private ContentId? cid;
// private string purchaseId = string.Empty;
// [TestMoment(t: Zero)]
// public void NodePostsStorageRequest()
// {
// var contractDuration = TimeSpan.FromMinutes(8);
// decimal totalDurationSeconds = Convert.ToDecimal(contractDuration.TotalSeconds);
// var expectedTotalCost = numberOfSlots * pricePerSlotPerSecond.Amount * (totalDurationSeconds + 1) * 1000000;
namespace ContinuousTests.Tests
{
public class MarketplaceTest : ContinuousTest
{
public override int RequiredNumberOfNodes => 1;
public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(10);
public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure;
// file = FileManager.GenerateTestFile(fileSize);
private readonly uint numberOfSlots = 3;
private readonly ByteSize fileSize = 10.MB();
private readonly TestToken pricePerSlotPerSecond = 10.TestTokens();
// NodeRunner.RunNode((codexAccess, marketplaceAccess) =>
// {
// cid = UploadFile(codexAccess.Node, file);
// Assert.That(cid, Is.Not.Null);
private TrackedFile file = null!;
private ContentId? cid;
private string purchaseId = string.Empty;
// purchaseId = marketplaceAccess.RequestStorage(
// contentId: cid!,
// pricePerSlotPerSecond: pricePerSlotPerSecond,
// requiredCollateral: 100.TestTokens(),
// minRequiredNumberOfNodes: numberOfSlots,
// proofProbability: 10,
// duration: contractDuration);
[TestMoment(t: Zero)]
public void NodePostsStorageRequest()
{
var contractDuration = TimeSpan.FromMinutes(8);
decimal totalDurationSeconds = Convert.ToDecimal(contractDuration.TotalSeconds);
var expectedTotalCost = numberOfSlots * pricePerSlotPerSecond.Amount * (totalDurationSeconds + 1) * 1000000;
// Assert.That(!string.IsNullOrEmpty(purchaseId));
file = FileManager.GenerateFile(fileSize);
// WaitForContractToStart(codexAccess, purchaseId);
// });
// }
NodeRunner.RunNode(
s => s.WithName("Buyer"),
node =>
{
cid = node.UploadFile(file);
Assert.That(cid, Is.Not.Null);
// [TestMoment(t: MinuteFive + MinuteOne)]
// public void StoredDataIsAvailableAfterThreeDays()
// {
// NodeRunner.RunNode((codexAccess, marketplaceAccess) =>
// {
// var result = DownloadFile(codexAccess.Node, cid!);
purchaseId = node.Marketplace.RequestStorage(
contentId: cid!,
pricePerSlotPerSecond: pricePerSlotPerSecond,
requiredCollateral: 100.TestTokens(),
minRequiredNumberOfNodes: numberOfSlots,
proofProbability: 10,
duration: contractDuration);
// file.AssertIsEqual(result);
// });
// }
// }
//}
Assert.That(!string.IsNullOrEmpty(purchaseId));
WaitForContractToStart(codexAccess, purchaseId);
});
}
[TestMoment(t: MinuteFive + MinuteOne)]
public void StoredDataIsAvailableAfterThreeDays()
{
NodeRunner.RunNode((codexAccess, marketplaceAccess) =>
{
var result = DownloadFile(codexAccess.Node, cid!);
file.AssertIsEqual(result);
});
}
}
}