2
0
mirror of synced 2025-01-11 17:14:25 +00:00

Successful spin-up of geth companion node

This commit is contained in:
benbierens 2023-04-10 14:48:16 +02:00
parent e800197cdd
commit ab8318e102
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
8 changed files with 136 additions and 37 deletions

View File

@ -1,8 +1,10 @@
namespace CodexDistTestCore using CodexDistTestCore.Marketplace;
namespace CodexDistTestCore
{ {
public class CodexNodeContainer public class CodexNodeContainer
{ {
public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir, int metricsPort) public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir, int metricsPort, GethCompanionNodeContainer? gethCompanionNodeContainer)
{ {
Name = name; Name = name;
ServicePort = servicePort; ServicePort = servicePort;
@ -13,6 +15,7 @@
ListenPort = listenPort; ListenPort = listenPort;
DataDir = dataDir; DataDir = dataDir;
MetricsPort = metricsPort; MetricsPort = metricsPort;
GethCompanionNodeContainer = gethCompanionNodeContainer;
} }
public string Name { get; } public string Name { get; }
@ -24,6 +27,8 @@
public int ListenPort { get; } public int ListenPort { get; }
public string DataDir { get; } public string DataDir { get; }
public int MetricsPort { get; } public int MetricsPort { get; }
public GethCompanionNodeContainer? GethCompanionNodeContainer { get; }
} }
public class CodexGroupNumberSource public class CodexGroupNumberSource
@ -71,7 +76,8 @@
discoveryPort: codexPortSource.GetNextNumber(), discoveryPort: codexPortSource.GetNextNumber(),
listenPort: codexPortSource.GetNextNumber(), listenPort: codexPortSource.GetNextNumber(),
dataDir: $"datadir{n}", dataDir: $"datadir{n}",
metricsPort: GetMetricsPort(offline) metricsPort: GetMetricsPort(offline),
CreateGethNodeContainer(offline, n)
); );
} }
@ -80,5 +86,18 @@
if (offline.MetricsEnabled) return codexPortSource.GetNextNumber(); if (offline.MetricsEnabled) return codexPortSource.GetNextNumber();
return 0; return 0;
} }
private GethCompanionNodeContainer? CreateGethNodeContainer(OfflineCodexNodes offline, int n)
{
if (offline.MarketplaceConfig == null) return null;
return new GethCompanionNodeContainer(
name: $"geth-node{n}",
servicePort: groupContainerFactory.GetNextServicePort(),
servicePortName: groupContainerFactory.GetNextServicePortName(),
apiPort: codexPortSource.GetNextNumber(),
containerPortName: $"geth-{n}"
);
}
} }
} }

View File

@ -1,4 +1,5 @@
using CodexDistTestCore.Config; using CodexDistTestCore.Config;
using CodexDistTestCore.Marketplace;
using k8s.Models; using k8s.Models;
using System.Collections; using System.Collections;
@ -45,6 +46,7 @@ namespace CodexDistTestCore
public V1Deployment? Deployment { get; set; } public V1Deployment? Deployment { get; set; }
public V1Service? Service { get; set; } public V1Service? Service { get; set; }
public PodInfo? PodInfo { get; set; } public PodInfo? PodInfo { get; set; }
public GethInfo? GethInfo { get; set; }
public CodexNodeContainer[] GetContainers() public CodexNodeContainer[] GetContainers()
{ {

View File

@ -34,7 +34,7 @@ namespace CodexDistTestCore
if (offline.MarketplaceConfig != null) if (offline.MarketplaceConfig != null)
{ {
BringOnlineMarketplace(); online.GethInfo = BringOnlineMarketplace();
} }
K8s(k => k.BringOnline(online, offline)); K8s(k => k.BringOnline(online, offline));
@ -87,7 +87,7 @@ namespace CodexDistTestCore
return K8s(k => k.BringOnlinePrometheus(spec)); return K8s(k => k.BringOnlinePrometheus(spec));
} }
public PodInfo BringOnlineGethBootstrapNode() public GethInfo BringOnlineGethBootstrapNode()
{ {
var spec = new K8sGethBoostrapSpecs(codexGroupNumberSource.GetNextServicePort()); var spec = new K8sGethBoostrapSpecs(codexGroupNumberSource.GetNextServicePort());
@ -104,9 +104,9 @@ namespace CodexDistTestCore
metricsAggregator.BeginCollectingMetricsFor(DowncastNodes(group)); metricsAggregator.BeginCollectingMetricsFor(DowncastNodes(group));
} }
private void BringOnlineMarketplace() private GethInfo BringOnlineMarketplace()
{ {
marketplaceController.BringOnlineMarketplace(); return marketplaceController.BringOnlineMarketplace();
} }
private CodexNodeGroup CreateOnlineCodexNodes(OfflineCodexNodes offline) private CodexNodeGroup CreateOnlineCodexNodes(OfflineCodexNodes offline)

