-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_g5kapi.py
64 lines (47 loc) · 1.7 KB
/
test_g5kapi.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
import node_reservation
from grid5000 import Grid5000
import os
import time
site = "lyon"
cluster = "taurus"
timeout = 1 #timeout in minutes for the job to stay on
walltime = "01:00"
number_of_nodes = 3
command = ""
def submit_job(gk, site, timeout, number_of_nodes, env, res_duration):
site = gk.sites[site]
job = site.jobs.create({"name": "bartering-deployment",
"command": "sleep 3600",
"types": ["deploy"],
"resources": f"nodes={number_of_nodes},walltime={res_duration}"})
while job.state != "running":
print(job.state)
job.refresh()
print("Waiting the job [%s] to be running" % job.uid)
time.sleep(10)
print("Assigned nodes : %s" % job.assigned_nodes)
deployment = site.deployments.create({"nodes": job.assigned_nodes,
"environment": env})
while deployment.status != "terminated":
print(deployment.status)
deployment.refresh()
print("Waiting for the deployment [%s] to be finished" % deployment.uid)
time.sleep(10)
print(deployment.result)
print(f"Job id : {job.uid}")
return job, deployment.result
conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml")
gk = Grid5000.from_yaml(conf_file)
job, result = submit_job(gk,site, "",3,"debian11-min","0:03:30")
print("result ",result)
print("job ",job)
nodes = []
for node in result.keys():
print(result[node]["state"])
if result[node]["state"]=='OK':
nodes.append(node)
else :
print("One of the nodes not OK - cannot continue job - will delete it")
os.system(f"oardel {job.uid}")
exit(-1)
print(nodes)