|
1 | 1 | import subprocess |
2 | 2 | import sys |
3 | 3 | import tempfile |
4 | | -from multiprocessing import Process |
| 4 | +from multiprocessing import Process, Queue |
5 | 5 | from pathlib import Path |
6 | 6 | from typing import Optional |
7 | 7 |
|
|
22 | 22 | NAMESPACES_CHART_LOCATION, |
23 | 23 | NAMESPACES_FILE, |
24 | 24 | NETWORK_FILE, |
| 25 | + SCENARIOS_DIR, |
25 | 26 | WARGAMES_NAMESPACE_PREFIX, |
26 | 27 | ) |
| 28 | +from .control import _run |
27 | 29 | from .k8s import ( |
28 | 30 | get_default_namespace, |
29 | 31 | get_default_namespace_or, |
@@ -295,24 +297,42 @@ def deploy_network(directory: Path, debug: bool = False, namespace: Optional[str |
295 | 297 | with network_file_path.open() as f: |
296 | 298 | network_file = yaml.safe_load(f) |
297 | 299 |
|
| 300 | + queue = Queue() |
298 | 301 | processes = [] |
| 302 | + |
299 | 303 | for node in network_file["nodes"]: |
300 | | - p = Process(target=deploy_single_node, args=(node, directory, debug, namespace)) |
| 304 | + p = Process(target=deploy_single_node, args=(node, directory, debug, namespace, queue)) |
301 | 305 | p.start() |
302 | 306 | processes.append(p) |
303 | 307 |
|
304 | 308 | for p in processes: |
305 | 309 | p.join() |
306 | 310 |
|
| 311 | + if any([queue.get() for _ in range(queue.qsize())]): |
| 312 | + _run( |
| 313 | + scenario_file=SCENARIOS_DIR / "ln_init.py", |
| 314 | + debug=True, |
| 315 | + source_dir=SCENARIOS_DIR, |
| 316 | + additional_args=None, |
| 317 | + namespace=namespace, |
| 318 | + ) |
| 319 | + |
307 | 320 |
|
308 | | -def deploy_single_node(node, directory: Path, debug: bool, namespace: str): |
| 321 | +def deploy_single_node(node, directory: Path, debug: bool, namespace: str, queue: Queue): |
309 | 322 | defaults_file_path = directory / DEFAULTS_FILE |
310 | 323 | click.echo(f"Deploying node: {node.get('name')}") |
311 | 324 | temp_override_file_path = "" |
312 | 325 | try: |
313 | 326 | node_name = node.get("name") |
314 | 327 | node_config_override = {k: v for k, v in node.items() if k != "name"} |
315 | 328 |
|
| 329 | + if ( |
| 330 | + "lnd" in node_config_override |
| 331 | + and "channels" in node_config_override["lnd"] |
| 332 | + and len(node_config_override["lnd"]["channels"]) > 0 |
| 333 | + ): |
| 334 | + queue.put(True) |
| 335 | + |
316 | 336 | defaults_file_path = directory / DEFAULTS_FILE |
317 | 337 | cmd = f"{HELM_COMMAND} {node_name} {BITCOIN_CHART_LOCATION} --namespace {namespace} -f {defaults_file_path}" |
318 | 338 | if debug: |
|
0 commit comments