Skip to content

Commit e4bd52d

Browse files
authored
Merge pull request #709 from bitcoin-dev-project/help-scenario
allow scenarios to run locally without a cluster (for --help)
2 parents 9a918e0 + 68cecc1 commit e4bd52d

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

resources/scenarios/commander.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,32 @@
2525
from test_framework.test_node import TestNode
2626
from test_framework.util import PortSeed, get_rpc_proxy
2727

28-
# Figure out what namespace we are in
29-
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f:
30-
NAMESPACE = f.read().strip()
31-
32-
# Get the in-cluster k8s client to determine what we have access to
33-
config.load_incluster_config()
34-
sclient = client.CoreV1Api()
28+
NAMESPACE = None
29+
pods = client.V1PodList(items=[])
30+
cmaps = client.V1ConfigMapList(items=[])
3531

3632
try:
37-
# An admin with cluster access can list everything.
38-
# A wargames player with namespaced access will get a FORBIDDEN error here
39-
pods = sclient.list_pod_for_all_namespaces()
40-
cmaps = sclient.list_config_map_for_all_namespaces()
33+
# Get the in-cluster k8s client to determine what we have access to
34+
config.load_incluster_config()
35+
sclient = client.CoreV1Api()
36+
37+
# Figure out what namespace we are in
38+
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f:
39+
NAMESPACE = f.read().strip()
40+
41+
try:
42+
# An admin with cluster access can list everything.
43+
# A wargames player with namespaced access will get a FORBIDDEN error here
44+
pods = sclient.list_pod_for_all_namespaces()
45+
cmaps = sclient.list_config_map_for_all_namespaces()
46+
except Exception:
47+
# Just get whatever we have access to in this namespace only
48+
pods = sclient.list_namespaced_pod(namespace=NAMESPACE)
49+
cmaps = sclient.list_namespaced_config_map(namespace=NAMESPACE)
4150
except Exception:
42-
# Just get whatever we have access to in this namespace only
43-
pods = sclient.list_namespaced_pod(namespace=NAMESPACE)
44-
cmaps = sclient.list_namespaced_config_map(namespace=NAMESPACE)
51+
# If there is no cluster config, the user might just be
52+
# running the scenario file locally with --help
53+
pass
4554

4655
WARNET = {"tanks": [], "lightning": [], "channels": []}
4756
for pod in pods.items:

test/scenarios_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self):
1919

2020
def run_test(self):
2121
try:
22+
self.check_help()
2223
self.setup_network()
2324
self.run_and_check_miner_scenario_from_file()
2425
self.run_and_check_scenario_from_file()
@@ -73,6 +74,14 @@ def check_blocks(self, target_blocks, start: int = 0):
7374

7475
return count >= start + target_blocks
7576

77+
def check_help(self):
78+
scenario_file = self.scen_dir / "miner_std.py"
79+
self.log.info(f"Running scenario from file with -- --help: {scenario_file}")
80+
help_text = self.warnet(f"run {scenario_file} -- --help")
81+
assert "usage" in help_text
82+
# no commander pods actually deployed
83+
assert len(scenarios_deployed()) == 0
84+
7685
def run_and_check_miner_scenario_from_file(self):
7786
scenario_file = self.scen_dir / "miner_std.py"
7887
self.log.info(f"Running scenario from file: {scenario_file}")

0 commit comments

Comments
 (0)