Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id B9FFDE0044F; Mon, 3 Oct 2016 10:49:38 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no * trust * [74.125.82.42 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 24D2BE0043B for ; Mon, 3 Oct 2016 10:49:34 -0700 (PDT) Received: by mail-wm0-f42.google.com with SMTP id f193so18040243wmg.0 for ; Mon, 03 Oct 2016 10:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=rRlgQkT1MnVrAE3zm+38avwQ1BPUn67wOyXyuUK93U0=; b=dPv4ZryMSNCxx0ZGjUz3Gyqqnz7zJMWDf2WldYaT3Cn7ksDFNSuIN8H/XPvSP0fWv5 6K8AUjb99OxGaPj7TjgRoLwxGoS/Oenc/Z9BEywigKp9zNC4/2ZBWo9LTlmKOPDUmAHM ux4NWWK/vSpSUPdu47LeSxYLEW/SPc5Y3Hd+rlGTG1xByc0ym1yzxUgBnoLIpn6jFduu 7MkDCyyOdIM8gylgBh8tBfcfoCDGWcosgrlDzh6w20AAfAQHsuCXtfFRveU70PWq4GCo Bel60Q9pt7cMyaeHXvoSbH7PhL6Tvun+hU38ykRcIFzSpyngucam4bsltBgimONfCRAP mm5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rRlgQkT1MnVrAE3zm+38avwQ1BPUn67wOyXyuUK93U0=; b=ODq8C/OBFOC/ns/rk8cFWB6wWm47GpRD5V/bxsOvZ0Eijc9wlC5Ix4WczdF3cldtrW 6f1ctUCZK7hvpCzZdxaADCSwv6mqSUc+x6QAj6eR+PannQhbJrguqb472U2ohZBrCSFc Jm5k0nospA0/B+WDj51ooIQKk0VYJ7eL9Pi16tG0A0+dgoV5IOKB3JPpB2FCsNK2mUUw YL8Qhurf28JRi76EFf5y8F5wVde8CAdK465QNhiRyT8ZHuaZEkIoqQCfwjk4gFsAVNXS sN9YK7gacANh2fCSvZe1xtvlkf2W7v5bP/ETtDX3W5cLraKDZX0OnnA6p5p9ZHpTfwns YGVA== X-Gm-Message-State: AA6/9Rk45aQbwp5Ytbquu4JITkvA584Vo0S9J38ALbH1J0RKNhzs84jK7bKyDWjEO3AbNx0J X-Received: by 10.28.38.193 with SMTP id m184mr9816547wmm.38.1475516973790; Mon, 03 Oct 2016 10:49:33 -0700 (PDT) Received: from orion.home (host31-48-249-102.range31-48.btcentralplus.com. [31.48.249.102]) by smtp.gmail.com with ESMTPSA id j198sm20064826wmg.4.2016.10.03.10.49.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Oct 2016 10:49:33 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 3 Oct 2016 18:49:31 +0100 Message-Id: <1475516971-18166-1-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] toaster: api / project Cancel any in progress builds before project delete X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Oct 2016 17:49:38 -0000 Before we finally delete any project make sure we send the cancel command to any in-progress builds. This ensures that an inaccessible build doesn't block up the system and that we don't get errors after deletion. [YOCTO #10289] Signed-off-by: Michael Wood --- bitbake/lib/toaster/toastergui/api.py | 55 +++++++++++++--------- .../lib/toaster/toastergui/templates/project.html | 12 +++-- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 3a05d66..b01d4ba 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py @@ -49,6 +49,28 @@ class XhrBuildRequest(View): def get(self, request, *args, **kwargs): return HttpResponse() + @staticmethod + def cancel_build(br): + """Cancel a build request""" + try: + bbctrl = bbcontroller.BitbakeController(br.environment) + bbctrl.forceShutDown() + except: + # We catch a bunch of exceptions here because + # this is where the server has not had time to start up + # and the build request or build is in transit between + # processes. + # We can safely just set the build as cancelled + # already as it never got started + build = br.build + build.outcome = Build.CANCELLED + build.save() + + # We now hand over to the buildinfohelper to update the + # build state once we've finished cancelling + br.state = BuildRequest.REQ_CANCELLING + br.save() + def post(self, request, *args, **kwargs): """ Build control @@ -74,26 +96,7 @@ class XhrBuildRequest(View): for i in request.POST['buildCancel'].strip().split(" "): try: br = BuildRequest.objects.get(project=project, pk=i) - - try: - bbctrl = bbcontroller.BitbakeController(br.environment) - bbctrl.forceShutDown() - except: - # We catch a bunch of exceptions here because - # this is where the server has not had time to start up - # and the build request or build is in transit between - # processes. - # We can safely just set the build as cancelled - # already as it never got started - build = br.build - build.outcome = Build.CANCELLED - build.save() - - # We now hand over to the buildinfohelper to update the - # build state once we've finished cancelling - br.state = BuildRequest.REQ_CANCELLING - br.save() - + self.cancel_build(br) except BuildRequest.DoesNotExist: return error_response('No such build request id %s' % i) @@ -823,11 +826,21 @@ class XhrProject(View): return HttpResponse() def delete(self, request, *args, **kwargs): + """Delete a project. Cancels any builds in progress""" try: - Project.objects.get(pk=kwargs['project_id']).delete() + project = Project.objects.get(pk=kwargs['project_id']) + # Cancel any builds in progress + for br in BuildRequest.objects.filter( + project=project, + state=BuildRequest.REQ_INPROGRESS): + XhrBuildRequest.cancel_build(br) + + project.delete() + except Project.DoesNotExist: return error_response("Project %s does not exist" % kwargs['project_id']) + return JsonResponse({ "error": "ok", "gotoUrl": reverse("all-projects", args=[]) diff --git a/bitbake/lib/toaster/toastergui/templates/project.html b/bitbake/lib/toaster/toastergui/templates/project.html index 7644dad..5abe241 100644 --- a/bitbake/lib/toaster/toastergui/templates/project.html +++ b/bitbake/lib/toaster/toastergui/templates/project.html @@ -31,12 +31,14 @@

Are you sure you want to delete this project?