Skip to content

Commit 7dee9e7

Browse files
authored
Merge pull request #3352 from vkarak/bugfix/jobopts-constraints
[bugfix] Fix treatment of Slurm constraints in `job.options` and system partition's `access` parameter
2 parents 3637536 + 727f46a commit 7dee9e7

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

reframe/core/schedulers/slurm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def emit_preamble(self, job):
234234
job._cli_options = other_cli_opts
235235

236236
arg = '&'.join(f'({c.strip()})' for c in constraints)
237-
job._sched_access = [f'--constraint={arg}']
237+
job._sched_access = [f'--constraint={arg}'] + access_other
238238

239239
if not self._sched_access_in_submit:
240240
for opt in job.sched_access:
@@ -244,8 +244,10 @@ def emit_preamble(self, job):
244244
prefix_patt = re.compile(r'(#\w+)')
245245
for opt in job.options + job.cli_options:
246246
if opt.strip().startswith(('-C', '--constraint')):
247-
# Constraints are already processed
248-
continue
247+
if access.constraint:
248+
# Constraints are already combined with the `sched_access`
249+
# and processed
250+
continue
249251

250252
if not prefix_patt.match(opt):
251253
preamble.append('%s %s' % (self._prefix, opt))

unittests/test_schedulers.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ def test_prepare_without_smt(fake_job, slurm_only):
452452
assert re.search(r'--hint=nomultithread', fp.read()) is not None
453453

454454

455+
def test_prepare_with_constraints(fake_job, slurm_only):
456+
fake_job.options = ['--constraint=foo']
457+
prepare_job(fake_job)
458+
with open(fake_job.script_filename) as fp:
459+
assert re.search(r'#SBATCH --constraint=foo', fp.read()) is not None
460+
461+
455462
def test_prepare_nodes_option(make_exec_ctx, make_job, slurm_only):
456463
make_exec_ctx(test_util.TEST_CONFIG_FILE, 'testsys')
457464
job = make_job(sched_opts={'part_name': 'gpu'})
@@ -625,42 +632,47 @@ def test_no_empty_lines_in_preamble(minimal_job):
625632

626633

627634
def test_combined_access_constraint(make_job, slurm_only):
628-
job = make_job(sched_access=['--constraint=c1'])
635+
job = make_job(sched_access=['--constraint=c1', '-A acct', '-p part'])
629636
job.options = ['-C c2&c3']
630637
prepare_job(job)
631638
with open(job.script_filename) as fp:
632639
script_content = fp.read()
633640

634-
print(script_content)
641+
assert re.search('-A acct', script_content)
642+
assert re.search('-p part', script_content)
635643
assert re.search(r'(?m)--constraint=\(c1\)&\(c2&c3\)$', script_content)
636644
assert re.search(r'(?m)--constraint=(c1|c2&c3)$', script_content) is None
637645

638646

639647
def test_combined_access_multiple_constraints(make_job, slurm_only):
640-
job = make_job(sched_access=['--constraint=c1'])
648+
job = make_job(sched_access=['--constraint=c1', '-A acct', '-p part'])
641649
job.options = ['--constraint=c2', '-C c3']
642650
prepare_job(job)
643651
with open(job.script_filename) as fp:
644652
script_content = fp.read()
645653

654+
assert re.search('-A acct', script_content)
655+
assert re.search('-p part', script_content)
646656
assert re.search(r'(?m)--constraint=\(c1\)&\(c3\)$', script_content)
647657
assert re.search(r'(?m)--constraint=(c1|c2|c3)$', script_content) is None
648658

649659

650660
def test_combined_access_verbatim_constraint(make_job, slurm_only):
651-
job = make_job(sched_access=['--constraint=c1'])
661+
job = make_job(sched_access=['--constraint=c1', '-A acct', '-p part'])
652662
job.options = ['#SBATCH --constraint=c2', '#SBATCH -C c3']
653663
prepare_job(job)
654664
with open(job.script_filename) as fp:
655665
script_content = fp.read()
656666

667+
assert re.search('-A acct', script_content)
668+
assert re.search('-p part', script_content)
657669
assert re.search(r'(?m)--constraint=c1$', script_content)
658670
assert re.search(r'(?m)^#SBATCH --constraint=c2$', script_content)
659671
assert re.search(r'(?m)^#SBATCH -C c3$', script_content)
660672

661673

662674
def test_sched_access_in_submit(make_job):
663-
job = make_job(sched_access=['--constraint=c1', '--foo=bar'])
675+
job = make_job(sched_access=['--constraint=c1', '-A acct'])
664676
job.options = ['--constraint=c2', '--xyz']
665677
job.scheduler._sched_access_in_submit = True
666678

@@ -673,7 +685,7 @@ def test_sched_access_in_submit(make_job):
673685

674686
print(script_content)
675687
assert '--xyz' in script_content
676-
assert '--foo=bar' not in script_content
688+
assert '-A acct' not in script_content
677689
if job.scheduler.registered_name in ('slurm', 'squeue'):
678690
# Constraints are combined in `sched_access` for Slurm backends
679691
assert '--constraint' not in script_content

0 commit comments

Comments
 (0)