View File

@ -2,10 +2,9 @@
using CodexDistTestCore.Marketplace; using CodexDistTestCore.Marketplace;
using CodexDistTestCore.Metrics; using CodexDistTestCore.Metrics;
using k8s; using k8s;
using k8s.KubeConfigModels;
using k8s.Models; using k8s.Models;
using Nethereum.Merkle.Patricia;
using NUnit.Framework; using NUnit.Framework;
using System.Numerics;
namespace CodexDistTestCore namespace CodexDistTestCore
{ {
@ -79,7 +78,7 @@ namespace CodexDistTestCore
return new PrometheusInfo(spec.ServicePort, FetchNewPod()); return new PrometheusInfo(spec.ServicePort, FetchNewPod());
} }
public PodInfo BringOnlineGethBootstrapNode(K8sGethBoostrapSpecs spec) public GethInfo BringOnlineGethBootstrapNode(K8sGethBoostrapSpecs spec)
{ {
EnsureTestNamespace(); EnsureTestNamespace();
@ -87,7 +86,7 @@ namespace CodexDistTestCore
CreateGethBootstrapService(spec); CreateGethBootstrapService(spec);
WaitUntilGethBootstrapOnline(spec); WaitUntilGethBootstrapOnline(spec);
return FetchNewPod(); return new GethInfo(spec, FetchNewPod());
} }
private void FetchPodInfo(CodexNodeGroup online) private void FetchPodInfo(CodexNodeGroup online)
@ -213,6 +212,11 @@ namespace CodexDistTestCore
TargetPort = container.ContainerPortName, TargetPort = container.ContainerPortName,
NodePort = container.ServicePort NodePort = container.ServicePort
}); });
if (container.GethCompanionNodeContainer != null)
{
result.Add(container.GethCompanionNodeContainer.CreateServicePort());
}
} }
return result; return result;
} }
@ -299,6 +303,11 @@ namespace CodexDistTestCore
}, },
Env = dockerImage.CreateEnvironmentVariables(offline, container) Env = dockerImage.CreateEnvironmentVariables(offline, container)
}); });
if (container.GethCompanionNodeContainer != null)
{
result.Add(container.GethCompanionNodeContainer.CreateDeploymentContainer(online.GethInfo!));
}
} }
return result; return result;

View File

@ -0,0 +1,53 @@
using k8s.Models;
namespace CodexDistTestCore.Marketplace
{
public class GethCompanionNodeContainer
{
public GethCompanionNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName)
{
Name = name;
ServicePort = servicePort;
ServicePortName = servicePortName;
ApiPort = apiPort;
ContainerPortName = containerPortName;
}
public string Name { get; }
public int ServicePort { get; }
public string ServicePortName { get; }
public int ApiPort { get; }
public string ContainerPortName { get; }
public V1Container CreateDeploymentContainer(GethInfo gethInfo)
{
return new V1Container
{
Name = Name,
Image = GethDockerImage.Image,
Ports = new List<V1ContainerPort>
{
new V1ContainerPort
{
ContainerPort = ApiPort,
Name = ContainerPortName
}
},
// todo: use env vars to connect this node to the bootstrap node provided by gethInfo.podInfo & gethInfo.servicePort & gethInfo.genesisJsonBase64
//Env = dockerImage.CreateEnvironmentVariables(offline, container)
};
}
public V1ServicePort CreateServicePort()
{
return new V1ServicePort
{
Name = ServicePortName,
Protocol = "TCP",
Port = ApiPort,
TargetPort = ContainerPortName,
NodePort = ServicePort
};
}
}
}

View File

