Skip to content

Commit 678478b

Browse files
committed
Make the shell command safer in at least two ways
Prevent errors where we could not retrieve the command status like File "/usr/lib/python3.13/site-packages/avocado_spawner_remote/__init__.py", line 218, in wait_task if not RemoteSpawner.is_task_alive(runtime_task): ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ File "/usr/lib/python3.13/site-packages/avocado_spawner_remote/__init__.py", line 142, in is_task_alive status, output = session.cmd_status_output( ~~~~~~~~~~~~~~~~~~~~~~~~~^ f"pgrep -r R,S -f {runtime_task.task.identifier}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/usr/lib/python3.13/site-packages/aexpect/client.py", line 1491, in cmd_status_output raise ShellStatusError(cmd, out) from error Use the "safe" flag to handle cases where the shell prompt might be polluted with "[Done] some-background-process" appearing from the detached avocado task process but also handle any further unexpected status retrieval errors. There were still rare cases where the safe flag might miss something yet it does filter our most cases from needing to catch status errors (which is also worst in terms of peformance compared to a regular boolean check). Signed-off-by: Plamen Dimitrov <plamen.dimitrov@intra2net.com>
1 parent 22d58b8 commit 678478b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • optional_plugins/spawner_remote/avocado_spawner_remote

optional_plugins/spawner_remote/avocado_spawner_remote/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ def is_operational(self):
8080
@staticmethod
8181
def run_remote_cmd(session, command, timeout):
8282
try:
83-
status, output = session.cmd_status_output(command, timeout)
83+
status, output = session.cmd_status_output(command, timeout, safe=True)
8484
except exceptions.ShellTimeoutError:
8585
status, output = 2, f"Remote command timeout of {timeout} reached"
8686
except exceptions.ShellProcessTerminatedError:
8787
status, output = 2, "Remote command terminated prematurely"
88+
except exceptions.ShellStatusError:
89+
status, output = 3, f"Remote command could not retrieve status"
8890
return status, output
8991

9092
@contextlib.contextmanager

0 commit comments

Comments
 (0)