Skip to contentSkip to conversation

Cancel toaster builds when cli is interrupted

PATCH New Michael Wood 1 participant 4 messages May 12, 2016

lore
Share & tools
lore
#0 lore raw

cover Cancel toaster builds when cli is interrupted

If a bitbake build is running on the command line and is interrupted (e.g. by Ctrl-c), capture the interrupt and shut down the bitbake server. Also set the outcome to CANCELLED so the build displays correctly in the Toaster UI.

Elliot Smith (3):
buildinfohelper: add method to set current build as CANCELLED
toasterui: capture keyboard interrupts the same way as knotty
toaster: don't show "Rebuild" button for cancelled cli builds

 lib/bb/ui/buildinfohelper.py                      | 10 +++++++++
 lib/bb/ui/toasterui.py                            | 17 ++++++++++++++-
 lib/toaster/toastergui/templates/mrb_section.html | 25 +++++++++++++----------
 3 files changed, 40 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 buildinfohelper: add method to set current build as CANCELLED

From: Elliot Smith <[email protected]>

This will be used from toasterui to cancel the current command-line build when a keyboard interrupt is captured.

[YOCTO #8515]

---
 lib/bb/ui/buildinfohelper.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/bb/ui/buildinfohelper.py +10 -0
index ff4da78..c5368f6 100644
@@ -1251,6 +1251,16 @@ class BuildInfoHelper(object):
 
 
 
+    def cancel_cli_build(self):
+        """
+        If a build is currently underway, set its state to CANCELLED;
+        note that this only gets called for command line builds which are
+        interrupted, so it doesn't touch any BuildRequest objects
+        """
+        build = self.internal_state['build']
+        if build:
+            build.outcome = Build.CANCELLED
+            build.save()
 
     def store_dependency_information(self, event):
         assert '_depgraph' in vars(event)
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 toasterui: capture keyboard interrupts the same way as knotty

In reply to Michael Wood

From: Elliot Smith <[email protected]>

knotty captures two levels of keyboard interrupt: a single interrupt or two interrupts in a row. These then trigger stateShutdown and stateForceShutdown respectively.

toasterui doesn't have an equivalent way of capturing interrupts and using them to shut down bitbake. Now that we are no longer using knotty + XMLRPCServer for our command line builds (since switching to per-project build directories), we see some odd side effects of this, such as builds continuing after they have been interrupted on the command line.

Bring toasterui in line with knotty (copy-paste most of the code in knotty.py which deals with interrupts) so that a keyboard interrupt actually shuts down the bitbake server (if not in observe only mode).

Additionally use the cancel_cli_build() method to set the Build status to CANCELLED in Toaster's db when we get keyboard interrupts. This means that builds interrupted on the command line show as cancelled (same as if they'd been cancelled from the Toaster UI), as specified in the UI designs.

[YOCTO #8515]

---
 lib/bb/ui/toasterui.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
lib/bb/ui/toasterui.py +16 -1
index addd5cc..8e5af65 100644
@@ -441,7 +441,22 @@ def main(server, eventHandler, params):
             if ioerror.args[0] == 4:
                 pass
         except KeyboardInterrupt:
-            main.shutdown = 1
+            if params.observe_only:
+                print("\nKeyboard Interrupt, exiting observer...")
+                main.shutdown = 2
+            if not params.observe_only and main.shutdown == 1:
+                print("\nSecond Keyboard Interrupt, stopping...\n")
+                _, error = server.runCommand(["stateForceShutdown"])
+                if error:
+                    logger.error("Unable to cleanly stop: %s" % error)
+            if not params.observe_only and main.shutdown == 0:
+                print("\nKeyboard Interrupt, closing down...\n")
+                interrupted = True
+                _, error = server.runCommand(["stateShutdown"])
+                if error:
+                    logger.error("Unable to cleanly shutdown: %s" % error)
+            buildinfohelper.cancel_cli_build()
+            main.shutdown = main.shutdown + 1
         except Exception as e:
             # print errors to log
             import traceback
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/3 toaster: don't show "Rebuild" button for cancelled cli builds

In reply to Michael Wood

From: Elliot Smith <[email protected]>

[YOCTO #8515]

---
 lib/toaster/toastergui/templates/mrb_section.html | 25 +++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)
lib/toaster/toastergui/templates/mrb_section.html +14 -11
index b5e798d..212998a 100644
@@ -125,8 +125,6 @@
                       pull-right"
                       data-request-url="{% url 'xhr_buildrequest' build.project.pk %}"
                       data-target='{{build.target_set.all|get_tasks|json}}'>
-
-
                         Rebuild
                   </button>
               {% endif %}
@@ -144,7 +142,7 @@
     <div class="lead span3 progress-info"><span id="build-pc-done-{{build.pk}}">{{build.completeper}}</span>% of tasks complete</div>
     {# No build cancel for command line builds project #}
     {% if build.project.is_default %}
-    <i class="icon-question-sign get-help get-help-blue pull-right" title="" data-original-title="Builds in this project cannot be cancelled from Toaster: they can only be cancalled from the command line"></i>
+    <i class="icon-question-sign get-help get-help-blue pull-right" title="" data-original-title="Builds in this project cannot be cancelled from Toaster: they can only be cancelled from the command line"></i>
     {% else %}
     <div class="lead pull-right progress-info">
       <button class="cancel-build-btn btn btn-info pull-right"
@@ -158,15 +156,20 @@
     {%endif%} {# end if in progress #}
 
     {% if build.outcome == build.CANCELLED %}
-    <div class="span4">
-      <p class="lead">Build cancelled</p>
-    </div>
-    <button class="btn btn-info pull-right run-again-btn"
-        data-request-url="{% url 'xhr_buildrequest' build.project.pk %}"
-        data-target='{{build.target_set.all|get_tasks|json}}'>
-      Rebuild
+      <div class="span4">
+        <p class="lead">Build cancelled</p>
+      </div>
 
-    </button>
+      {% if build.project.is_default %}
+        <i class="icon-question-sign get-help get-help-blue pull-right" title=""
+          data-original-title="Builds in this project cannot be rebuilt from Toaster: they can only be rebuilt from the command line"></i>
+      {% else %}
+        <button class="btn btn-info pull-right run-again-btn"
+                data-request-url="{% url 'xhr_buildrequest' build.project.pk %}"
+                data-target='{{build.target_set.all|get_tasks|json}}'>
+          Rebuild
+        </button>
+      {% endif %}
     {% endif %}
   </div>
 </div>
Signature · 1 line
2.7.4