Skip to content

Commit a4d1b34

Browse files
authored
Merge pull request #109 from guillaumeeb/add_pbs_spawner
Adding PBSSpawner
2 parents 4747946 + fa3b09d commit a4d1b34

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

batchspawner/batchspawner.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,31 @@ class MoabSpawner(TorqueSpawner):
501501
state_exechost_re = Unicode(r'AllocNodeList="([^\r\n\t\f :"]*)').tag(config=True)
502502

503503

504+
class PBSSpawner(TorqueSpawner):
505+
batch_script = Unicode("""#!/bin/sh
506+
{% if queue or host %}#PBS -q {% if queue %}{{queue}}{% endif %}\
507+
{% if host %}@{{host}}{% endif %}{% endif %}
508+
#PBS -l walltime={{runtime}}
509+
#PBS -l select=1:ncpus={{nprocs}}:mem={{memory}}
510+
#PBS -N jupyterhub-singleuser
511+
#PBS -o {{homedir}}/.jupyterhub.pbs.out
512+
#PBS -e {{homedir}}/.jupyterhub.pbs.err
513+
#PBS -v {{keepvars}}
514+
{% if options %}#PBS {{options}}{% endif %}
515+
516+
{{prologue}}
517+
{{cmd}}
518+
{{epilogue}}
519+
""").tag(config=True)
520+
521+
# outputs job data XML string
522+
batch_query_cmd = Unicode('qstat -fx {job_id}').tag(config=True)
523+
524+
state_pending_re = Unicode(r'job_state = [QH]').tag(config=True)
525+
state_running_re = Unicode(r'job_state = R').tag(config=True)
526+
state_exechost_re = Unicode(r'exec_host = ([\w_-]+)/').tag(config=True)
527+
528+
504529
class UserEnvMixin:
505530
"""Mixin class that computes values for USER, SHELL and HOME in the environment passed to
506531
the job submission subprocess in case the batch system needs these for the batch script."""

batchspawner/tests/test_spawners.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,37 @@ def test_moab(db, io_loop):
330330
spawner_kwargs=spawner_kwargs)
331331

332332

333+
def test_pbs(db, io_loop):
334+
spawner_kwargs = {
335+
'req_nprocs': '4',
336+
'req_memory': '10256',
337+
'req_options': 'some_option_asdf',
338+
'req_host': 'some_pbs_admin_node',
339+
'req_runtime': '08:00:00',
340+
}
341+
batch_script_re_list = [
342+
re.compile(r'singleuser_command'),
343+
re.compile(r'select=1'),
344+
re.compile(r'ncpus=4'),
345+
re.compile(r'mem=10256'),
346+
re.compile(r'walltime=08:00:00'),
347+
re.compile(r'@some_pbs_admin_node'),
348+
re.compile(r'^#PBS some_option_asdf', re.M),
349+
]
350+
script = [
351+
(re.compile(r'sudo.*qsub'), str(testjob)),
352+
(re.compile(r'sudo.*qstat'), 'job_state = Q'.format(testhost)), # pending
353+
(re.compile(r'sudo.*qstat'), 'job_state = R\nexec_host = {}/2*1'.format(testhost)), # running
354+
(re.compile(r'sudo.*qstat'), 'job_state = R\nexec_host = {}/2*1'.format(testhost)), # running
355+
(re.compile(r'sudo.*qdel'), 'STOP'),
356+
(re.compile(r'sudo.*qstat'), ''),
357+
]
358+
from .. import PBSSpawner
359+
run_spawner_script(db, io_loop, PBSSpawner, script,
360+
batch_script_re_list=batch_script_re_list,
361+
spawner_kwargs=spawner_kwargs)
362+
363+
333364
def test_slurm(db, io_loop):
334365
spawner_kwargs = {
335366
'req_runtime': '3-05:10:10',

0 commit comments

Comments
 (0)