Skip to content

Commit 15cab4a

Browse files
authored
Merge pull request #676 from mplsgrant/2025-01-move-tanks-connected
move tanks_connected to commander
2 parents 80dade1 + 6059e8b commit 15cab4a

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

resources/scenarios/commander.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import signal
1010
import sys
1111
import tempfile
12+
import threading
13+
from time import sleep
1214
from typing import Dict
1315

1416
from kubernetes import client, config
@@ -100,6 +102,30 @@ def b64_to_hex(b64, reverse=False):
100102
else:
101103
return base64.b64decode(b64).hex()
102104

105+
def wait_for_tanks_connected(self):
106+
def tank_connected(self, tank):
107+
while True:
108+
peers = tank.getpeerinfo()
109+
count = sum(
110+
1
111+
for peer in peers
112+
if peer.get("connection_type") == "manual" or peer.get("addnode") is True
113+
)
114+
self.log.info(f"Tank {tank.tank} connected to {count}/{tank.init_peers} peers")
115+
if count >= tank.init_peers:
116+
break
117+
else:
118+
sleep(1)
119+
120+
conn_threads = [
121+
threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes
122+
]
123+
for thread in conn_threads:
124+
thread.start()
125+
126+
all(thread.join() is None for thread in conn_threads)
127+
self.log.info("Network connected")
128+
103129
def handle_sigterm(self, signum, frame):
104130
print("SIGTERM received, stopping...")
105131
self.shutdown()

resources/scenarios/ln_init.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,7 @@ def run_test(self):
2020
# L1 P2P
2121
##
2222
self.log.info("Waiting for L1 p2p network connections...")
23-
24-
def tank_connected(self, tank):
25-
while True:
26-
peers = tank.getpeerinfo()
27-
count = sum(
28-
1
29-
for peer in peers
30-
if peer.get("connection_type") == "manual" or peer.get("addnode") is True
31-
)
32-
self.log.info(f"Tank {tank.tank} connected to {count}/{tank.init_peers} peers")
33-
if count >= tank.init_peers:
34-
break
35-
else:
36-
sleep(1)
37-
38-
conn_threads = [
39-
threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes
40-
]
41-
for thread in conn_threads:
42-
thread.start()
43-
44-
all(thread.join() is None for thread in conn_threads)
45-
self.log.info("Network connected")
23+
self.wait_for_tanks_connected()
4624

4725
##
4826
# MINER

0 commit comments

Comments
 (0)