Skip to content

Commit e1aee76

Browse files
author
mickael.roger
committed
Fix timedout execution issue and Add cmd parsing ehancement using shlex
Signed-off-by: mickael.roger <mickael.roger@thalesgroup.com>
1 parent 6a8456c commit e1aee76

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

chaosk8s/pod/actions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
from chaosk8s import create_k8s_api_client
1919

20+
import shlex
21+
2022
__all__ = ["terminate_pods", "exec_in_pods", "delete_pods"]
2123

2224

@@ -112,7 +114,7 @@ def exec_in_pods(cmd: str,
112114
pods = _select_pods(v1, label_selector, name_pattern,
113115
all, rand, mode, qty, ns, order)
114116

115-
exec_command = cmd.strip().split()
117+
exec_command = shlex.split(cmd)
116118

117119
results = []
118120
for po in pods:
@@ -138,7 +140,16 @@ def exec_in_pods(cmd: str,
138140

139141
resp.run_forever(timeout=request_timeout)
140142

141-
err = json.loads(resp.read_channel(ERROR_CHANNEL))
143+
# When timeout_request is triggered, resp.read_channel(ERROR_CHANNEL)
144+
# could return a None object
145+
try:
146+
err = json.loads(resp.read_channel(ERROR_CHANNEL))
147+
except Exception:
148+
err = json.loads('{"status": "Timedout", \
149+
"message": "Action has been timed out",\
150+
"details": {"causes": \
151+
[{"message": "Action stopped by timeout"}]}}')
152+
142153
out = resp.read_channel(STDOUT_CHANNEL)
143154

144155
if err['status'] != "Success":

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ kubernetes
33
logzero
44
chaostoolkit-lib>=0.20.0
55
pyyaml
6+
shlex

0 commit comments

Comments
 (0)