Parse SchedMD pre-release / zero-padded Slurm versions robustly - #200
Merged
gunchu merged 2 commits intoJul 14, 2026
Merged
Conversation
## Summary
`slurm_version()` parsed the Slurm version with `tuple(int(v) for v in version.split("."))`, which assumes every dot-separated component is a plain integer. SchedMD pre-release builds append a `-<n>pre<n>` suffix to the micro version, so `sinfo -V` reports e.g. `slurm 26.05.2-0pre1` and `int("2-0pre1")` raises `ValueError: invalid literal for int() with base 10: '2-0pre1'`. This crashes every caller — for example gcm's `slurm_monitor` poller — on clusters running Slurm built from a SchedMD development branch rather than a tagged release.
Parse the numeric release with `packaging.version.Version` after stripping the non-PEP440 pre-release suffix. `packaging` also normalizes the zero-padded `YY.MM` minor (`26.05` -> `26`), which strict SemVer rejects outright. The `Tuple[int, ...]` return type is unchanged so existing comparisons (e.g. `slurm_version() >= (23, 2)`) keep working, and any unexpected string falls back to the original split. Adds `packaging` (pure-Python, already ubiquitous) to `dependencies`.
## Test Plan
Exercised the patched `slurm_version()` with the version string mocked to each SchedMD form — including the zero-padded pre-release the old `int()` split crashed on:
```
$ python -c "
from unittest.mock import patch
import clusterscope.lib as lib
for s in ['26.05.2-0pre1', '24.11.2-0pre1', '24.05.0', '25.11']:
with patch.object(lib, 'get_unified_info') as m:
m.return_value.get_slurm_version.return_value = s
print(f'{s:16} -> {lib.slurm_version()}')
"
26.05.2-0pre1 -> (26, 5, 2)
24.11.2-0pre1 -> (24, 11, 2)
24.05.0 -> (24, 5, 0)
25.11 -> (25, 11)
```
luccabb
approved these changes
Jul 13, 2026
Address review feedback: catch only `packaging.version.InvalidVersion` (the sole expected failure when normalizing the SchedMD version string) instead of a bare `except Exception`, so unexpected errors propagate rather than silently hitting the legacy split.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
slurm_version()parsed the Slurm version withtuple(int(v) for v in version.split(".")), which assumes every dot-separated component is a plain integer. SchedMD pre-release builds append a-<n>pre<n>suffix to the micro version, sosinfo -Vreports e.g.slurm 26.05.2-0pre1andint("2-0pre1")raisesValueError: invalid literal for int() with base 10: '2-0pre1'. This crashes every caller — for example gcm'sslurm_monitorpoller — on clusters running Slurm built from a SchedMD development branch rather than a tagged release.Parse the numeric release with
packaging.version.Versionafter stripping the non-PEP440 pre-release suffix.packagingalso normalizes the zero-paddedYY.MMminor (26.05->26), which strict SemVer rejects outright. TheTuple[int, ...]return type is unchanged so existing comparisons (e.g.slurm_version() >= (23, 2)) keep working, and any unexpected string falls back to the original split. Addspackaging(pure-Python, already ubiquitous) todependencies.Test Plan
Exercised the patched
slurm_version()with the version string mocked to each SchedMD form — including the zero-padded pre-release the oldint()split crashed on: