From 8a6ababba61c9ba390413e96cf192bda2e165444 Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 11 Apr 2023 10:12:24 +0200 Subject: [PATCH] begin splitting geth companion node to its own pod. --- CodexDistTestCore/Config/CodexDockerImage.cs | 15 +++++- CodexDistTestCore/K8sManager.cs | 4 +- .../Marketplace/MarketplaceAccess.cs | 47 +++++++++++++------ .../Marketplace/MarketplaceController.cs | 8 ++++ 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/CodexDistTestCore/Config/CodexDockerImage.cs b/CodexDistTestCore/Config/CodexDockerImage.cs index 333ec0d..5855f71 100644 --- a/CodexDistTestCore/Config/CodexDockerImage.cs +++ b/CodexDistTestCore/Config/CodexDockerImage.cs @@ -14,10 +14,10 @@ namespace CodexDistTestCore.Config return "b20483"; } - public List CreateEnvironmentVariables(OfflineCodexNodes node, CodexNodeContainer environment) + public List CreateEnvironmentVariables(OfflineCodexNodes node, CodexNodeContainer container) { var formatter = new EnvFormatter(); - formatter.Create(node, environment); + formatter.Create(node, container); return formatter.Result; } @@ -50,6 +50,17 @@ namespace CodexDistTestCore.Config AddVar("METRICS_ADDR", "0.0.0.0"); 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) diff --git a/CodexDistTestCore/K8sManager.cs b/CodexDistTestCore/K8sManager.cs index c9e27ff..3e1eeac 100644 --- a/CodexDistTestCore/K8sManager.cs +++ b/CodexDistTestCore/K8sManager.cs @@ -123,8 +123,8 @@ namespace CodexDistTestCore private void ConnectMarketplace(CodexNodeGroup group, OnlineCodexNode node) { - var access = new MarketplaceAccess(this, log); - access.Initialize(group.PodInfo!, node.Container.GethCompanionNodeContainer!); + var access = new MarketplaceAccess(this, marketplaceController, log, group, node.Container.GethCompanionNodeContainer!); + access.Initialize(); node.Marketplace = access; } diff --git a/CodexDistTestCore/Marketplace/MarketplaceAccess.cs b/CodexDistTestCore/Marketplace/MarketplaceAccess.cs index a49eab4..9dcd1c9 100644 --- a/CodexDistTestCore/Marketplace/MarketplaceAccess.cs +++ b/CodexDistTestCore/Marketplace/MarketplaceAccess.cs @@ -14,30 +14,33 @@ namespace CodexDistTestCore.Marketplace public class MarketplaceAccess : IMarketplaceAccess { private readonly K8sManager k8sManager; + private readonly MarketplaceController marketplaceController; private readonly TestLog log; + private readonly CodexNodeGroup group; + private readonly GethCompanionNodeContainer gethCompanionNodeContainer; 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.marketplaceController = marketplaceController; this.log = log; + this.group = group; + this.gethCompanionNodeContainer = gethCompanionNodeContainer; } - public void Initialize(PodInfo pod, GethCompanionNodeContainer gethCompanionNodeContainer) + public void Initialize() { - FetchAccount(pod, gethCompanionNodeContainer); - 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}'"); - } + EnsureAccount(); - private void FetchAccount(PodInfo pod, GethCompanionNodeContainer gethCompanionNodeContainer) - { - account = k8sManager.ExecuteCommand(pod, gethCompanionNodeContainer.Name, "cat", GethDockerImage.AccountFilename); + marketplaceController.AddToBalance(account, group.Origin.MarketplaceConfig!.InitialBalance); + + 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) @@ -59,6 +62,22 @@ namespace CodexDistTestCore.Marketplace { 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 diff --git a/CodexDistTestCore/Marketplace/MarketplaceController.cs b/CodexDistTestCore/Marketplace/MarketplaceController.cs index d4dbbce..9b2c960 100644 --- a/CodexDistTestCore/Marketplace/MarketplaceController.cs +++ b/CodexDistTestCore/Marketplace/MarketplaceController.cs @@ -29,6 +29,14 @@ namespace CodexDistTestCore.Marketplace 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() { FetchAccountAndGenesisJson();