Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions tests/integration-tests/tests/common/schedulers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import os
import re
import shlex
from abc import ABCMeta, abstractmethod

from assertpy import assert_that
Expand Down Expand Up @@ -387,6 +388,11 @@ def _submit_batch_job( # noqa: C901
else:
return self._remote_command_executor.run_remote_command(submission_command, raise_on_error=raise_on_error)

@staticmethod
def _is_valid_file_path(path):
"""Return True if path looks like a valid absolute file path (not empty, no non-printable chars)."""
return not is_blank(path) and path.startswith("/") and path.isprintable()

def _dump_job_output(self, job_info):
params = re.split(r"\s+", job_info)
stderr = None
Expand All @@ -396,29 +402,39 @@ def _dump_job_output(self, job_info):
match_stdout = re.match(r"StdOut=(.*)?", param)
if match_stderr:
stderr = match_stderr.group(1)
logging.info("stderr:" + stderr)
logging.info("stderr:%s", stderr)
if match_stdout:
stdout = match_stdout.group(1)
logging.info("stdout:" + stdout)
logging.info("stdout:%s", stdout)

# Validate paths: must be absolute and contain only printable characters.
# scontrol may emit empty or non-printable values for StdErr when --wrap is used,
# which would cause bare `cat` (reading from stdin) to hang indefinitely.
stderr = stderr if self._is_valid_file_path(stderr) else None
stdout = stdout if self._is_valid_file_path(stdout) else None

dump_timeout = 60
if not is_blank(stderr) or not is_blank(stdout):
if not is_blank(stderr) and stderr == stdout:
if stderr or stdout:
if stderr and stderr == stdout:
result = self._remote_command_executor.run_remote_command(
f'echo "stderr/stdout:" && cat {stderr}', timeout=dump_timeout
f"timeout {dump_timeout} cat {shlex.quote(stderr)}",
timeout=dump_timeout + 10,
)
logging.error(result.stdout)
logging.error(f"stderr/stdout:\n{result.stdout}")
else:
if not is_blank(stderr):
if stderr:
stderr_result = self._remote_command_executor.run_remote_command(
f'echo "stderr" && cat {stderr}', timeout=dump_timeout
f"timeout {dump_timeout} cat {shlex.quote(stderr)}",
timeout=dump_timeout + 10,
)
logging.error(stderr_result.stdout)
logging.error(f"stderr:\n{stderr_result.stdout}")

if not is_blank(stdout):
if stdout:
stdout_result = self._remote_command_executor.run_remote_command(
f'echo "stdout" && cat {stdout}', timeout=dump_timeout
f"timeout {dump_timeout} cat {shlex.quote(stdout)}",
timeout=dump_timeout + 10,
)
logging.error(stdout_result.stdout)
logging.error(f"stdout:\n{stdout_result.stdout}")
else:
logging.error("Unable to retrieve job output.")

Expand Down
Loading