Skip to content

Commit

Permalink
Extend scontrol output parser to be able to retrieve reservation info
Browse files Browse the repository at this point in the history
After this patch the `_parse_nodes_info` method is able to retrieve `ReservationName` field.
This info will be saved in the `reservation` attribute of the SlurmNode.

Signed-off-by: Enrico Usai <[email protected]>
  • Loading branch information
enrico-usai committed Oct 13, 2023
1 parent 659d56d commit 64f8715
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/common/schedulers/slurm_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
SCONTROL_OUTPUT_AWK_PARSER = (
'awk \'BEGIN{{RS="\\n\\n" ; ORS="######\\n";}} {{print}}\' | '
+ "grep -oP '^(NodeName=\\S+)|(NodeAddr=\\S+)|(NodeHostName=\\S+)|(?<!Next)(State=\\S+)|"
+ "(Partitions=\\S+)|(SlurmdStartTime=\\S+)|(LastBusyTime=\\S+)|(Reason=.*)|(######)'"
+ "(Partitions=\\S+)|(SlurmdStartTime=\\S+)|(LastBusyTime=\\S+)|(ReservationName=\\S+)|(Reason=.*)|(######)'"
)

# Set default timeouts for running different slurm commands.
Expand Down Expand Up @@ -389,15 +389,16 @@ def _parse_nodes_info(slurm_node_info: str) -> List[SlurmNode]:
"""Parse slurm node info into SlurmNode objects."""
# [ec2-user@ip-10-0-0-58 ~]$ /opt/slurm/bin/scontrol show nodes compute-dy-c5xlarge-[1-3],compute-dy-c5xlarge-50001\
# | awk 'BEGIN{{RS="\n\n" ; ORS="######\n";}} {{print}}' | grep -oP "^(NodeName=\S+)|(NodeAddr=\S+)
# |(NodeHostName=\S+)|(?<!Next)(State=\S+)|(Partitions=\S+)|(SlurmdStartTime=\S+)|(LastBusyTime=\\S+)|(Reason=.*)\
# |(######)"
# |(NodeHostName=\S+)|(?<!Next)(State=\S+)|(Partitions=\S+)|(SlurmdStartTime=\S+)|(LastBusyTime=\\S+)
# |(ReservationName=\S+)|(Reason=.*)|(######)"
# NodeName=compute-dy-c5xlarge-1
# NodeAddr=1.2.3.4
# NodeHostName=compute-dy-c5xlarge-1
# State=IDLE+CLOUD+POWER
# Partitions=compute,compute2
# SlurmdStartTime=2023-01-26T09:57:15
# Reason=some reason
# ReservationName=root_1
# ######
# NodeName=compute-dy-c5xlarge-2
# NodeAddr=1.2.3.4
Expand Down Expand Up @@ -430,6 +431,7 @@ def _parse_nodes_info(slurm_node_info: str) -> List[SlurmNode]:
"Reason": "reason",
"SlurmdStartTime": "slurmdstarttime",
"LastBusyTime": "lastbusytime",
"ReservationName": "reservation",
}

date_fields = ["SlurmdStartTime", "LastBusyTime"]
Expand Down
43 changes: 42 additions & 1 deletion tests/common/schedulers/test_slurm_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ def test_is_static_node(nodename, expected_is_static):
"State=IDLE+CLOUD+POWER\n"
"Partitions=multiple\n"
"SlurmdStartTime=2023-01-23T17:57:07\n"
"######\n"
"NodeName=queue1-st-crt2micro-1\n"
"NodeAddr=10.0.236.182\n"
"NodeHostName=queue1-st-crt2micro-1\n"
"State=IDLE+CLOUD+MAINTENANCE+RESERVED\n"
"Partitions=queue1\n"
"SlurmdStartTime=2023-01-23T17:57:07\n"
"LastBusyTime=2023-10-13T10:13:20\n"
"ReservationName=root_1\n"
"######\n",
[
StaticNode(
Expand All @@ -125,6 +134,16 @@ def test_is_static_node(nodename, expected_is_static):
"multiple",
slurmdstarttime=datetime(2023, 1, 23, 17, 57, 7).astimezone(tz=timezone.utc),
),
StaticNode(
"queue1-st-crt2micro-1",
"10.0.236.182",
"queue1-st-crt2micro-1",
"IDLE+CLOUD+MAINTENANCE+RESERVED",
"queue1",
slurmdstarttime=datetime(2023, 1, 23, 17, 57, 7).astimezone(tz=timezone.utc),
lastbusytime=datetime(2023, 10, 13, 10, 13, 20).astimezone(tz=timezone.utc),
reservation="root_1",
),
],
False,
),
Expand Down Expand Up @@ -1044,7 +1063,25 @@ def test_get_nodes_info_argument_validation(
" CurrentWatts=0 AveWatts=0\n"
" ExtSensorsJoules=n/s ExtSensorsWatts=0 ExtSensorsTemp=n/s\n"
" Reason=Reboot ASAP : reboot issued [slurm@2023-01-26T10:11:40]\n"
" Comment=some comment \n"
" Comment=some comment \n\n"
"NodeName=queue1-st-crt2micro-1 Arch=x86_64 CoresPerSocket=1\n"
" CPUAlloc=0 CPUEfctv=1 CPUTot=1 CPULoad=0.00\n"
" AvailableFeatures=static,t2.micro,crt2micro\n"
" ActiveFeatures=static,t2.micro,crt2micro\n"
" Gres=(null)\n"
" NodeAddr=10.0.236.182 NodeHostName=queue1-st-crt2micro-1 Version=23.02.4\n"
" OS=Linux 5.10.186-179.751.amzn2.x86_64 #1 SMP Tue Aug 1 20:51:38 UTC 2023\n"
" RealMemory=972 AllocMem=0 FreeMem=184 Sockets=1 Boards=1\n"
" State=IDLE+CLOUD+MAINTENANCE+RESERVED ThreadsPerCore=1 TmpDisk=0 Weight=1 Owner=N/A MCS_label=N/A\n"
" Partitions=queue1\n"
" BootTime=2023-10-13T10:09:58 SlurmdStartTime=2023-10-13T10:13:17\n"
" LastBusyTime=2023-10-13T10:13:20 ResumeAfterTime=None\n"
" CfgTRES=cpu=1,mem=972M,billing=1\n"
" AllocTRES=\n"
" CapWatts=n/a\n"
" CurrentWatts=0 AveWatts=0\n"
" ExtSensorsJoules=n/s ExtSensorsWatts=0 ExtSensorsTemp=n/s\n"
" ReservationName=root_5\n"
),
(
"NodeName=queue1-st-compute-resource-1-1\nNodeAddr=192.168.123.191\n"
Expand All @@ -1057,6 +1094,10 @@ def test_get_nodes_info_argument_validation(
"SlurmdStartTime=2023-01-26T09:57:16\n"
"LastBusyTime=Unknown\n"
"Reason=Reboot ASAP : reboot issued [slurm@2023-01-26T10:11:40]\n######\n"
"NodeName=queue1-st-crt2micro-1\nNodeAddr=10.0.236.182\n"
"NodeHostName=queue1-st-crt2micro-1\nState=IDLE+CLOUD+MAINTENANCE+RESERVED\nPartitions=queue1\n"
"SlurmdStartTime=2023-10-13T10:13:17\n"
"LastBusyTime=2023-10-13T10:13:20\nReservationName=root_5######\n"
),
)
],
Expand Down

0 comments on commit 64f8715

Please sign in to comment.