Skip to content

Commit 199a457

Browse files
authored
Merge pull request #3448 from c3se/develop
[bugfix] Fix constraint evaluation for Slurm features starting with numbers
2 parents 79a9e72 + 17f085c commit 199a457

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

reframe/core/schedulers/slurm.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -732,31 +732,22 @@ def is_down(self):
732732
return not self.is_avail()
733733

734734
def satisfies(self, slurm_constraint):
735-
def _replacemany(s, replacements):
736-
for src, dst in replacements:
737-
s = s.replace(src, dst)
738-
739-
return s
740-
741735
# Convert the Slurm constraint to a Python expression and evaluate it,
742736
# but restrict our syntax to accept only AND or OR constraints and
743-
# their combinations; to properly treat `-` in constraints we need to
744-
# convert them to valid Python identifiers before evaluating the
745-
# constraint.
746-
if not re.match(r'^[\-\w\d\(\)\|\&]*$', slurm_constraint):
737+
# their combinations; since Slurm features are not valid Python
738+
# identifiers, we replace them with booleans before evaluating.
739+
740+
if not re.match(r'^[\-\w\(\)\|\&]+$', slurm_constraint):
747741
return False
748742

749-
names = {
750-
grp[0] for grp in re.finditer(r'[\-\w][\-\w\d]*', slurm_constraint)
751-
}
752-
expr = _replacemany(slurm_constraint,
753-
[('-', '_'), ('|', ' or '), ('&', ' and ')])
754-
vars = {n.replace('-', '_'): True for n in self.active_features}
755-
vars.update({
756-
n.replace('-', '_'): False for n in names - self.active_features
757-
})
743+
expr = re.sub(
744+
r'[\-\w]+',
745+
lambda m: str(m.group(0) in self.active_features),
746+
slurm_constraint
747+
).replace('|', ' or ').replace('&', ' and ')
748+
758749
try:
759-
return eval(expr, {}, vars)
750+
return eval(expr)
760751
except BaseException:
761752
return False
762753

0 commit comments

Comments
 (0)