-
Notifications
You must be signed in to change notification settings - Fork 24
/
test_jobs.py
224 lines (189 loc) · 7.83 KB
/
test_jobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import logging
import pytest
from hostlist import expand_hostlist as expand
from deploy import Cluster
from testutils import (
wait_job_state,
wait_node_state,
wait_node_flags_any,
sbatch,
run,
util,
)
from util import Lookup
log = logging.getLogger()
def test_job(cluster):
job_id = sbatch(cluster, "sbatch -N3 --wrap='srun hostname'")
job = wait_job_state(cluster, job_id, "COMPLETED", "FAILED", "CANCELLED")
assert job["job_state"][0] == "COMPLETED"
def test_openmpi(cluster):
prog = r"""
#include <stdio.h>
#include <mpi.h>
int main(int argc, char **argv)
{
int node;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &node);
printf("Hello World from Node %d\n", node);
MPI_Finalize();
}
"""
cluster.login_exec("tee hello.c", input=prog)
cluster.login_exec(
"bash --login -c 'module load openmpi && mpicc -o hello hello.c'"
)
job_id = sbatch(cluster, "sbatch -N3 --wrap='srun hello'")
job = wait_job_state(cluster, job_id, "COMPLETED", "FAILED", "CANCELLED")
log.info(cluster.login_get_file(f"slurm-{job_id}.out"))
assert job["job_state"][0] == "COMPLETED"
def test_gpu_job(cluster, lkp):
gpu_parts = {}
for part_name, partition in lkp.cfg.partitions.items():
for nodeset_name in partition.partition_nodeset:
nodeset = lkp.cfg.nodeset.get(nodeset_name)
template = lkp.template_info(nodeset.instance_template)
if (
template.gpu_count > 0
and not template.shieldedInstanceConfig.enableSecureBoot
):
gpu_parts[part_name] = partition
if not gpu_parts:
pytest.skip("no gpu partitions found")
return
for part_name, partition in gpu_parts.items():
job_id = sbatch(
cluster,
f"sbatch --partition={part_name} --gpus=1 --wrap='srun nvidia-smi'",
)
job = wait_job_state(cluster, job_id, "COMPLETED", "FAILED", "CANCELLED")
assert job["job_state"][0] == "COMPLETED"
log.info(cluster.login_exec_output(f"cat slurm-{job_id}.out"))
def test_shielded(image_marker, cluster: Cluster, lkp: Lookup):
# only run test for ubuntu-2004
log.info(f"detected image_marker:{image_marker}")
if image_marker == "debian-11-arm64":
pytest.skip("shielded not supported on {image_marker}")
skip_gpus = "ubuntu-2004" not in image_marker
shielded_parts = {}
for part_name, partition in lkp.cfg.partitions.items():
has_gpus = any(
lkp.template_info(
lkp.cfg.nodeset.get(nodeset_name).instance_template
).gpu_count
> 0
for nodeset_name in partition.partition_nodeset
)
if skip_gpus and has_gpus:
continue
for nodeset_name in partition.partition_nodeset:
nodeset = lkp.cfg.nodeset.get(nodeset_name)
template = lkp.template_info(nodeset.instance_template)
if template.shieldedInstanceConfig.enableSecureBoot:
shielded_parts[part_name] = partition
partition.has_gpus = has_gpus
if not shielded_parts:
pytest.skip("No viable partitions with shielded instances found")
return
for part_name, partition in shielded_parts.items():
if partition.has_gpus:
job_id = sbatch(
cluster,
f"sbatch --partition={part_name} --gpus=1 --wrap='srun nvidia-smi'",
)
else:
job_id = sbatch(
cluster,
f"sbatch --partition={part_name} --wrap='srun hostname'",
)
job = wait_job_state(cluster, job_id, "COMPLETED", "FAILED", "CANCELLED")
assert job["job_state"][0] == "COMPLETED"
log.info(cluster.login_exec_output(f"cat slurm-{job_id}.out"))
def test_placement_groups(cluster, lkp):
nodesets = []
for nodeset_name, nodeset in lkp.cfg.nodeset.items():
if nodeset.enable_placement:
nodesets.append(nodeset_name)
partitions = []
for part_name, partition in lkp.cfg.partitions.items():
if any(item in nodesets for item in partition.partition_nodeset):
partitions.append(part_name)
if not partitions:
pytest.skip("no partitions with placement groups enabled")
return
def placement_job(part_name):
job_id = sbatch(
cluster, f"sbatch -N3 --partition={part_name} --wrap='sleep 600'"
)
job = wait_job_state(cluster, job_id, "RUNNING", max_wait=300)
nodes = expand(job["nodes"])
physical_hosts = {
node: lkp.describe_instance(node).resourceStatus.physicalHost or None
for node in nodes
}
# this isn't working sometimes now. None are matching
log.debug(
"matching physicalHost IDs: {}".format(
set.intersection(*map(set, physical_hosts.values()))
)
)
# assert bool(set.intersection(*physical_hosts))
assert all(host is not None for node, host in physical_hosts.items())
cluster.login_exec(f"scancel {job_id}")
job = wait_job_state(cluster, job_id, "CANCELLED")
for node in nodes:
wait_node_flags_any(cluster, node, "idle", "POWERED_DOWN", max_wait=240)
util.execute_with_futures(placement_job, partitions)
# def test_partition_jobs(cluster):
# jobs = []
# for name, part in cluster_partitions.items():
# job_id = sbatch(
# cluster, f"sbatch -N2 --partition={name} --wrap='srun hostname'"
# )
# jobs.append(job_id)
# for job_id in jobs:
# job = wait_job_state(cluster, job_id, "COMPLETED", "FAILED", "CANCELLED")
# assert job["job_state"][0] == "COMPLETED"
def test_preemption(cluster: Cluster, lkp: Lookup):
partitions = []
for part_name, partition in lkp.cfg.partitions.items():
for nodeset_name in partition.partition_nodeset:
nodeset = lkp.cfg.nodeset.get(nodeset_name)
template = lkp.template_info(nodeset.instance_template)
if template.scheduling.preemptible:
partitions.append(part_name)
break
if not partitions:
pytest.skip("no partitions with preemptible nodes")
return
def preemptible_job(part_name):
job_id = sbatch(
cluster, f"sbatch -N2 --partition={part_name} --wrap='srun sleep 9999'"
)
job = wait_job_state(cluster, job_id, "RUNNING")
last_node = expand(job["nodes"])[-1]
lkp.instances.cache_clear()
inst = lkp.instance(last_node)
run(f"gcloud compute instances stop {last_node} --zone={inst.zone}")
node = wait_node_state(cluster, last_node, "down", max_wait=180)
assert node["reason"] == "Instance stopped/deleted"
wait_node_state(cluster, last_node, "idle")
cluster.login_exec(f"scancel {job_id}")
wait_job_state(cluster, job_id, "CANCELLED")
util.execute_with_futures(preemptible_job, partitions)
def test_prolog_scripts(cluster: Cluster, lkp: Lookup):
"""check that the prolog and epilog scripts ran"""
# The partition this runs on must not be job exclusive so the VM stays
# after job completion
job_id = sbatch(cluster, "sbatch -N1 --wrap='srun sleep 999'")
job = wait_job_state(cluster, job_id, "RUNNING", max_wait=300)
node = next(iter(expand(job["nodes"])))
node_ssh = cluster.ssh(lkp.instance(node).selfLink)
check = cluster.exec_cmd(node_ssh, f"ls /slurm/out/prolog_{job_id}")
log.debug(f"{check.command}: {check.stdout or check.stderr}")
assert check.exit_status == 0
cluster.login_exec(f"scancel {job_id}")
wait_job_state(cluster, job_id, "CANCELLED", max_wait=300)
check = cluster.exec_cmd(node_ssh, f"ls /slurm/out/epilog_{job_id}")
log.debug(f"{check.command}: {check.stdout or check.stderr}")
assert check.exit_status == 0