Fixes port clashes for multiple geth nodes per pod

This commit is contained in:
benbierens 2023-04-10 15:21:45 +02:00
parent ab8318e102
commit 230f9f3bd0
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 30 additions and 5 deletions

View File

@ -96,6 +96,7 @@ namespace CodexDistTestCore
servicePort: groupContainerFactory.GetNextServicePort(), servicePort: groupContainerFactory.GetNextServicePort(),
servicePortName: groupContainerFactory.GetNextServicePortName(), servicePortName: groupContainerFactory.GetNextServicePortName(),
apiPort: codexPortSource.GetNextNumber(), apiPort: codexPortSource.GetNextNumber(),
rpcPort: codexPortSource.GetNextNumber(),
containerPortName: $"geth-{n}" containerPortName: $"geth-{n}"
); );
} }

View File

@ -4,12 +4,13 @@ namespace CodexDistTestCore.Marketplace
{ {
public class GethCompanionNodeContainer public class GethCompanionNodeContainer
{ {
public GethCompanionNodeContainer(string name, int servicePort, string servicePortName, int apiPort, string containerPortName) public GethCompanionNodeContainer(string name, int servicePort, string servicePortName, int apiPort, int rpcPort, string containerPortName)
{ {
Name = name; Name = name;
ServicePort = servicePort; ServicePort = servicePort;
ServicePortName = servicePortName; ServicePortName = servicePortName;
ApiPort = apiPort; ApiPort = apiPort;
RpcPort = rpcPort;
ContainerPortName = containerPortName; ContainerPortName = containerPortName;
} }
@ -17,6 +18,7 @@ namespace CodexDistTestCore.Marketplace
public int ServicePort { get; } public int ServicePort { get; }
public string ServicePortName { get; } public string ServicePortName { get; }
public int ApiPort { get; } public int ApiPort { get; }
public int RpcPort { get; }
public string ContainerPortName { get; } public string ContainerPortName { get; }
public V1Container CreateDeploymentContainer(GethInfo gethInfo) public V1Container CreateDeploymentContainer(GethInfo gethInfo)
@ -34,7 +36,19 @@ namespace CodexDistTestCore.Marketplace
} }
}, },
// todo: use env vars to connect this node to the bootstrap node provided by gethInfo.podInfo & gethInfo.servicePort & gethInfo.genesisJsonBase64 // 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) 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
}
}
}; };
} }

View File

@ -31,8 +31,12 @@ namespace CodexDistTestCore.Marketplace
private void ExtractAccountAndGenesisJson() private void ExtractAccountAndGenesisJson()
{ {
bootstrapAccount = ExecuteCommand("cat", "account_string.txt"); FetchAccountAndGenesisJson();
bootstrapGenesisJson = ExecuteCommand("cat", "genesis.json"); if (string.IsNullOrEmpty(bootstrapAccount) || string.IsNullOrEmpty(bootstrapGenesisJson))
{
Thread.Sleep(TimeSpan.FromSeconds(15));
FetchAccountAndGenesisJson();
}
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.");
@ -40,6 +44,12 @@ namespace CodexDistTestCore.Marketplace
gethBootstrapNode!.GenesisJsonBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(bootstrapGenesisJson)); gethBootstrapNode!.GenesisJsonBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(bootstrapGenesisJson));
} }
private void FetchAccountAndGenesisJson()
{
bootstrapAccount = ExecuteCommand("cat", "account_string.txt");
bootstrapGenesisJson = ExecuteCommand("cat", "genesis.json");
}
private string ExecuteCommand(string command, params string[] arguments) private string ExecuteCommand(string command, params string[] arguments)
{ {
return k8sManager.ExecuteCommand(gethBootstrapNode!.Pod, K8sGethBoostrapSpecs.ContainerName, command, arguments); return k8sManager.ExecuteCommand(gethBootstrapNode!.Pod, K8sGethBoostrapSpecs.ContainerName, command, arguments);

View File

@ -34,7 +34,7 @@ namespace Tests.BasicTests
[Test] [Test]
public void MarketplaceExample() public void MarketplaceExample()
{ {
var primary = SetupCodexNodes(1) var primary = SetupCodexNodes(4)
.WithStorageQuota(10.GB()) .WithStorageQuota(10.GB())
.EnableMarketplace(initialBalance: 20) .EnableMarketplace(initialBalance: 20)
.BringOnline()[0]; .BringOnline()[0];