diff --git a/CodexDistTestCore/K8sManager.cs b/CodexDistTestCore/K8sManager.cs index 5e8716b..c9e27ff 100644 --- a/CodexDistTestCore/K8sManager.cs +++ b/CodexDistTestCore/K8sManager.cs @@ -30,23 +30,27 @@ namespace CodexDistTestCore public ICodexNodeGroup BringOnline(OfflineCodexNodes offline) { - var online = CreateOnlineCodexNodes(offline); + var group = CreateOnlineCodexNodes(offline); if (offline.MarketplaceConfig != null) { - online.GethInfo = BringOnlineMarketplace(); + group.GethInfo = BringOnlineMarketplace(); } - K8s(k => k.BringOnline(online, offline)); - - log.Log($"{online.Describe()} online."); + K8s(k => k.BringOnline(group, offline)); if (offline.MetricsEnabled) { - BringOnlineMetrics(online); + BringOnlineMetrics(group); + } + if (offline.MarketplaceConfig != null) + { + ConnectMarketplace(group); } - return online; + log.Log($"{group.Describe()} online."); + + return group; } public IOfflineCodexNodes BringOffline(ICodexNodeGroup node) @@ -109,6 +113,21 @@ namespace CodexDistTestCore return marketplaceController.BringOnlineMarketplace(); } + private void ConnectMarketplace(CodexNodeGroup group) + { + foreach (var node in DowncastNodes(group)) + { + ConnectMarketplace(group, node); + } + } + + private void ConnectMarketplace(CodexNodeGroup group, OnlineCodexNode node) + { + var access = new MarketplaceAccess(this, log); + access.Initialize(group.PodInfo!, node.Container.GethCompanionNodeContainer!); + node.Marketplace = access; + } + private CodexNodeGroup CreateOnlineCodexNodes(OfflineCodexNodes offline) { var containers = CreateContainers(offline); diff --git a/CodexDistTestCore/Marketplace/K8sGethSpecs.cs b/CodexDistTestCore/Marketplace/K8sGethSpecs.cs index dd0204d..751fb5e 100644 --- a/CodexDistTestCore/Marketplace/K8sGethSpecs.cs +++ b/CodexDistTestCore/Marketplace/K8sGethSpecs.cs @@ -6,6 +6,8 @@ namespace CodexDistTestCore.Marketplace public static class GethDockerImage { public const string Image = "thatbenbierens/geth-confenv:latest"; + public const string AccountFilename = "account_string.txt"; + public const string GenesisFilename = "genesis.json"; } public class K8sGethBoostrapSpecs diff --git a/CodexDistTestCore/Marketplace/MarketplaceAccess.cs b/CodexDistTestCore/Marketplace/MarketplaceAccess.cs index 25bb63f..a49eab4 100644 --- a/CodexDistTestCore/Marketplace/MarketplaceAccess.cs +++ b/CodexDistTestCore/Marketplace/MarketplaceAccess.cs @@ -13,6 +13,33 @@ namespace CodexDistTestCore.Marketplace public class MarketplaceAccess : IMarketplaceAccess { + private readonly K8sManager k8sManager; + private readonly TestLog log; + private string account = string.Empty; + + public MarketplaceAccess(K8sManager k8sManager, TestLog log) + { + this.k8sManager = k8sManager; + this.log = log; + } + + public void Initialize(PodInfo pod, GethCompanionNodeContainer gethCompanionNodeContainer) + { + 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}'"); + } + + private void FetchAccount(PodInfo pod, GethCompanionNodeContainer gethCompanionNodeContainer) + { + account = k8sManager.ExecuteCommand(pod, gethCompanionNodeContainer.Name, "cat", GethDockerImage.AccountFilename); + } + public void AdvertiseContract(ContentId contentId, float maxPricePerMBPerSecond, float minRequiredCollateral, float minRequiredNumberOfDuplicates) { throw new NotImplementedException(); diff --git a/CodexDistTestCore/Marketplace/MarketplaceController.cs b/CodexDistTestCore/Marketplace/MarketplaceController.cs index e832335..d4dbbce 100644 --- a/CodexDistTestCore/Marketplace/MarketplaceController.cs +++ b/CodexDistTestCore/Marketplace/MarketplaceController.cs @@ -38,16 +38,18 @@ namespace CodexDistTestCore.Marketplace FetchAccountAndGenesisJson(); } - 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(bootstrapAccount, Is.Not.Empty, "Unable to fetch account for geth bootstrap node. Test infra failure."); + Assert.That(bootstrapGenesisJson, Is.Not.Empty, "Unable to fetch genesis-json for geth bootstrap node. Test infra failure."); gethBootstrapNode!.GenesisJsonBase64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(bootstrapGenesisJson)); + + log.Log($"Initialized geth bootstrap node with account '{bootstrapAccount}'"); } private void FetchAccountAndGenesisJson() { - bootstrapAccount = ExecuteCommand("cat", "account_string.txt"); - bootstrapGenesisJson = ExecuteCommand("cat", "genesis.json"); + bootstrapAccount = ExecuteCommand("cat", GethDockerImage.AccountFilename); + bootstrapGenesisJson = ExecuteCommand("cat", GethDockerImage.GenesisFilename); } private string ExecuteCommand(string command, params string[] arguments)