From 9844f77819b260b1acc03fc1141d30f8e091a501 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Pelayo Date: Thu, 16 Jan 2025 23:29:35 +0100 Subject: [PATCH] Add timeout support and extra checks --- contrib/drivers/shell/jumpstarter_driver_shell/driver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/drivers/shell/jumpstarter_driver_shell/driver.py b/contrib/drivers/shell/jumpstarter_driver_shell/driver.py index bcecf4c5..781f4647 100644 --- a/contrib/drivers/shell/jumpstarter_driver_shell/driver.py +++ b/contrib/drivers/shell/jumpstarter_driver_shell/driver.py @@ -15,6 +15,7 @@ class Shell(Driver): # to be executed by each method methods: dict[str, str] shell: list[str] = field(default_factory=lambda: ["bash", "-c"]) + timeout: int = 300 log_level: str = "INFO" cwd: str | None = None @@ -67,6 +68,9 @@ def _run_inline_shell_script(self, method, script, *args, env_vars=None): if env_vars: combined_env.update(env_vars) + if not isinstance(script, str) or not script.strip(): + raise ValueError("Shell script must be a non-empty string") + cmd = self.shell + [script, method] + list(args) # Run the command @@ -75,7 +79,8 @@ def _run_inline_shell_script(self, method, script, *args, env_vars=None): capture_output=True, # Captures stdout and stderr text=True, # Returns stdout/stderr as strings (not bytes) env=combined_env, # Pass our merged environment - cwd=self.cwd # Run in the working directory (if set) + cwd=self.cwd, # Run in the working directory (if set) + timeout=self.timeout, ) return result