From 1c10960e05332c1f1271f6062d35226c6c8af0a9 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Jul 06 2017 08:21:18 +0000
Subject: Allow user to override build_arch_can_fail


Fixes: https://pagure.io/koji/issue/413

---

diff --git a/builder/kojid b/builder/kojid
index f34bff6..15ff6fc 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -870,7 +870,8 @@ class BuildTask(BaseTaskHandler):
         #(initBuild raises an exception if there is a conflict)
         try:
             self.extra_information = { "src": src, "data": data, "target": target }
-            srpm,rpms,brmap,logs = self.runBuilds(srpm, build_tag, archlist, repo_info['id'])
+            srpm,rpms,brmap,logs = self.runBuilds(srpm, build_tag, archlist,
+                    repo_info['id'], fail_fast=self.opts.get('fail_fast'))
 
             if opts.get('scratch'):
                 #scratch builds do not get imported
@@ -1013,7 +1014,7 @@ class BuildTask(BaseTaskHandler):
         return 'noarch'
 
 
-    def runBuilds(self, srpm, build_tag, archlist, repo_id):
+    def runBuilds(self, srpm, build_tag, archlist, repo_id, fail_fast=True):
         self.logger.debug("Spawning jobs for arches: %r" % (archlist))
         subtasks = {}
         keep_srpm = True
@@ -1030,7 +1031,7 @@ class BuildTask(BaseTaskHandler):
         self.logger.debug("Waiting on subtasks...")
 
         # wait for subtasks to finish
-        failany = not getattr(self.options, 'build_arch_can_fail', False)
+        failany = not (getattr(self.options, 'build_arch_can_fail', False) and fail_fast)
         results = self.wait(subtasks.values(), all=True, failany=failany)
 
         # finalize import
diff --git a/builder/kojid.conf b/builder/kojid.conf
index 3d2f3ce..27fd94f 100644
--- a/builder/kojid.conf
+++ b/builder/kojid.conf
@@ -88,4 +88,5 @@ from_addr=Koji Build System <buildsys@example.com>
 ;serverca = /etc/kojid/serverca.crt
 
 ;if set to True, failing subtask will not automatically cancel other siblings
+;in such case it could be overriden by user 'koji build --fail-slow' option
 ;build_arch_can_fail = False
diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py
index 02d7684..980a4ef 100644
--- a/cli/koji_cli/commands.py
+++ b/cli/koji_cli/commands.py
@@ -409,6 +409,9 @@ def handle_build(options, session, args):
     parser.add_option("--quiet", action="store_true",
                       help=_("Do not print the task information"), default=options.quiet)
     parser.add_option("--arch-override", help=_("Override build arches"))
+    parser.add_option("--fail-slow", action="store_false", dest="fail_fast", default=True,
+                      help=_("Override builder's build_arch_can_fail settings "
+                             "and doesn't cancel other subtasks if some fails"))
     parser.add_option("--repo-id", type="int", help=_("Use a specific repo"))
     parser.add_option("--noprogress", action="store_true",
                       help=_("Do not display progress of the upload"))
@@ -438,7 +441,7 @@ def handle_build(options, session, args):
     opts = {}
     if build_opts.arch_override:
         opts['arch_override'] = parse_arches(build_opts.arch_override)
-    for key in ('skip_tag', 'scratch', 'repo_id'):
+    for key in ('skip_tag', 'scratch', 'repo_id', 'fail_fast'):
         val = getattr(build_opts, key)
         if val is not None:
             opts[key] = val
diff --git a/tests/test_cli/test_build.py b/tests/test_cli/test_build.py
index 1eff2e6..2a0a756 100644
--- a/tests/test_cli/test_build.py
+++ b/tests/test_cli/test_build.py
@@ -39,7 +39,7 @@ class TestBuild(unittest.TestCase):
         source = 'srpm'
         task_id = 1
         args = [target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -91,7 +91,7 @@ Task info: weburl/taskinfo?taskID=1
         source = 'http://scm'
         task_id = 1
         args = [target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -198,6 +198,8 @@ Options:
   --quiet               Do not print the task information
   --arch-override=ARCH_OVERRIDE
                         Override build arches
+  --fail-slow           Override builder's build_arch_can_fail settings and
+                        doesn't cancel other subtasks if some fails
   --repo-id=REPO_ID     Use a specific repo
   --noprogress          Do not display progress of the upload
   --background          Run the build at a lower priority
@@ -281,7 +283,11 @@ Options:
         task_id = 1
         repo_id = 2
         args = ['--repo-id=' + str(repo_id), target, source]
-        opts = {'repo_id': repo_id, 'skip_tag': True}
+        opts = {
+            'repo_id': repo_id,
+            'skip_tag': True,
+            'fail_fast': True,
+        }
         priority = None
 
         self.session.build.return_value = task_id
@@ -475,7 +481,11 @@ Task info: weburl/taskinfo?taskID=1
             '--scratch',
             target,
             source]
-        opts = {'arch_override': arch_override, 'scratch': True}
+        opts = {
+            'arch_override': arch_override,
+            'scratch': True,
+            'fail_fast': True,
+        }
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -526,7 +536,7 @@ Task info: weburl/taskinfo?taskID=1
         task_id = 1
         args = ['--background', target, source]
         priority = 5
-        opts = {}
+        opts = {'fail_fast': True}
 
         self.session.getBuildTarget.return_value = target_info
         self.session.getTag.return_value = dest_tag_info
@@ -574,7 +584,7 @@ Task info: weburl/taskinfo?taskID=1
         source = 'srpm'
         task_id = 1
         args = [target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -625,7 +635,7 @@ Task info: weburl/taskinfo?taskID=1
         source = 'srpm'
         task_id = 1
         args = ['--noprogress', target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -679,7 +689,7 @@ Task info: weburl/taskinfo?taskID=1
         task_id = 1
         quiet = True
         args = ['--quiet', target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -729,7 +739,7 @@ Task info: weburl/taskinfo?taskID=1
         task_id = 1
         quiet = None
         args = ['--wait', target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info
@@ -782,7 +792,7 @@ Task info: weburl/taskinfo?taskID=1
         source = 'srpm'
         task_id = 1
         args = ['--nowait', target, source]
-        opts = {}
+        opts = {'fail_fast': True}
         priority = None
 
         self.session.getBuildTarget.return_value = target_info

