diff --git a/resources/scenarios/commander.py b/resources/scenarios/commander.py index 5684c4ce7..513586df1 100644 --- a/resources/scenarios/commander.py +++ b/resources/scenarios/commander.py @@ -9,6 +9,8 @@ import signal import sys import tempfile +import threading +from time import sleep from typing import Dict from kubernetes import client, config @@ -100,6 +102,30 @@ def b64_to_hex(b64, reverse=False): else: return base64.b64decode(b64).hex() + def wait_for_tanks_connected(self): + def tank_connected(self, tank): + while True: + peers = tank.getpeerinfo() + count = sum( + 1 + for peer in peers + if peer.get("connection_type") == "manual" or peer.get("addnode") is True + ) + self.log.info(f"Tank {tank.tank} connected to {count}/{tank.init_peers} peers") + if count >= tank.init_peers: + break + else: + sleep(1) + + conn_threads = [ + threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes + ] + for thread in conn_threads: + thread.start() + + all(thread.join() is None for thread in conn_threads) + self.log.info("Network connected") + def handle_sigterm(self, signum, frame): print("SIGTERM received, stopping...") self.shutdown() diff --git a/resources/scenarios/ln_init.py b/resources/scenarios/ln_init.py index 9c2f0588e..96dd8161f 100644 --- a/resources/scenarios/ln_init.py +++ b/resources/scenarios/ln_init.py @@ -20,29 +20,7 @@ def run_test(self): # L1 P2P ## self.log.info("Waiting for L1 p2p network connections...") - - def tank_connected(self, tank): - while True: - peers = tank.getpeerinfo() - count = sum( - 1 - for peer in peers - if peer.get("connection_type") == "manual" or peer.get("addnode") is True - ) - self.log.info(f"Tank {tank.tank} connected to {count}/{tank.init_peers} peers") - if count >= tank.init_peers: - break - else: - sleep(1) - - conn_threads = [ - threading.Thread(target=tank_connected, args=(self, tank)) for tank in self.nodes - ] - for thread in conn_threads: - thread.start() - - all(thread.join() is None for thread in conn_threads) - self.log.info("Network connected") + self.wait_for_tanks_connected() ## # MINER