Skip to content

Commit 6ca5b9c

Browse files
authored
Merge pull request #3569 from teojgo/feat/support_or_in_node_state
[feat] Support OR-ing node states in flexible node allocation
2 parents ce5a2e3 + 8458582 commit 6ca5b9c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

docs/manpage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ The way the tests are generated and how they interact with the test filtering op
10591059
``--distribute=NODESTATE`` now matches nodes that are exclusively in state ``NODESTATE``, so that the default ``--distribute=idle`` will match only the Slurm nodes that are in the ``IDLE`` state exclusively.
10601060
To achieve the previous behaviour, you should use ``--distribute=idle*``.
10611061

1062+
.. versionchanged:: 4.9
1063+
``--distribute=NODESTATE`` now allows you to specify multiple valid states using the ``|`` character.
10621064

10631065
.. option:: -P, --parameterize=[TEST.]VAR=VAL0,VAL1,...
10641066

reframe/core/schedulers/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,27 @@ def filter_nodes_by_state(nodelist, state):
161161
If ``all``, the initial list is returned untouched.
162162
If ``avail``, only the available nodes will be returned.
163163
All other values are interpreted as a state string.
164+
The pipe character ``|`` can be used as to specify multiple
165+
alternative node states.
164166
State match is exclusive unless the ``*`` is added at the end of the
165167
state string.
168+
When defining multiple states using ``|``, ``*`` has to be added at
169+
the end of each alternative state for which a non-exclusive match is
170+
required.
171+
166172
:returns: the filtered node list
173+
174+
.. versionchanged:: 4.9
175+
Support the ``|`` character to filter according to alternative states.
167176
'''
168-
if state == 'avail':
177+
if '|' in state:
178+
allowed_states = state.split('|')
179+
final_nodelist = set()
180+
for s in allowed_states:
181+
final_nodelist.update(filter_nodes_by_state(nodelist, s))
182+
183+
nodelist = final_nodelist
184+
elif state == 'avail':
169185
nodelist = {n for n in nodelist if n.is_avail()}
170186
elif state != 'all':
171187
if state.endswith('*'):

unittests/test_schedulers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,31 @@ def test_flex_alloc_not_enough_nodes_constraint_expr(make_flexible_job):
12471247
prepare_job(job)
12481248

12491249

1250+
def test_flex_alloc_alloc_state_OR(make_flexible_job):
1251+
job = make_flexible_job('allocated|idle')
1252+
job.options = ['--partition=p3']
1253+
prepare_job(job)
1254+
assert job.num_tasks == 12
1255+
1256+
job = make_flexible_job('maint*|idle')
1257+
prepare_job(job)
1258+
assert job.num_tasks == 16
1259+
1260+
job = make_flexible_job('maint|avail')
1261+
job.options = ['--partition=p1']
1262+
prepare_job(job)
1263+
assert job.num_tasks == 12
1264+
1265+
job = make_flexible_job('all|idle')
1266+
prepare_job(job)
1267+
assert job.num_tasks == 16
1268+
1269+
job = make_flexible_job('allocated|idle|maint')
1270+
job.options = ['--partition=p1']
1271+
prepare_job(job)
1272+
assert job.num_tasks == 12
1273+
1274+
12501275
@pytest.fixture
12511276
def slurm_node_allocated():
12521277
return _SlurmNode(

0 commit comments

Comments
 (0)