diff --git a/resources/scenarios/commander.py b/resources/scenarios/commander.py index 8a50b2fc5..8cfe99180 100644 --- a/resources/scenarios/commander.py +++ b/resources/scenarios/commander.py @@ -25,23 +25,32 @@ from test_framework.test_node import TestNode from test_framework.util import PortSeed, get_rpc_proxy -# Figure out what namespace we are in -with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: - NAMESPACE = f.read().strip() - -# Get the in-cluster k8s client to determine what we have access to -config.load_incluster_config() -sclient = client.CoreV1Api() +NAMESPACE = None +pods = client.V1PodList(items=[]) +cmaps = client.V1ConfigMapList(items=[]) try: - # An admin with cluster access can list everything. - # A wargames player with namespaced access will get a FORBIDDEN error here - pods = sclient.list_pod_for_all_namespaces() - cmaps = sclient.list_config_map_for_all_namespaces() + # Get the in-cluster k8s client to determine what we have access to + config.load_incluster_config() + sclient = client.CoreV1Api() + + # Figure out what namespace we are in + with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: + NAMESPACE = f.read().strip() + + try: + # An admin with cluster access can list everything. + # A wargames player with namespaced access will get a FORBIDDEN error here + pods = sclient.list_pod_for_all_namespaces() + cmaps = sclient.list_config_map_for_all_namespaces() + except Exception: + # Just get whatever we have access to in this namespace only + pods = sclient.list_namespaced_pod(namespace=NAMESPACE) + cmaps = sclient.list_namespaced_config_map(namespace=NAMESPACE) except Exception: - # Just get whatever we have access to in this namespace only - pods = sclient.list_namespaced_pod(namespace=NAMESPACE) - cmaps = sclient.list_namespaced_config_map(namespace=NAMESPACE) + # If there is no cluster config, the user might just be + # running the scenario file locally with --help + pass WARNET = {"tanks": [], "lightning": [], "channels": []} for pod in pods.items: diff --git a/test/scenarios_test.py b/test/scenarios_test.py index dfb8d6b2d..9d89cf8ed 100755 --- a/test/scenarios_test.py +++ b/test/scenarios_test.py @@ -19,6 +19,7 @@ def __init__(self): def run_test(self): try: + self.check_help() self.setup_network() self.run_and_check_miner_scenario_from_file() self.run_and_check_scenario_from_file() @@ -73,6 +74,14 @@ def check_blocks(self, target_blocks, start: int = 0): return count >= start + target_blocks + def check_help(self): + scenario_file = self.scen_dir / "miner_std.py" + self.log.info(f"Running scenario from file with -- --help: {scenario_file}") + help_text = self.warnet(f"run {scenario_file} -- --help") + assert "usage" in help_text + # no commander pods actually deployed + assert len(scenarios_deployed()) == 0 + def run_and_check_miner_scenario_from_file(self): scenario_file = self.scen_dir / "miner_std.py" self.log.info(f"Running scenario from file: {scenario_file}")