This commit is contained in:
benbierens 2023-04-11 11:00:39 +02:00
parent 8a6ababba6
commit c977e37ab8
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
7 changed files with 75 additions and 94 deletions

View File

@ -1,10 +1,8 @@
using CodexDistTestCore.Marketplace;
namespace CodexDistTestCore
namespace CodexDistTestCore
{
public class CodexNodeContainer
{
public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir, int metricsPort, GethCompanionNodeContainer? gethCompanionNodeContainer)
public CodexNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName, int discoveryPort, int listenPort, string dataDir, int metricsPort)
{
Name = name;
ServicePort = servicePort;
@ -15,7 +13,6 @@ namespace CodexDistTestCore
ListenPort = listenPort;
DataDir = dataDir;
MetricsPort = metricsPort;
GethCompanionNodeContainer = gethCompanionNodeContainer;
}
public string Name { get; }
@ -27,8 +24,6 @@ namespace CodexDistTestCore
public int ListenPort { get; }
public string DataDir { get; }
public int MetricsPort { get; }
public GethCompanionNodeContainer? GethCompanionNodeContainer { get; }
}
public class CodexGroupNumberSource
@ -57,11 +52,11 @@ namespace CodexDistTestCore
{
private readonly NumberSource containerNameSource = new NumberSource(1);
private readonly NumberSource codexPortSource = new NumberSource(8080);
private readonly CodexGroupNumberSource groupContainerFactory;
private readonly CodexGroupNumberSource numberSource;
public CodexNodeContainerFactory(CodexGroupNumberSource groupContainerFactory)
public CodexNodeContainerFactory(CodexGroupNumberSource numberSource)
{
this.groupContainerFactory = groupContainerFactory;
this.numberSource = numberSource;
}
public CodexNodeContainer CreateNext(OfflineCodexNodes offline)
@ -69,15 +64,14 @@ namespace CodexDistTestCore
var n = containerNameSource.GetNextNumber();
return new CodexNodeContainer(
name: $"codex-node{n}",
servicePort: groupContainerFactory.GetNextServicePort(),
servicePortName: groupContainerFactory.GetNextServicePortName(),
servicePort: numberSource.GetNextServicePort(),
servicePortName: numberSource.GetNextServicePortName(),
apiPort: codexPortSource.GetNextNumber(),
containerPortName: $"api-{n}",
discoveryPort: codexPortSource.GetNextNumber(),
listenPort: codexPortSource.GetNextNumber(),
dataDir: $"datadir{n}",
metricsPort: GetMetricsPort(offline),
CreateGethNodeContainer(offline, n)
metricsPort: GetMetricsPort(offline)
);
}
@ -87,18 +81,5 @@ namespace CodexDistTestCore
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(),
rpcPort: codexPortSource.GetNextNumber(),
containerPortName: $"geth-{n}"
);
}
}
}

View File

@ -34,7 +34,7 @@ namespace CodexDistTestCore
if (offline.MarketplaceConfig != null)
{
group.GethInfo = BringOnlineMarketplace();
group.GethInfo = marketplaceController.BringOnlineMarketplace(offline);
}
K8s(k => k.BringOnline(group, offline));
@ -108,11 +108,6 @@ namespace CodexDistTestCore
metricsAggregator.BeginCollectingMetricsFor(DowncastNodes(group));
}
private GethInfo BringOnlineMarketplace()
{
return marketplaceController.BringOnlineMarketplace();
}
private void ConnectMarketplace(CodexNodeGroup group)
{
foreach (var node in DowncastNodes(group))

View File

@ -4,64 +4,18 @@ namespace CodexDistTestCore.Marketplace
{
public class GethCompanionNodeContainer
{
public GethCompanionNodeContainer(string name, int servicePort, string servicePortName, int apiPort, int rpcPort, string containerPortName)
public GethCompanionNodeContainer(string name, int apiPort, int rpcPort, string containerPortName)
{
Name = name;
ServicePort = servicePort;
ServicePortName = servicePortName;
ApiPort = apiPort;
RpcPort = rpcPort;
ContainerPortName = containerPortName;
}
public string Name { get; }
public int ServicePort { get; }
public string ServicePortName { get; }
public int ApiPort { get; }
public int RpcPort { 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 = new List<V1EnvVar>
{
new V1EnvVar
{
Name = "GETH_ARGS",
Value = $"--port {ApiPort} --discovery.port {ApiPort} --authrpc.port {RpcPort}"
},
new V1EnvVar
{
Name = "GENESIS_JSON",
Value = gethInfo.GenesisJsonBase64
}
}
};
}
public V1ServicePort CreateServicePort()
{
return new V1ServicePort
{
Name = ServicePortName,
Protocol = "TCP",
Port = ApiPort,
TargetPort = ContainerPortName,
NodePort = ServicePort
};
}
}
}

View File

@ -1,5 +1,6 @@
using CodexDistTestCore.Config;
using k8s.Models;
using System.Xml.Linq;
namespace CodexDistTestCore.Marketplace
{
@ -126,6 +127,37 @@ namespace CodexDistTestCore.Marketplace
return serviceSpec;
}
public V1Deployment CreateGethCompanionDeployment(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 = new List<V1EnvVar>
{
new V1EnvVar
{
Name = "GETH_ARGS",
Value = $"--port {ApiPort} --discovery.port {ApiPort} --authrpc.port {RpcPort}"
},
new V1EnvVar
{
Name = "GENESIS_JSON",
Value = gethInfo.GenesisJsonBase64
}
}
};
}
private Dictionary<string, string> CreateSelector()
{
return new Dictionary<string, string> { { "test-gethb", "dtest-gethb" } };

View File

@ -5,8 +5,8 @@ namespace CodexDistTestCore.Marketplace
{
public interface IMarketplaceAccess
{
void AdvertiseStorage(ByteSize size, float pricePerMBPerSecond, float collateral);
void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates);
void MakeStorageAvailable(ByteSize size, int minPricePerBytePerSecond, float maxCollateral);
void RequestStorage(ContentId contentId, int pricePerBytePerSecond, float requiredCollateral, float minRequiredNumberOfNodes);
void AssertThatBalance(IResolveConstraint constraint, string message = "");
float GetBalance();
}
@ -48,7 +48,7 @@ namespace CodexDistTestCore.Marketplace
throw new NotImplementedException();
}
public void AdvertiseStorage(ByteSize size, float pricePerMBPerSecond, float collateral)
public void MakeStorageAvailable(ByteSize size, float pricePerMBPerSecond, float collateral)
{
throw new NotImplementedException();
}
@ -87,7 +87,7 @@ namespace CodexDistTestCore.Marketplace
Unavailable();
}
public void AdvertiseStorage(ByteSize size, float pricePerMBPerSecond, float collateral)
public void MakeStorageAvailable(ByteSize size, float pricePerMBPerSecond, float collateral)
{
Unavailable();
}

View File

@ -17,18 +17,34 @@ namespace CodexDistTestCore.Marketplace
this.k8sManager = k8sManager;
}
public GethInfo BringOnlineMarketplace()
public GethInfo BringOnlineMarketplace(OfflineCodexNodes offline)
{
if (gethBootstrapNode != null) return gethBootstrapNode;
log.Log("Starting Geth bootstrap node...");
gethBootstrapNode = k8sManager.BringOnlineGethBootstrapNode();
ExtractAccountAndGenesisJson();
log.Log("Geth boothstrap node started.");
log.Log($"Geth boothstrap node started. Initializing companions for {offline.NumberOfNodes} Codex nodes.");
return gethBootstrapNode;
}
private GethCompanionNodeContainer? CreateGethNodeContainer(OfflineCodexNodes offline, int n)
{
return new GethCompanionNodeContainer(
name: $"geth-node{n}",
servicePort: numberSource.GetNextServicePort(),
servicePortName: numberSource.GetNextServicePortName(),
apiPort: codexPortSource.GetNextNumber(),
rpcPort: codexPortSource.GetNextNumber(),
containerPortName: $"geth-{n}"
);
}
public void AddToBalance(string account, int amount)
{
if (amount < 1 || string.IsNullOrEmpty(account)) Assert.Fail("Invalid arguments for AddToBalance");
@ -62,20 +78,22 @@ namespace CodexDistTestCore.Marketplace
private string ExecuteCommand(string command, params string[] arguments)
{
return k8sManager.ExecuteCommand(gethBootstrapNode!.Pod, K8sGethBoostrapSpecs.ContainerName, command, arguments);
return k8sManager.ExecuteCommand(gethBootstrapNode!.BootstrapPod, K8sGethBoostrapSpecs.ContainerName, command, arguments);
}
}
public class GethInfo
{
public GethInfo(K8sGethBoostrapSpecs spec, PodInfo pod)
public GethInfo(K8sGethBoostrapSpecs spec, PodInfo bootstrapPod, PodInfo companionPod)
{
Spec = spec;
Pod = pod;
BootstrapPod = bootstrapPod;
CompanionPod = companionPod;
}
public K8sGethBoostrapSpecs Spec { get; }
public PodInfo Pod { get; }
public PodInfo BootstrapPod { get; }
public PodInfo CompanionPod { get; }
public string GenesisJsonBase64 { get; set; } = string.Empty;
}
}

View File

@ -34,7 +34,7 @@ namespace Tests.BasicTests
[Test]
public void MarketplaceExample()
{
var primary = SetupCodexNodes(4)
var primary = SetupCodexNodes(1)
.WithStorageQuota(10.GB())
.EnableMarketplace(initialBalance: 20)
.BringOnline()[0];
@ -44,11 +44,12 @@ namespace Tests.BasicTests
// .BringOnline()[0];
//primary.ConnectToPeer(secondary);
//primary.Marketplace.AdvertiseStorage(10.GB(), pricePerMBPerSecond: 0.01f, collateral: 20);
//primary.Marketplace.MakeStorageAvailable(10.GB(), minPricePerBytePerSecond: 1, maxCollateral: 20);
//var testFile = GenerateTestFile(10.MB());
//var contentId = secondary.UploadFile(testFile);
//secondary.Marketplace.AdvertiseContract(contentId, maxPricePerMBPerSecond: 0.02f, minRequiredCollateral: 10, minRequiredNumberOfDuplicates: 1);
//secondary.Marketplace.RequestStorage(contentId, pricePerBytePerSecond: 2,
// requiredCollateral: 10, minRequiredNumberOfNodes: 1);
//primary.Marketplace.AssertThatBalance(Is.LessThan(20), "Collateral was not placed.");
//var primaryBalance = primary.Marketplace.GetBalance();