From aaf16ee89d16b73a94100f57c3ab9cf69d2acb2d Mon Sep 17 00:00:00 2001 From: Benoit Seignovert Date: Fri, 22 Mar 2024 19:41:27 +0100 Subject: [PATCH] Enforce cluster flag in sinfo query --- render/__main__.py | 2 +- src/glicid_spawner/slurm.py | 2 +- .../templates/views/slurm.jinja | 2 +- tests/data/sinfo.txt | 14 ++++++------- tests/test_form.py | 20 +++++++++---------- tests/test_slurm.py | 10 ++++++---- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/render/__main__.py b/render/__main__.py index f554c5a..a3eaac6 100644 --- a/render/__main__.py +++ b/render/__main__.py @@ -32,7 +32,7 @@ SINFO = sinfo_from_file( ) # Single vs. multi-cluster implementation -SLURM_SINGLE_CLUSTER = {'N/A': SINFO.pop('N/A')} +SLURM_SINGLE_CLUSTER = {'cluster': SINFO.pop('cluster')} SLURM_MULTI_CLUSTER = SINFO GPU_SINGLE_CLUSTER = gpu_max_duration(gres(SLURM_SINGLE_CLUSTER)) GPU_MULTI_CLUSTER = gpu_max_duration(gres(SLURM_MULTI_CLUSTER)) diff --git a/src/glicid_spawner/slurm.py b/src/glicid_spawner/slurm.py index 011193e..1aea52d 100644 --- a/src/glicid_spawner/slurm.py +++ b/src/glicid_spawner/slurm.py @@ -141,7 +141,7 @@ class SlurmCluster: def sinfo_run(username: str = None) -> str: """SLURM SINFO run command.""" - flags = '--federation --noheader --responding' + flags = '--federation --noheader --responding --cluster=all' fmt = 'Cluster,PartitionName,NodeHost,StateLong,CPUsState,Memory,Gres' cmd = f'sinfo {flags} --Format={fmt}' diff --git a/src/glicid_spawner/templates/views/slurm.jinja b/src/glicid_spawner/templates/views/slurm.jinja index 5486b16..6980efd 100644 --- a/src/glicid_spawner/templates/views/slurm.jinja +++ b/src/glicid_spawner/templates/views/slurm.jinja @@ -11,7 +11,7 @@
- {% if 'N/A' not in sinfo %} + {% if 'cluster' not in sinfo %}
diff --git a/tests/data/sinfo.txt b/tests/data/sinfo.txt index 4dcb4ae..37d0b25 100644 --- a/tests/data/sinfo.txt +++ b/tests/data/sinfo.txt @@ -1,10 +1,10 @@ -N/A Devel nazare001 idle 0/20/0/20 128000 (null) -N/A GPU-short budbud001 mixed 20/20/0/40 184000 gpu:t4:2,mps:t4:2000 -N/A A40-short budbud002 allocated 40/0/0/40 184000 gpu:a40:2,mps:a40:20 -N/A AMD-short cloudbreak001 drained 0/0/32/32 128000 (null) -N/A lowp budbud003 down~ 0/0/40/40 128000 gpu:p100:2 -N/A lowp budbud004 drained~ 0/0/20/20 128000 gpu:k80:4 -N/A lowp budbud005 idle~ 0/20/0/20 192000 gpu:p100:1 +cluster Devel nazare001 idle 0/20/0/20 128000 (null) +cluster GPU-short budbud001 mixed 20/20/0/40 184000 gpu:t4:2,mps:t4:2000 +cluster A40-short budbud002 allocated 40/0/0/40 184000 gpu:a40:2,mps:a40:20 +cluster AMD-short cloudbreak001 drained 0/0/32/32 128000 (null) +cluster lowp budbud003 down~ 0/0/40/40 128000 gpu:p100:2 +cluster lowp budbud004 drained~ 0/0/20/20 128000 gpu:k80:4 +cluster lowp budbud005 idle~ 0/20/0/20 192000 gpu:p100:1 nautilus standard cnode001 completing 0/96/0/96 384000 (null) nautilus bigmem cnode002 planned 0/96/0/96 768000 (null) nautilus gpu gnode1 mixed 4/92/0/96 768000 gpu:A100:1(S:0-1) diff --git a/tests/test_form.py b/tests/test_form.py index 99b8895..65aa099 100644 --- a/tests/test_form.py +++ b/tests/test_form.py @@ -12,7 +12,7 @@ from pytest import fixture DATA = Path(__file__).parent / 'data' SINFO = sinfo_from_file(DATA / 'sinfo.txt') -SLURM_SINGLE_CLUSTER = {'N/A': SINFO.pop('N/A')} +SLURM_SINGLE_CLUSTER = {'cluster': SINFO.pop('cluster')} SLURM_MULTI_CLUSTER = SINFO @@ -81,7 +81,7 @@ def test_options_attrs(mock_cluster): # Multi cluster configuration (default) sinfo = options['sinfo'] - assert 'N/A' not in sinfo + assert 'cluster' not in sinfo assert 'nautilus' in sinfo assert 'waves' in sinfo @@ -99,11 +99,11 @@ def test_options_attrs_single_cluster(mock_single_cluster): # Single cluster configuration sinfo = options['sinfo'] - assert 'N/A' in sinfo + assert 'cluster' in sinfo assert 'nautilus' not in sinfo assert 'waves' not in sinfo - node = sinfo['N/A']['Devel']['nazare001'] + node = sinfo['cluster']['Devel']['nazare001'] assert node == 'nazare001' assert node.cpu.idle == 20 @@ -218,32 +218,32 @@ def test_options_form_slurm_single_cluster(mock_single_cluster): assert ( '
' in html ) assert ( - '' + '' in html ) assert ( - '' + '' in html ) # Nodes (hidden by default) assert ( '
' in html ) assert ( - '' + '' in html ) assert ( - '' + '' in html ) diff --git a/tests/test_slurm.py b/tests/test_slurm.py index 28e23f1..a4d8693 100644 --- a/tests/test_slurm.py +++ b/tests/test_slurm.py @@ -105,6 +105,7 @@ def test_slurm_sinfo_run(monkeypatch): '--federation ' '--noheader ' '--responding ' + '--cluster=all ' '--Format=Cluster,PartitionName,NodeHost,StateLong,CPUsState,Memory,Gres' ) @@ -114,6 +115,7 @@ def test_slurm_sinfo_run(monkeypatch): '--federation ' '--noheader ' '--responding ' + '--cluster=all ' '--Format=Cluster,PartitionName,NodeHost,StateLong,CPUsState,Memory,Gres' ) @@ -127,7 +129,7 @@ def test_slurm_sinfo_reader(): node = nodes[0] - assert node.cluster == 'N/A' + assert node.cluster == 'cluster' assert node.partition == 'Devel' assert node.hostname == 'nazare001' assert node.state == 'idle' @@ -136,7 +138,7 @@ def test_slurm_sinfo_reader(): assert node.mem == 128 assert not node.gpu - assert [node.cluster for node in nodes] == 7 * ['N/A'] + 12 * ['nautilus'] + 6 * ['waves'] + assert [node.cluster for node in nodes] == 7 * ['cluster'] + 12 * ['nautilus'] + 6 * ['waves'] assert len([node for node in nodes if node.state in ('idle', 'mixed')]) == 10 @@ -172,7 +174,7 @@ def test_slurm_sinfo_filter(monkeypatch): assert isinstance(clusters, dict) assert len(clusters) == 3 - assert list(clusters) == ['N/A', 'nautilus', 'waves'] # __eq__ on cluster.name + assert list(clusters) == ['cluster', 'nautilus', 'waves'] # __eq__ on cluster.name assert [len(partitions) for partitions in clusters.values()] == [2, 4, 2] @@ -195,7 +197,7 @@ def test_slurm_sinfo_filter(monkeypatch): # Get only `idle` nodes clusters = sinfo_filter(resources, with_states=('idle')) - assert list(clusters) == ['N/A', 'nautilus'] + assert list(clusters) == ['cluster', 'nautilus'] assert [len(partitions) for partitions in clusters.values()] == [1, 3] # Discard clusters without partition available