Fetch account string for each geth companion node

This commit is contained in:
benbierens 2023-04-10 15:54:13 +02:00
parent 230f9f3bd0
commit 388aacf71c
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 61 additions and 11 deletions

View File

@ -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);

View File

@ -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

View File

@ -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();

View File

@ -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)