Skip to content

Commit 5e426d1

Browse files
committed
Add spawner tests for Moab, Condor, and LSF
- Also updates to other spawners
1 parent d9d4292 commit 5e426d1

File tree

1 file changed

+119
-8
lines changed

1 file changed

+119
-8
lines changed

batchspawner/tests/test_spawners.py

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ def run_command(self, cmd, input=None, env=None):
258258
status = io_loop.run_sync(spawner.poll, timeout=5)
259259
assert status == 1
260260
# batch_submit_cmd
261-
# batch_query_cmd
261+
# batch_query_cmd (result=pending)
262+
# batch_query_cmd (result=running)
262263
io_loop.run_sync(spawner.start, timeout=5)
263264
assert spawner.job_id == testjob
264265
check_ip(spawner, testhost)
@@ -274,14 +275,22 @@ def run_command(self, cmd, input=None, env=None):
274275

275276

276277
def test_torque(db, io_loop):
277-
spawner_kwargs = { }
278+
spawner_kwargs = {
279+
'req_nprocs': '5',
280+
'req_memory': '5678',
281+
'req_options': 'some_option_asdf',
282+
}
278283
batch_script_re_list = [
279284
re.compile(r'singleuser_command'),
285+
re.compile(r'mem=5678'),
286+
re.compile(r'ppn=5'),
287+
re.compile(r'^#PBS some_option_asdf', re.M),
280288
]
281289
script = [
282290
(re.compile(r'sudo.*qsub'), str(testjob)),
283-
(re.compile(r'sudo.*qstat'), '<job_state>R</job_state><exec_host>{}/1</exec_host>'.format(testhost)),
284-
(re.compile(r'sudo.*qstat'), '<job_state>R</job_state>'+testhost),
291+
(re.compile(r'sudo.*qstat'), '<job_state>Q</job_state><exec_host></exec_host>'.format(testhost)), # pending
292+
(re.compile(r'sudo.*qstat'), '<job_state>R</job_state><exec_host>{}/1</exec_host>'.format(testhost)), # running
293+
(re.compile(r'sudo.*qstat'), '<job_state>R</job_state><exec_host>{}/1</exec_host>'.format(testhost)), # running
285294
(re.compile(r'sudo.*qdel'), 'STOP'),
286295
(re.compile(r'sudo.*qstat'), ''),
287296
]
@@ -291,20 +300,49 @@ def test_torque(db, io_loop):
291300
spawner_kwargs=spawner_kwargs)
292301

293302

