diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-06-12 12:57:22 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-06-13 11:55:34 +0100 |
commit | e16352220572835ff2185cf992518fb4f3b2de0e (patch) | |
tree | 34ed801e6883d1ebd8e00d4431785dd5e7255039 /bitbake/lib/toaster/bldcontrol/management | |
parent | 87b99274e9c90101ec9d4c49ce0874bcb85f7746 (diff) | |
download | poky-e16352220572835ff2185cf992518fb4f3b2de0e.tar.gz |
bitbake: toaster: build control functionality
We add the build control functionality to toaster.
* The bldcontrol application gains bbcontroller classes
that know how to manage a localhost build environment.
* The toaster UI now detects it is running under build
environment controller, and update the build controller
database and will shut down the bitbake server once
the build is complete.
* The toaster script can now run in standalone mode,
launching the build controller and the web interface instead
of just monitoring the build, as in the interactive mode.
* A fixture with the default build controller entry for
localhost is provided.
[YOCTO #5490]
[YOCTO #5491]
[YOCTO #5492]
[YOCTO #5493]
[YOCTO #5494]
[YOCTO #5537]
(Bitbake rev: 10988bd77c8c7cefad3b88744bc5d8a7e3c1f4cf)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/bldcontrol/management')
3 files changed, 85 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/management/__init__.py b/bitbake/lib/toaster/bldcontrol/management/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bitbake/lib/toaster/bldcontrol/management/__init__.py | |||
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/__init__.py b/bitbake/lib/toaster/bldcontrol/management/commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bitbake/lib/toaster/bldcontrol/management/commands/__init__.py | |||
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py b/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py new file mode 100644 index 0000000000..dd8f84b07a --- /dev/null +++ b/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py | |||
@@ -0,0 +1,85 @@ | |||
1 | from django.core.management.base import NoArgsCommand, CommandError | ||
2 | from django.db import transaction | ||
3 | from orm.models import Build | ||
4 | from bldcontrol.bbcontroller import getBuildEnvironmentController, ShellCmdException | ||
5 | from bldcontrol.models import BuildRequest, BuildEnvironment | ||
6 | import os | ||
7 | |||
8 | class Command(NoArgsCommand): | ||
9 | args = "" | ||
10 | help = "Schedules and executes build requests as possible. Does not return (interrupt with Ctrl-C)" | ||
11 | |||
12 | |||
13 | @transaction.commit_on_success | ||
14 | def _selectBuildEnvironment(self): | ||
15 | bec = getBuildEnvironmentController(lock = BuildEnvironment.LOCK_FREE) | ||
16 | bec.be.lock = BuildEnvironment.LOCK_LOCK | ||
17 | bec.be.save() | ||
18 | return bec | ||
19 | |||
20 | @transaction.commit_on_success | ||
21 | def _selectBuildRequest(self): | ||
22 | br = BuildRequest.objects.filter(state = BuildRequest.REQ_QUEUED).order_by('pk')[0] | ||
23 | br.state = BuildRequest.REQ_INPROGRESS | ||
24 | br.save() | ||
25 | return br | ||
26 | |||
27 | def schedule(self): | ||
28 | try: | ||
29 | br = None | ||
30 | try: | ||
31 | # select the build environment and the request to build | ||
32 | br = self._selectBuildRequest() | ||
33 | except IndexError as e: | ||
34 | return | ||
35 | try: | ||
36 | bec = self._selectBuildEnvironment() | ||
37 | except IndexError as e: | ||
38 | # we could not find a BEC; postpone the BR | ||
39 | br.state = BuildRequest.REQ_QUEUED | ||
40 | br.save() | ||
41 | return | ||
42 | |||
43 | # set up the buid environment with the needed layers | ||
44 | print "Build %s, Environment %s" % (br, bec.be) | ||
45 | bec.setLayers(br.brlayer_set.all()) | ||
46 | |||
47 | # get the bb server running | ||
48 | bbctrl = bec.getBBController() | ||
49 | |||
50 | # let toasterui that this is a managed build | ||
51 | bbctrl.setVariable("TOASTER_BRBE", "%d:%d" % (br.pk, bec.be.pk)) | ||
52 | |||
53 | # set the build configuration | ||
54 | for variable in br.brvariable_set.all(): | ||
55 | bbctrl.setVariable(variable.name, variable.value) | ||
56 | |||
57 | # trigger the build command | ||
58 | bbctrl.build(list(map(lambda x:x.target, br.brtarget_set.all()))) | ||
59 | |||
60 | print "Build launched, exiting" | ||
61 | # disconnect from the server | ||
62 | bbctrl.disconnect() | ||
63 | |||
64 | # cleanup to be performed by toaster when the deed is done | ||
65 | |||
66 | except ShellCmdException as e: | ||
67 | import traceback | ||
68 | print " EE Error executing shell command\n", e | ||
69 | traceback.format_exc(e) | ||
70 | |||
71 | except Exception as e: | ||
72 | import traceback | ||
73 | traceback.print_exc() | ||
74 | raise e | ||
75 | |||
76 | def cleanup(self): | ||
77 | from django.utils import timezone | ||
78 | from datetime import timedelta | ||
79 | # environments locked for more than 30 seconds - they should be unlocked | ||
80 | BuildEnvironment.objects.filter(lock=BuildEnvironment.LOCK_LOCK).filter(updated__lt = timezone.now() - timedelta(seconds = 30)).update(lock = BuildEnvironment.LOCK_FREE) | ||
81 | |||
82 | |||
83 | def handle_noargs(self, **options): | ||
84 | self.cleanup() | ||
85 | self.schedule() | ||