@ -3,10 +3,14 @@ using k8s.Models;
namespace CodexDistTestCore.Marketplace namespace CodexDistTestCore.Marketplace
{ {
public static class GethDockerImage
{
public const string Image = "thatbenbierens/geth-confenv:latest";
}
public class K8sGethBoostrapSpecs public class K8sGethBoostrapSpecs
{ {
public const string ContainerName = "dtest-gethb"; public const string ContainerName = "dtest-gethb";
private const string dockerImage = "thatbenbierens/geth-confenv:latest";
private const string portName = "gethb"; private const string portName = "gethb";
private const string genesisJsonBase64 = "ewogICAgImNvbmZpZyI6IHsKICAgICAgImNoYWluSWQiOiAxMjM0NSwKICAgICAgImhvbWVzdGVhZEJsb2NrIjogMCwKICAgICAgImVpcDE1MEJsb2NrIjogMCwKICAgICAgImVpcDE1NUJsb2NrIjogMCwKICAgICAgImVpcDE1OEJsb2NrIjogMCwKICAgICAgImJ5emFudGl1bUJsb2NrIjogMCwKICAgICAgImNvbnN0YW50aW5vcGxlQmxvY2siOiAwLAogICAgICAicGV0ZXJzYnVyZ0Jsb2NrIjogMCwKICAgICAgImlzdGFuYnVsQmxvY2siOiAwLAogICAgICAibXVpckdsYWNpZXJCbG9jayI6IDAsCiAgICAgICJiZXJsaW5CbG9jayI6IDAsCiAgICAgICJsb25kb25CbG9jayI6IDAsCiAgICAgICJhcnJvd0dsYWNpZXJCbG9jayI6IDAsCiAgICAgICJncmF5R2xhY2llckJsb2NrIjogMCwKICAgICAgImNsaXF1ZSI6IHsKICAgICAgICAicGVyaW9kIjogNSwKICAgICAgICAiZXBvY2giOiAzMDAwMAogICAgICB9CiAgICB9LAogICAgImRpZmZpY3VsdHkiOiAiMSIsCiAgICAiZ2FzTGltaXQiOiAiODAwMDAwMDAwIiwKICAgICJleHRyYWRhdGEiOiAiMHgwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwN2RmOWE4NzVhMTc0YjNiYzU2NWU2NDI0YTAwNTBlYmMxYjJkMWQ4MjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLAogICAgImFsbG9jIjogewogICAgICAiQUNDT1VOVF9IRVJFIjogeyAiYmFsYW5jZSI6ICI1MDAwMDAiIH0KICAgIH0KICB9"; private const string genesisJsonBase64 = "ewogICAgImNvbmZpZyI6IHsKICAgICAgImNoYWluSWQiOiAxMjM0NSwKICAgICAgImhvbWVzdGVhZEJsb2NrIjogMCwKICAgICAgImVpcDE1MEJsb2NrIjogMCwKICAgICAgImVpcDE1NUJsb2NrIjogMCwKICAgICAgImVpcDE1OEJsb2NrIjogMCwKICAgICAgImJ5emFudGl1bUJsb2NrIjogMCwKICAgICAgImNvbnN0YW50aW5vcGxlQmxvY2siOiAwLAogICAgICAicGV0ZXJzYnVyZ0Jsb2NrIjogMCwKICAgICAgImlzdGFuYnVsQmxvY2siOiAwLAogICAgICAibXVpckdsYWNpZXJCbG9jayI6IDAsCiAgICAgICJiZXJsaW5CbG9jayI6IDAsCiAgICAgICJsb25kb25CbG9jayI6IDAsCiAgICAgICJhcnJvd0dsYWNpZXJCbG9jayI6IDAsCiAgICAgICJncmF5R2xhY2llckJsb2NrIjogMCwKICAgICAgImNsaXF1ZSI6IHsKICAgICAgICAicGVyaW9kIjogNSwKICAgICAgICAiZXBvY2giOiAzMDAwMAogICAgICB9CiAgICB9LAogICAgImRpZmZpY3VsdHkiOiAiMSIsCiAgICAiZ2FzTGltaXQiOiAiODAwMDAwMDAwIiwKICAgICJleHRyYWRhdGEiOiAiMHgwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwN2RmOWE4NzVhMTc0YjNiYzU2NWU2NDI0YTAwNTBlYmMxYjJkMWQ4MjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLAogICAgImFsbG9jIjogewogICAgICAiQUNDT1VOVF9IRVJFIjogeyAiYmFsYW5jZSI6ICI1MDAwMDAiIH0KICAgIH0KICB9";
@ -52,7 +56,7 @@ namespace CodexDistTestCore.Marketplace
new V1Container new V1Container
{ {
Name = ContainerName, Name = ContainerName,
Image = dockerImage, Image = GethDockerImage.Image,
Ports = new List<V1ContainerPort> Ports = new List<V1ContainerPort>
{ {
new V1ContainerPort new V1ContainerPort

View File

@ -1,4 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
using System.Text;
namespace CodexDistTestCore.Marketplace namespace CodexDistTestCore.Marketplace
{ {
@ -6,7 +7,7 @@ namespace CodexDistTestCore.Marketplace
{ {
private readonly TestLog log; private readonly TestLog log;
private readonly K8sManager k8sManager; private readonly K8sManager k8sManager;
private PodInfo? gethBootstrapNode; private GethInfo? gethBootstrapNode;
private string bootstrapAccount = string.Empty; private string bootstrapAccount = string.Empty;
private string bootstrapGenesisJson = string.Empty; private string bootstrapGenesisJson = string.Empty;
@ -16,14 +17,16 @@ namespace CodexDistTestCore.Marketplace
this.k8sManager = k8sManager; this.k8sManager = k8sManager;
} }
public void BringOnlineMarketplace() public GethInfo BringOnlineMarketplace()
{ {
if (gethBootstrapNode != null) return; if (gethBootstrapNode != null) return gethBootstrapNode;
log.Log("Starting Geth bootstrap node..."); log.Log("Starting Geth bootstrap node...");
gethBootstrapNode = k8sManager.BringOnlineGethBootstrapNode(); gethBootstrapNode = k8sManager.BringOnlineGethBootstrapNode();
ExtractAccountAndGenesisJson(); ExtractAccountAndGenesisJson();
log.Log("Geth boothstrap node started."); log.Log("Geth boothstrap node started.");
return gethBootstrapNode;
} }
private void ExtractAccountAndGenesisJson() private void ExtractAccountAndGenesisJson()
@ -33,11 +36,26 @@ namespace CodexDistTestCore.Marketplace
Assert.That(bootstrapAccount, Is.Not.Empty, "Unable to fetch account for bootstrap geth node. Test infra failure."); Assert.That(bootstrapAccount, Is.Not.Empty, "Unable to fetch account for bootstrap geth node. Test infra failure.");
Assert.That(bootstrapGenesisJson, Is.Not.Empty, "Unable to fetch genesis-json for bootstrap geth node. Test infra failure."); Assert.That(bootstrapGenesisJson, Is.Not.Empty, "Unable to fetch genesis-json for bootstrap geth node. Test infra failure.");
gethBootstrapNode!.GenesisJsonBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(bootstrapGenesisJson));
} }
private string ExecuteCommand(string command, params string[] arguments) private string ExecuteCommand(string command, params string[] arguments)
{ {
return k8sManager.ExecuteCommand(gethBootstrapNode!, K8sGethBoostrapSpecs.ContainerName, command, arguments); return k8sManager.ExecuteCommand(gethBootstrapNode!.Pod, K8sGethBoostrapSpecs.ContainerName, command, arguments);
} }
} }
public class GethInfo
{
public GethInfo(K8sGethBoostrapSpecs spec, PodInfo pod)
{
Spec = spec;
Pod = pod;
}
public K8sGethBoostrapSpecs Spec { get; }
public PodInfo Pod { get; }
public string GenesisJsonBase64 { get; set; } = string.Empty;
}
} }

View File

@ -6,14 +6,6 @@ namespace Tests.BasicTests
[TestFixture] [TestFixture]
public class SimpleTests : DistTest public class SimpleTests : DistTest
{ {
[Test]
public void DoCommand()
{
var primary = SetupCodexNodes(1).BringOnline()[0];
k8sManager.ExampleOfCMD(primary);
}
[Test] [Test]
public void TwoMetricsExample() public void TwoMetricsExample()
{ {
@ -47,22 +39,24 @@ namespace Tests.BasicTests
.EnableMarketplace(initialBalance: 20) .EnableMarketplace(initialBalance: 20)
.BringOnline()[0]; .BringOnline()[0];
var secondary = SetupCodexNodes(1) //var secondary = SetupCodexNodes(1)
.EnableMarketplace(initialBalance: 1000) // .EnableMarketplace(initialBalance: 1000)
.BringOnline()[0]; // .BringOnline()[0];
primary.ConnectToPeer(secondary); //primary.ConnectToPeer(secondary);
primary.Marketplace.AdvertiseStorage(10.GB(), pricePerMBPerSecond: 0.01f, collateral: 20); //primary.Marketplace.AdvertiseStorage(10.GB(), pricePerMBPerSecond: 0.01f, collateral: 20);
var testFile = GenerateTestFile(10.MB()); //var testFile = GenerateTestFile(10.MB());
var contentId = secondary.UploadFile(testFile); //var contentId = secondary.UploadFile(testFile);
secondary.Marketplace.AdvertiseContract(contentId, maxPricePerMBPerSecond: 0.02f, minRequiredCollateral: 10, minRequiredNumberOfDuplicates: 1); //secondary.Marketplace.AdvertiseContract(contentId, maxPricePerMBPerSecond: 0.02f, minRequiredCollateral: 10, minRequiredNumberOfDuplicates: 1);
primary.Marketplace.AssertThatBalance(Is.LessThan(20), "Collateral was not placed."); //primary.Marketplace.AssertThatBalance(Is.LessThan(20), "Collateral was not placed.");
var primaryBalance = primary.Marketplace.GetBalance(); //var primaryBalance = primary.Marketplace.GetBalance();
secondary.Marketplace.AssertThatBalance(Is.LessThan(1000), "Contractor was not charged for storage."); //secondary.Marketplace.AssertThatBalance(Is.LessThan(1000), "Contractor was not charged for storage.");
primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage."); //primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage.");
var aa = 0;
} }
[Test] [Test]