Skip to content

Commit a6ac73f

Browse files
committed
add pod exit staus helper and use in test_base
1 parent bac0546 commit a6ac73f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/warnet/k8s.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ def get_mission(mission: str) -> list[V1PodList]:
3636
return crew
3737

3838

39+
def get_pod_exit_status(pod_name):
40+
try:
41+
sclient = get_static_client()
42+
pod = sclient.read_namespaced_pod(name=pod_name, namespace=get_default_namespace())
43+
for container_status in pod.status.container_statuses:
44+
if container_status.state.terminated:
45+
return container_status.state.terminated.exit_code
46+
return None
47+
except client.ApiException as e:
48+
print(f"Exception when calling CoreV1Api->read_namespaced_pod: {e}")
49+
return None
50+
51+
3952
def get_edges() -> any:
4053
sclient = get_static_client()
4154
configmap = sclient.read_namespaced_config_map(name="edges", namespace="warnet")

test/test_base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from warnet import SRC_DIR
1414
from warnet.control import get_active_scenarios
15+
from warnet.k8s import get_pod_exit_status
1516
from warnet.network import _connected as network_connected
1617
from warnet.network import _status as network_status
1718

@@ -132,7 +133,12 @@ def check_scenarios():
132133
scns = get_active_scenarios()
133134
if len(scns) == 0:
134135
return True
135-
return all(s["status"] == "succeeded" for s in scns)
136+
for s in scns:
137+
exit_status = get_pod_exit_status(s)
138+
self.log.debug(f"Scenario {s} exited with code {exit_status}")
139+
if exit_status != 0:
140+
return False
141+
return True
136142

137143
self.wait_for_predicate(check_scenarios)
138144

0 commit comments

Comments
 (0)