Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,12 @@ def get_env(self):
class SlurmSpawner(UserEnvMixin, BatchSpawnerRegexStates):
batch_script = Unicode(
"""#!/bin/bash
#SBATCH --output={{homedir}}/jupyterhub_slurmspawner_%j.log
#SBATCH --job-name=spawner-jupyterhub
#SBATCH --chdir={{homedir}}
#SBATCH --export={{keepvars}}
#SBATCH --get-user-env=L
{% if partition %}#SBATCH --partition={{partition}}
{% if output %}#SBATCH --output={% if not output.startswith('/') %}{{homedir}}/{% endif %}{{output}}
{% endif %}{% if partition %}#SBATCH --partition={{partition}}
{% endif %}{% if runtime %}#SBATCH --time={{runtime}}
{% endif %}{% if memory %}#SBATCH --mem={{memory}}
{% endif %}{% if gres %}#SBATCH --gres={{gres}}
Expand Down Expand Up @@ -717,6 +717,12 @@ class SlurmSpawner(UserEnvMixin, BatchSpawnerRegexStates):
help="Additional resources (e.g. GPUs) requested",
).tag(config=True)

req_output = Unicode(
"jupyterhub_slurmspawner_%j.log",
help="Batch script standard output and standard error filename pattern."
"Relative filename is considered relative to ``req_homedir``.",
).tag(config=True)

# outputs line like "Submitted batch job 209"
batch_submit_cmd = Unicode("sbatch --parsable").tag(config=True)
# outputs status and exec node like "RUNNING hostname"
Expand Down
34 changes: 34 additions & 0 deletions batchspawner/tests/test_spawners.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,40 @@ async def test_slurm(db, event_loop):
re.compile(r"^\#SBATCH \s+ some_option_asdf", re.X | re.M),
re.compile(r"^\#SBATCH \s+ --reservation=RES123", re.X | re.M),
re.compile(r"^\#SBATCH \s+ --gres=GRES123", re.X | re.M),
re.compile(
r"^\#SBATCH \s+ --output= .+ /jupyterhub_slurmspawner_%j.log", re.X | re.M
),
]
from .. import SlurmSpawner

await run_spawner_script(
db,
SlurmSpawner,
normal_slurm_script,
batch_script_re_list=batch_script_re_list,
spawner_kwargs=spawner_kwargs,
)


@pytest.mark.parametrize(
"req_output,expected_file_pattern",
[
("/dev/null", "/dev/null"),
("slurm-%j.out", "{homedir}/slurm-%j.out"),
],
)
async def test_slurm_req_output(db, event_loop, req_output, expected_file_pattern):
homedir = "/users/jhub_users"
spawner_kwargs = {
"req_output": req_output,
"req_homedir": homedir,
}

batch_script_re_list = [
re.compile(
r"^\#SBATCH \s+ --output=" + expected_file_pattern.format(homedir=homedir),
re.X | re.M,
),
]
from .. import SlurmSpawner

Expand Down