303+
def test_moab(db, io_loop):
304+
spawner_kwargs = {
305+
'req_nprocs': '5',
306+
'req_memory': '5678',
307+
'req_options': 'some_option_asdf',
308+
}
309+
batch_script_re_list = [
310+
re.compile(r'singleuser_command'),
311+
re.compile(r'mem=5678'),
312+
re.compile(r'ppn=5'),
313+
re.compile(r'^#PBS some_option_asdf', re.M),
314+
]
315+
script = [
316+
(re.compile(r'sudo.*msub'), str(testjob)),
317+
(re.compile(r'sudo.*mdiag'), 'State="Idle"'.format(testhost)), # pending
318+
(re.compile(r'sudo.*mdiag'), 'State="Running" AllocNodeList="{}"'.format(testhost)), # running
319+
(re.compile(r'sudo.*mdiag'), 'State="Running" AllocNodeList="{}"'.format(testhost)), # running
320+
(re.compile(r'sudo.*mjobctl.*-c'), 'STOP'),
321+
(re.compile(r'sudo.*mdiag'), ''),
322+
]
323+
from .. import MoabSpawner
324+
run_spawner_script(db, io_loop, MoabSpawner, script,
325+
batch_script_re_list=batch_script_re_list,
326+
spawner_kwargs=spawner_kwargs)
327+
328+
294329
def test_slurm(db, io_loop):
295330
spawner_kwargs = {
331+
'req_runtime': '3-05:10:10',
296332
'req_nprocs': '5',
297333
'req_memory': '5678',
298334
'req_options': 'some_option_asdf',
299335
}
300336
batch_script_re_list = [
301-
re.compile(r'srun.*singleuser_command'),
302-
re.compile(r'#SBATCH\s+--cpus-per-task=5'),
303-
re.compile(r'#SBATCH\s+some_option_asdf'),
337+
re.compile(r'srun .* singleuser_command', re.X|re.M),
338+
re.compile(r'^#SBATCH \s+ --cpus-per-task=5', re.X|re.M),
339+
re.compile(r'^#SBATCH \s+ --time=3-05:10:10', re.X|re.M),
340+
re.compile(r'^#SBATCH \s+ some_option_asdf', re.X|re.M),
304341
]
305342
script = [
306343
(re.compile(r'sudo.*sbatch'), str(testjob)),
307-
(re.compile(r'sudo.*squeue'), 'RUNNING '+testhost),
344+
(re.compile(r'sudo.*squeue'), 'PENDING '), # pending
345+
(re.compile(r'sudo.*squeue'), 'RUNNING '+testhost), # running
308346
(re.compile(r'sudo.*squeue'), 'RUNNING '+testhost),
309347
(re.compile(r'sudo.*scancel'), 'STOP'),
310348
(re.compile(r'sudo.*squeue'), ''),
@@ -313,3 +351,76 @@ def test_slurm(db, io_loop):
313351
run_spawner_script(db, io_loop, SlurmSpawner, script,
314352
batch_script_re_list=batch_script_re_list,
315353
spawner_kwargs=spawner_kwargs)
354+
355+
356+
#def test_gridengine(db, io_loop):
357+
# spawner_kwargs = {
358+
# 'req_options': 'some_option_asdf',
359+
# }
360+
# batch_script_re_list = [
361+
# re.compile(r'singleuser_command'),
362+
# re.compile(r'#$\s+some_option_asdf'),
363+
# ]
364+
# script = [
365+
# (re.compile(r'sudo.*qsub'), 'x x '+str(testjob)),
366+
# (re.compile(r'sudo.*qstat'), 'PENDING '),
367+
# (re.compile(r'sudo.*qstat'), 'RUNNING '+testhost),
368+
# (re.compile(r'sudo.*qstat'), 'RUNNING '+testhost),
369+
# (re.compile(r'sudo.*qdel'), 'STOP'),
370+
# (re.compile(r'sudo.*qstat'), ''),
371+
# ]
372+
# from .. import GridengineSpawner
373+
# run_spawner_script(db, io_loop, GridengineSpawner, script,
374+
# batch_script_re_list=batch_script_re_list,
375+
# spawner_kwargs=spawner_kwargs)
376+
377+
378+
def test_condor(db, io_loop):
379+
spawner_kwargs = {
380+
'req_nprocs': '5',
381+
'req_memory': '5678',
382+
'req_options': 'some_option_asdf',
383+
}
384+
batch_script_re_list = [
385+
re.compile(r'exec singleuser_command'),
386+
re.compile(r'RequestCpus = 5'),
387+
re.compile(r'RequestMemory = 5678'),
388+
re.compile(r'^some_option_asdf', re.M),
389+
]
390+
script = [
391+
(re.compile(r'sudo.*condor_submit'), 'submitted to cluster {}'.format(str(testjob))),
392+
(re.compile(r'sudo.*condor_q'), '1,'.format(testhost)), # pending
393+
(re.compile(r'sudo.*condor_q'), '2, @{}'.format(testhost)), # runing
394+
(re.compile(r'sudo.*condor_q'), '2, @{}'.format(testhost)),
395+
(re.compile(r'sudo.*condor_rm'), 'STOP'),
396+
(re.compile(r'sudo.*condor_q'), ''),
397+
]
398+
from .. import CondorSpawner
399+
run_spawner_script(db, io_loop, CondorSpawner, script,
400+
batch_script_re_list=batch_script_re_list,
401+
spawner_kwargs=spawner_kwargs)
402+
403+
404+
def test_lfs(db, io_loop):
405+
spawner_kwargs = {
406+
'req_nprocs': '5',
407+
'req_memory': '5678',
408+
'req_options': 'some_option_asdf',
409+
'req_queue': 'some_queue',
410+
}
411+
batch_script_re_list = [
412+
re.compile(r'^singleuser_command', re.M),
413+
re.compile(r'#BSUB\s+-q\s+some_queue', re.M),
414+
]
415+
script = [
416+
(re.compile(r'sudo.*bsub'), 'Job <{}> is submitted to default queue <normal>'.format(str(testjob))),
417+
(re.compile(r'sudo.*bjobs'), 'PEND '.format(testhost)), # pending
418+
(re.compile(r'sudo.*bjobs'), 'RUN {}'.format(testhost)), # running
419+
(re.compile(r'sudo.*bjobs'), 'RUN {}'.format(testhost)),
420+
(re.compile(r'sudo.*bkill'), 'STOP'),
421+
(re.compile(r'sudo.*bjobs'), ''),
422+
]
423+
from .. import LsfSpawner
424+
run_spawner_script(db, io_loop, LsfSpawner, script,
425+
batch_script_re_list=batch_script_re_list,
426+
spawner_kwargs=spawner_kwargs)

0 commit comments

Comments
 (0)