Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions resources/scenarios/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions test/scenarios_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}")
Expand Down
Loading