begin splitting geth companion node to its own pod.

This commit is contained in:
benbierens 2023-04-11 10:12:24 +02:00
parent 388aacf71c
commit 8a6ababba6
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 56 additions and 18 deletions

View File

@ -14,10 +14,10 @@ namespace CodexDistTestCore.Config
return "b20483"; return "b20483";
} }
public List<V1EnvVar> CreateEnvironmentVariables(OfflineCodexNodes node, CodexNodeContainer environment) public List<V1EnvVar> CreateEnvironmentVariables(OfflineCodexNodes node, CodexNodeContainer container)
{ {
var formatter = new EnvFormatter(); var formatter = new EnvFormatter();
formatter.Create(node, environment); formatter.Create(node, container);
return formatter.Result; return formatter.Result;
} }
@ -50,6 +50,17 @@ namespace CodexDistTestCore.Config
AddVar("METRICS_ADDR", "0.0.0.0"); AddVar("METRICS_ADDR", "0.0.0.0");
AddVar("METRICS_PORT", container.MetricsPort.ToString()); AddVar("METRICS_PORT", container.MetricsPort.ToString());
} }
if (container.GethCompanionNodeContainer != null)
{
// well, darn: To get the account here, the geth companion needs to have been started and account string fetched.
// but the codex node and geth companion node are in the same pod. so they start at the same time.
// so we cannot start the codex node with the correct account string at the same time as we start the geth node that
// is supposed to generate that string.
// begin rework: Separate pod for geth companion node.
//ETH_PROVIDER
//ETH_ACCOUNT
//ETH_DEPLOYMENT
}
} }
private void AddVar(string key, string value) private void AddVar(string key, string value)

View File

@ -123,8 +123,8 @@ namespace CodexDistTestCore
private void ConnectMarketplace(CodexNodeGroup group, OnlineCodexNode node) private void ConnectMarketplace(CodexNodeGroup group, OnlineCodexNode node)
{ {
var access = new MarketplaceAccess(this, log); var access = new MarketplaceAccess(this, marketplaceController, log, group, node.Container.GethCompanionNodeContainer!);
access.Initialize(group.PodInfo!, node.Container.GethCompanionNodeContainer!); access.Initialize();
node.Marketplace = access; node.Marketplace = access;
} }

View File

@ -14,30 +14,33 @@ namespace CodexDistTestCore.Marketplace
public class MarketplaceAccess : IMarketplaceAccess public class MarketplaceAccess : IMarketplaceAccess
{ {
private readonly K8sManager k8sManager; private readonly K8sManager k8sManager;
private readonly MarketplaceController marketplaceController;
private readonly TestLog log; private readonly TestLog log;
private readonly CodexNodeGroup group;
private readonly GethCompanionNodeContainer gethCompanionNodeContainer;
private string account = string.Empty; private string account = string.Empty;
public MarketplaceAccess(K8sManager k8sManager, TestLog log) public MarketplaceAccess(
K8sManager k8sManager,
MarketplaceController marketplaceController,
TestLog log,
CodexNodeGroup group,
GethCompanionNodeContainer gethCompanionNodeContainer)
{ {
this.k8sManager = k8sManager; this.k8sManager = k8sManager;
this.marketplaceController = marketplaceController;
this.log = log; this.log = log;
this.group = group;
this.gethCompanionNodeContainer = gethCompanionNodeContainer;
} }
public void Initialize(PodInfo pod, GethCompanionNodeContainer gethCompanionNodeContainer) public void Initialize()
{ {
FetchAccount(pod, gethCompanionNodeContainer); EnsureAccount();
if (string.IsNullOrEmpty(account))
{
Thread.Sleep(TimeSpan.FromSeconds(15));
FetchAccount(pod, gethCompanionNodeContainer);
}
Assert.That(account, Is.Not.Empty, "Unable to fetch account for geth companion node. Test infra failure.");
log.Log($"Initialized Geth companion node with account '{account}'");
}
private void FetchAccount(PodInfo pod, GethCompanionNodeContainer gethCompanionNodeContainer) marketplaceController.AddToBalance(account, group.Origin.MarketplaceConfig!.InitialBalance);
{
account = k8sManager.ExecuteCommand(pod, gethCompanionNodeContainer.Name, "cat", GethDockerImage.AccountFilename); log.Log($"Initialized Geth companion node with account '{account}' and initial balance {group.Origin.MarketplaceConfig!.InitialBalance}");
} }
public void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates) public void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates)
@ -59,6 +62,22 @@ namespace CodexDistTestCore.Marketplace
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private void EnsureAccount()
{
FetchAccount();
if (string.IsNullOrEmpty(account))
{
Thread.Sleep(TimeSpan.FromSeconds(15));
FetchAccount();
}
Assert.That(account, Is.Not.Empty, "Unable to fetch account for geth companion node. Test infra failure.");
}
private void FetchAccount()
{
account = k8sManager.ExecuteCommand(group.PodInfo!, gethCompanionNodeContainer.Name, "cat", GethDockerImage.AccountFilename);
}
} }
public class MarketplaceUnavailable : IMarketplaceAccess public class MarketplaceUnavailable : IMarketplaceAccess

View File

@ -29,6 +29,14 @@ namespace CodexDistTestCore.Marketplace
return gethBootstrapNode; return gethBootstrapNode;
} }
public void AddToBalance(string account, int amount)
{
if (amount < 1 || string.IsNullOrEmpty(account)) Assert.Fail("Invalid arguments for AddToBalance");
// call the bootstrap node and convince it to give 'account' 'amount' tokens somehow.
throw new NotImplementedException();
}
private void ExtractAccountAndGenesisJson() private void ExtractAccountAndGenesisJson()
{ {
FetchAccountAndGenesisJson(); FetchAccountAndGenesisJson();