Coverage for src/mockslurm/mock_scontrol.py: 81%
16 statements
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-07 13:34 +0000
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-07 13:34 +0000
1# Copyright 2026 CNRS
2# This software is distributed under the terms of the CeCILL-C free software license.
4"""Mock of scontrol.
6This extremely minimal mock only prints hardcoded values corresponding to the
7commands SAG uses in its tests in the SDE.
8"""
10import sys
12SCONTROL_SHOW_NODE_STR = """NodeName=localhost Arch=x86_64 CoresPerSocket=1
13 CPUAlloc=0 CPUTot=8 CPULoad=2.79
14 AvailableFeatures=(null)
15 ActiveFeatures=(null)
16 Gres=(null)
17 NodeAddr=localhost NodeHostName=localhost Version=20.02.7
18 OS=Linux 6.5.0-27-generic #28~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 15 10:51:06 UTC 2
19 RealMemory=5120 AllocMem=0 FreeMem=13771 Sockets=8 Boards=1
20 State=IDLE ThreadsPerCore=1 TmpDisk=0 Weight=1 Owner=N/A MCS_label=N/A
21 Partitions=test,prod
22 BootTime=2024-04-19T08:09:45 SlurmdStartTime=2024-04-19T09:38:48
23 CfgTRES=cpu=8,mem=5G,billing=8
24 AllocTRES=
25 CapWatts=n/a
26 CurrentWatts=0 AveWatts=0
27 ExtSensorsJoules=n/s ExtSensorsWatts=0 ExtSensorsTemp=n/s
30"""
33def main():
35 if len(sys.argv) < 4:
36 raise ValueError(
37 'scontrol mock only supports "scontrol show node node_name" or '
38 '"scontrol show hostnames node_name" commands, but got "{}"'.format(" ".join(["scontrol"] + sys.argv[1:]))
39 )
41 if sys.argv[1] != "show": 41 ↛ 42line 41 didn't jump to line 42 because the condition on line 41 was never true
42 raise NotImplementedError(f'scontrol mock only supports the "show" command, but got {sys.argv[1]}')
44 if sys.argv[3] != "localhost":
45 raise NotImplementedError(f'scontrol mock only supports node "localhost" but got {sys.argv[3]}')
47 match sys.argv[2]:
48 case "node":
49 print(SCONTROL_SHOW_NODE_STR, end="")
50 case "hostnames": 50 ↛ 52line 50 didn't jump to line 52 because the pattern on line 50 always matched
51 print("localhost")
52 case _:
53 raise NotImplementedError(
54 f'scontrol show mock only supports "hostnames" and "node" commands, but got {sys.argv[2]}'
55 )