Skip to content

Commit

Permalink
Add timeout support and extra checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mangelajo committed Jan 22, 2025
1 parent 67a23a7 commit 9844f77
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/drivers/shell/jumpstarter_driver_shell/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 9844f77

Please sign in to comment.