Merge lp:~stylesen/lava-scheduler/multinode into lp:lava-scheduler/multinode

Proposed by Senthil Kumaran S
Status: Merged
Approved by: Neil Williams
Approved revision: no longer in the source branch.
Merged at revision: 255
Proposed branch: lp:~stylesen/lava-scheduler/multinode
Merge into: lp:lava-scheduler/multinode
Diff against target: 74 lines (+42/-0)
2 files modified
lava_scheduler_app/api.py (+15/-0)
lava_scheduler_app/utils.py (+27/-0)
To merge this branch: bzr merge lp:~stylesen/lava-scheduler/multinode
Reviewer Review Type Date Requested Status
Linaro Automation & Validation Pending
Review via email: mp+171829@code.launchpad.net

Description of the change

Catch device availability during multinode job submission.

To post a comment you must log in.
255. By Neil Williams

Senthil Kumaran 2013-06-27 Detect device availability during job submission for multinode jobs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_scheduler_app/api.py'
2--- lava_scheduler_app/api.py 2013-06-20 11:41:39 +0000
3+++ lava_scheduler_app/api.py 2013-06-27 14:57:48 +0000
4@@ -2,6 +2,7 @@
5 from simplejson import JSONDecodeError
6 from django.db.models import Count
7 from linaro_django_xmlrpc.models import ExposedAPI
8+from lava_scheduler_app import utils
9 from lava_scheduler_app.models import (
10 Device,
11 DeviceType,
12@@ -27,6 +28,20 @@
13 "'lava_scheduler_app.add_testjob' permission. Contact "
14 "the administrators." % self.user.username)
15 try:
16+ requested_devices = utils.requested_device_count(job_data)
17+ if requested_devices:
18+ all_devices = {}
19+ for d in self.all_device_types():
20+ all_devices[d['name']] = d['idle'] + d['busy']
21+
22+ for board, count in requested_devices.iteritems():
23+ if all_devices.get(board, None) and \
24+ count <= all_devices[board]:
25+ continue
26+ else:
27+ raise xmlrpclib.Fault(
28+ 400, "Required number of device(s) unavailable.")
29+
30 job = TestJob.from_json_and_user(job_data, self.user)
31 except JSONDecodeError as e:
32 raise xmlrpclib.Fault(400, "Decoding JSON failed: %s." % e)
33
34=== modified file 'lava_scheduler_app/utils.py'
35--- lava_scheduler_app/utils.py 2013-06-27 12:17:42 +0000
36+++ lava_scheduler_app/utils.py 2013-06-27 14:57:48 +0000
37@@ -18,6 +18,7 @@
38 # along with LAVA Scheduler. If not, see <http://www.gnu.org/licenses/>.
39
40 import copy
41+import simplejson
42
43
44 def split_multi_job(json_jobdata, target_group):
45@@ -70,3 +71,29 @@
46 return node_json
47
48 return 0
49+
50+
51+def requested_device_count(json_data):
52+ """Utility function check the requested number of devices for each
53+ device_type in a multinode job.
54+
55+ JSON_DATA is the job definition string.
56+
57+ Returns requested_device which is a dictionary of the following format:
58+
59+ {'kvm': 1, 'qemu': 3, 'panda': 1}
60+
61+ If the job is not a multinode job, then return None.
62+ """
63+ job_data = simplejson.loads(json_data)
64+ if 'device_group' in job_data:
65+ requested_devices = {}
66+ for device_group in job_data['device_group']:
67+ device_type = device_group['device_type']
68+ count = device_group['count']
69+ requested_devices[device_type] = count
70+ return requested_devices
71+ else:
72+ # TODO: Put logic to check whether we have requested devices attached
73+ # to this lava-server, even if it is a single node job?
74+ return None

Subscribers

People subscribed via source and target branches

to status/vote changes: