From 0b2e6442a6da8d05649530365601f49d37cb6ab5 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Tue, 2 Jun 2015 12:57:03 +0100 Subject: bitbake: toaster: improve the buildenvironment API We improve the buildenvironment API by reducing it to a single command: triggerBuild. This command is specifically implemented in each BE controller type, so the runbuilds management command is only concerned with scheduling the next build, and not with the details of how a build is actually started. (Bitbake rev: 7ee0f1da0a8fcac37419ffdddbe35a9268a1ded4) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/lib/toaster/bldcontrol/bbcontroller.py | 3 +++ .../toaster/bldcontrol/localhostbecontroller.py | 22 ++++++++++++++++ .../bldcontrol/management/commands/runbuilds.py | 30 +++++----------------- bitbake/lib/toaster/bldcontrol/sshbecontroller.py | 21 +++++++++++++++ 4 files changed, 53 insertions(+), 23 deletions(-) (limited to 'bitbake') diff --git a/bitbake/lib/toaster/bldcontrol/bbcontroller.py b/bitbake/lib/toaster/bldcontrol/bbcontroller.py index 42675d3fc6..9dd01e0deb 100644 --- a/bitbake/lib/toaster/bldcontrol/bbcontroller.py +++ b/bitbake/lib/toaster/bldcontrol/bbcontroller.py @@ -190,6 +190,9 @@ class BuildEnvironmentController(object): """ raise Exception("Must override BE release") + def triggerBuild(self, bitbake, layers, variables, targets): + raise Exception("Must override BE release") + class ShellCmdException(Exception): pass diff --git a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py index bc3566acee..d0f86325e9 100644 --- a/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py +++ b/bitbake/lib/toaster/bldcontrol/localhostbecontroller.py @@ -317,3 +317,25 @@ class LocalhostBEController(BuildEnvironmentController): import shutil shutil.rmtree(os.path.join(self.be.sourcedir, "build")) assert not os.path.exists(self.be.builddir) + + + def triggerBuild(self, bitbake, layers, variables, targets): + # set up the buid environment with the needed layers + self.setLayers(bitbake, layers) + self.writeConfFile("conf/toaster-pre.conf", ) + self.writeConfFile("conf/toaster.conf", raw = "INHERIT+=\"toaster buildhistory\"") + + # get the bb server running with the build req id and build env id + bbctrl = self.getBBController() + + # trigger the build command + task = reduce(lambda x, y: x if len(y)== 0 else y, map(lambda y: y.task, targets)) + if len(task) == 0: + task = None + + bbctrl.build(list(map(lambda x:x.target, targets)), task) + + logger.debug("localhostbecontroller: Build launched, exiting. Follow build logs at %s/toaster_ui.log" % self.be.builddir) + + # disconnect from the server + bbctrl.disconnect() diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py b/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py index 808318f14f..920d9efcd0 100644 --- a/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py +++ b/bitbake/lib/toaster/bldcontrol/management/commands/runbuilds.py @@ -50,33 +50,16 @@ class Command(NoArgsCommand): # write the build identification variable BRVariable.objects.create(req = br, name="TOASTER_BRBE", value="%d:%d" % (br.pk, bec.be.pk)) + # let the build request know where it is being executed br.environment = bec.be br.save() - # set up the buid environment with the needed layers - bec.setLayers(br.brbitbake_set.all(), br.brlayer_set.all()) - bec.writeConfFile("conf/toaster-pre.conf", br.brvariable_set.all()) - bec.writeConfFile("conf/toaster.conf", raw = "INHERIT+=\"toaster buildhistory\"") - - # get the bb server running with the build req id and build env id - bbctrl = bec.getBBController() - - # trigger the build command - task = reduce(lambda x, y: x if len(y)== 0 else y, map(lambda y: y.task, br.brtarget_set.all())) - if len(task) == 0: - task = None - bbctrl.build(list(map(lambda x:x.target, br.brtarget_set.all())), task) - - logger.debug("runbuilds: Build launched, exiting. Follow build logs at %s/toaster_ui.log" % bec.be.builddir) - # disconnect from the server - bbctrl.disconnect() - - # cleanup to be performed by toaster when the deed is done - + # this triggers an async build + bec.triggerBuild(br.brbitbake_set.all(), br.brlayer_set.all(), br.brvariable_set.all(), br.brtarget_set.all()) except Exception as e: - logger.error("runbuilds: Error executing shell command %s" % e) + logger.error("runbuilds: Error launching build %s" % e) traceback.print_exc(e) if "[Errno 111] Connection refused" in str(e): # Connection refused, read toaster_server.out @@ -124,8 +107,9 @@ class Command(NoArgsCommand): def cleanup(self): from django.utils import timezone from datetime import timedelta - # environments locked for more than 30 seconds - they should be unlocked - BuildEnvironment.objects.filter(lock=BuildEnvironment.LOCK_LOCK).filter(updated__lt = timezone.now() - timedelta(seconds = 30)).update(lock = BuildEnvironment.LOCK_FREE) + # DISABLED environments locked for more than 30 seconds - they should be unlocked + #BuildEnvironment.objects.filter(lock=BuildEnvironment.LOCK_LOCK).filter(updated__lt = timezone.now() - timedelta(seconds = 30)).update(lock = BuildEnvironment.LOCK_FREE) + pass def handle_noargs(self, **options): diff --git a/bitbake/lib/toaster/bldcontrol/sshbecontroller.py b/bitbake/lib/toaster/bldcontrol/sshbecontroller.py index 29ed0a770f..8ef434baf5 100644 --- a/bitbake/lib/toaster/bldcontrol/sshbecontroller.py +++ b/bitbake/lib/toaster/bldcontrol/sshbecontroller.py @@ -156,3 +156,24 @@ class SSHBEController(BuildEnvironmentController): import shutil shutil.rmtree(os.path.join(self.be.sourcedir, "build")) assert not self._pathexists(self.be.builddir) + + def triggerBuild(self, bitbake, layers, variables, targets): + # set up the buid environment with the needed layers + self.setLayers(bitbake, layers) + self.writeConfFile("conf/toaster-pre.conf", ) + self.writeConfFile("conf/toaster.conf", raw = "INHERIT+=\"toaster buildhistory\"") + + # get the bb server running with the build req id and build env id + bbctrl = self.getBBController() + + # trigger the build command + task = reduce(lambda x, y: x if len(y)== 0 else y, map(lambda y: y.task, targets)) + if len(task) == 0: + task = None + + bbctrl.build(list(map(lambda x:x.target, targets)), task) + + logger.debug("localhostbecontroller: Build launched, exiting. Follow build logs at %s/toaster_ui.log" % self.be.builddir) + + # disconnect from the server + bbctrl.disconnect() -- cgit v1.2.3-54-g00ecf