Run scontrol as a standalone subprocess and parse its output in Python#709
Merged
Merged
Conversation
c8e33cf to
d35fc2d
Compare
hehe7318
reviewed
Jun 19, 2026
| stderr, | ||
| ) | ||
| if raise_on_error: | ||
| raise subprocess.CalledProcessError(result.returncode, command, output=stdout, stderr=result.stderr) |
Contributor
There was a problem hiding this comment.
[Block]
aws-parallelcluster-node/src/common/utils.py
Lines 181 to 209 in aca9d7b
In the old _run_command it also catches OSError, can we add the except OSError to align?
Contributor
Author
There was a problem hiding this comment.
Done! Added in line 386 - 388
hehe7318
reviewed
Jun 19, 2026
hehe7318
left a comment
Contributor
There was a problem hiding this comment.
Good PR, only 1 blocking comment, others LGTM.
`get_nodes_info`, `get_partitions_info`, and `get_slurm_reservations_info` previously invoked `scontrol` through a shell pipeline (`scontrol ... | awk ... | grep ...`). When the pipeline failed, only the last command's exit code was reported, so a `scontrol` failure and a parsing failure were indistinguishable. This change runs scontrol on its own and does the field extraction and parsing in Python: Add `_run_scontrol_command`, which runs scontrol as a single subprocess (no shell), capturing stdout, stderr, and the exit code separately and logging them. This replaces the awk record splitting and grep -oP field filtering. `_parse_nodes_info`, `_parse_reservations_info`, and `_parse_partitions_info` now consume the list of extracted records `get_partitions_info` now uses scontrol show partitions (the `-o` oneliner is no longer needed, since records are split on blank lines like the node and reservation commands). * `shell=True` is removed from these paths, which is also a security improvement; `awk` and `grep` are no longer required at runtime. * Partition filtering is now an exact match on the partition name (the previous grep -e "PartitionName=<name>" also matched names by substring).
d35fc2d to
6e1d6fa
Compare
hehe7318
approved these changes
Jun 22, 2026
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.
Description of changes
get_nodes_info,get_partitions_info, andget_slurm_reservations_infopreviously invokedscontrolthrough a shell pipeline (scontrol ... | awk ... | grep ...). When the pipeline failed, only the last command's exit code was reported, so ascontrolfailure and a parsing failure were indistinguishable.This change runs scontrol on its own and does the field extraction and parsing in Python:
Add
_run_scontrol_command, which runs scontrol as a single subprocess (no shell), capturing stdout, stderr, and the exit code separately and logging them. This replaces the awk record splitting and grep -oP field filtering._parse_nodes_info,_parse_reservations_info, and_parse_partitions_infonow consume the list of extracted recordsget_partitions_infonow uses scontrol show partitions (the-ooneliner is no longer needed, since records are split on blank lines like the node and reservation commands).shell=Trueis removed from these paths, which is also a security improvement;awkandgrepare no longer required at runtime.Tests
Checklist
developadd the branch name as prefix in the PR title (e.g.[release-3.6]).Please review the guidelines for contributing and Pull Request Instructions.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.