From 633bfe1a31c5b07618793aaec2289d11875ef5d7 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 04 2018 12:15:28 +0000 Subject: [PATCH 1/2] propagate exception correctly Fixes: https://pagure.io/koji/issue/844 --- diff --git a/koji/tasks.py b/koji/tasks.py index 9135e6f..1033d1c 100644 --- a/koji/tasks.py +++ b/koji/tasks.py @@ -366,7 +366,10 @@ class BaseTaskHandler(object): """ if canfail is None: - canfail = [] + checked = set() + else: + # canfail task are marked as checked + checked = set(canfail) if isinstance(subtasks, int): # allow single integer w/o enclosing list subtasks = [subtasks] @@ -381,23 +384,18 @@ class BaseTaskHandler(object): elif len(finished) > 0: if all: if failany: - failed = False - for task in finished: - if task in canfail: - # no point in checking - continue + # we care only about tasks which are not correctly + # finished and in same time not in canfail list + for task in set(finished) - checked: try: self.session.getTaskResult(task) - except (koji.GenericError, xmlrpclib.Fault) as task_error: - self.logger.info("task %s failed or was canceled" % task) - failed = True - break - if failed: - self.logger.info("at least one task failed or was canceled, cancelling unfinished tasks") - self.session.cancelTaskChildren(self.id) - # reraise the original error now, rather than waiting for - # an error in taskWaitResults() - raise task_error + checked.add(task) + except (koji.GenericError, xmlrpclib.Fault) as ex: + self.logger.info("task %s failed or was canceled, cancelling unfinished tasks" % task) + self.session.cancelTaskChildren(self.id) + # reraise the original error now, rather than waiting for + # an error in taskWaitResults() + raise else: # at least one done break diff --git a/tests/test_lib_py2only/test_tasks.py b/tests/test_lib_py2only/test_tasks.py index 18cf398..dc39a96 100644 --- a/tests/test_lib_py2only/test_tasks.py +++ b/tests/test_lib_py2only/test_tasks.py @@ -215,7 +215,7 @@ class TasksTestCase(TestCase): obj.session.host.taskWaitResults.return_value = taskWaitResults self.assertEquals(obj.wait([1551234, 1591234]), dict(taskWaitResults)) obj.session.host.taskSetWait.assert_called_once_with(12345678, [1551234, 1591234]) - obj.session.host.taskWaitResults.assert_called_once_with(12345678, [1551234, 1591234], canfail=[]) + obj.session.host.taskWaitResults.assert_called_once_with(12345678, [1551234, 1591234], canfail=None) def test_BaseTaskHandler_wait_some_not_done(self): """ Tests that the wait function returns the one finished subtask results of @@ -240,7 +240,7 @@ class TasksTestCase(TestCase): obj.session.host.taskWaitResults.return_value = taskWaitResults self.assertEquals(obj.wait([1551234, 1591234]), dict(taskWaitResults)) obj.session.host.taskSetWait.assert_called_once_with(12345678, [1551234, 1591234]) - obj.session.host.taskWaitResults.assert_called_once_with(12345678, [1551234], canfail=[]) + obj.session.host.taskWaitResults.assert_called_once_with(12345678, [1551234], canfail=None) @patch('signal.pause', return_value=None) def test_BaseTaskHandler_wait_some_not_done_all_set(self, mock_signal_pause): @@ -280,7 +280,7 @@ class TasksTestCase(TestCase): obj.session.host.taskSetWait.assert_called_once_with(12345678, [1551234, 1591234]) obj.session.host.taskWait.assert_has_calls([call(12345678), call(12345678)]) mock_signal_pause.assert_called_once_with() - obj.session.host.taskWaitResults.assert_called_once_with(12345678, [1551234, 1591234], canfail=[]) + obj.session.host.taskWaitResults.assert_called_once_with(12345678, [1551234, 1591234], canfail=None) def test_BaseTaskHandler_wait_some_not_done_all_set_failany_set_failed_task(self): """ Tests that the wait function raises an exception when one of the subtask fails when the failany flag is set From 3b148063a7f63963c909c5c59cbd67d56753518d Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 06 2018 06:32:48 +0000 Subject: [PATCH 2/2] remove unused variable --- diff --git a/koji/tasks.py b/koji/tasks.py index 1033d1c..4bd1f35 100644 --- a/koji/tasks.py +++ b/koji/tasks.py @@ -390,7 +390,7 @@ class BaseTaskHandler(object): try: self.session.getTaskResult(task) checked.add(task) - except (koji.GenericError, xmlrpclib.Fault) as ex: + except (koji.GenericError, xmlrpclib.Fault): self.logger.info("task %s failed or was canceled, cancelling unfinished tasks" % task) self.session.cancelTaskChildren(self.id) # reraise the original error now, rather than waiting for