Source code for mockslurm.mock_scontrol

#!/usr/bin/env python
"""Implements a mock of scontrol

This extremely minimal mock only prints hardcoded values corresponding to the
commands SAG uses in its tests in the SDE.
"""


import sys

SCONTROL_SHOW_NODE_STR = """NodeName=localhost Arch=x86_64 CoresPerSocket=1 
   CPUAlloc=0 CPUTot=8 CPULoad=2.79
   AvailableFeatures=(null)
   ActiveFeatures=(null)
   Gres=(null)
   NodeAddr=localhost NodeHostName=localhost Version=20.02.7
   OS=Linux 6.5.0-27-generic #28~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 15 10:51:06 UTC 2 
   RealMemory=5120 AllocMem=0 FreeMem=13771 Sockets=8 Boards=1
   State=IDLE ThreadsPerCore=1 TmpDisk=0 Weight=1 Owner=N/A MCS_label=N/A
   Partitions=test,prod 
   BootTime=2024-04-19T08:09:45 SlurmdStartTime=2024-04-19T09:38:48
   CfgTRES=cpu=8,mem=5G,billing=8
   AllocTRES=
   CapWatts=n/a
   CurrentWatts=0 AveWatts=0
   ExtSensorsJoules=n/s ExtSensorsWatts=0 ExtSensorsTemp=n/s
   

"""


[docs] def main(): if len(sys.argv) < 4: raise ValueError( 'scontrol mock only supports "scontrol show node node_name" or ' '"scontrol show hostnames node_name" commands, but got "{}"'.format(" ".join(["scontrol"] + sys.argv[1:])) ) if sys.argv[1] != "show": raise NotImplementedError('scontrol mock only supports the "show" command, but got {}'.format(sys.argv[1])) if sys.argv[3] != "localhost": raise NotImplementedError('scontrol mock only supports node "localhost" but got {}'.format(sys.argv[3])) match sys.argv[2]: case "node": print(SCONTROL_SHOW_NODE_STR, end="") case "hostnames": print("localhost") case _: raise NotImplementedError( 'scontrol show mock only supports "hostnames" and "node" commands, but got {}'.format(sys.argv[2]) )