Add SLURM partition and cluster data classes

This commit is contained in:
Benoît Seignovert 2024-02-19 17:16:28 +01:00
parent 8529930db1
commit a163ecb575
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
2 changed files with 98 additions and 3 deletions

View file

@ -3,9 +3,11 @@
from pathlib import Path
from glicid_spawner.slurm import (
SlurmCluster,
SlurmCpu,
SlurmGpu,
SlurmNode,
SlurmPartition,
sinfo,
sinfo_filter,
sinfo_from_file,
@ -21,6 +23,7 @@ SINFO_CONTENT = SINFO_FILE.read_text()
def test_slurm_dataclasses():
"""Test SLURM dataclasses formatter."""
# CPU
cpu = SlurmCpu(1, '2', 4.0)
assert cpu.allocated == 1
@ -31,9 +34,11 @@ def test_slurm_dataclasses():
assert isinstance(cpu.idle, int)
assert isinstance(cpu.total, int)
# GPU
gpu = SlurmGpu('fOo', '1')
assert gpu # __bool__
assert str(gpu) == 'Foo' # = name
assert gpu.name == 'Foo'
assert gpu.nb == 1
@ -44,9 +49,47 @@ def test_slurm_dataclasses():
gpu = SlurmGpu()
assert not gpu # __bool__
assert str(gpu) == 'None' # = name
assert gpu.name == 'None'
assert gpu.nb == 0
# Node
node = SlurmNode(*'nautilus standard cnode001 completing 0/96/0/96 384000 (null)'.split())
assert str(node) == 'cnode001' # hostname
assert node.cluster == 'nautilus'
assert node.partition == 'standard'
assert node.hostname == 'cnode001'
assert node.state == 'completing'
assert node.cpu.allocated == 0
assert node.cpu.idle == 96
assert node.cpu.total == 96
assert node.mem == 384
assert node.gpu.name == 'None'
# Partition
partition = SlurmPartition('standard', [node])
assert str(partition) == 'standard' # = name
assert partition.name == 'standard'
for _node in partition:
assert str(_node) == 'cnode001'
assert partition.gpus == 'None'
assert partition.max_idle_cpu == 96
assert partition.max_mem == 384
# Cluster
cluster = SlurmCluster('nautilus', [partition])
assert str(cluster) == 'nautilus' # = name
assert cluster.name == 'nautilus'
assert cluster == 'nautilus' # __eq__
for _partition in cluster:
assert str(_partition) == 'standard'
def test_slurm_sinfo_run(monkeypatch):
"""Test SLURM SINFO run command."""