From a854fcfab8bfeecbfb77497430dcfad36bbcb712 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 2 Jun 2021 06:53:11 -0700 Subject: [PATCH] Make taskflow_executor log get_flow() exceptions Currently an exception raised in a get_flow() task builder will be silently swallowed with no logging. This patch makes us log it and then re-raise it so that it will be visible. Change-Id: I4315bfd68e5a184305f384705e35c4049f75b906 --- glance/async_/taskflow_executor.py | 3 +++ glance/tests/unit/async_/test_taskflow_executor.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/glance/async_/taskflow_executor.py b/glance/async_/taskflow_executor.py index 867986a358..e8adbcc305 100644 --- a/glance/async_/taskflow_executor.py +++ b/glance/async_/taskflow_executor.py @@ -139,6 +139,9 @@ class TaskExecutor(glance.async_.TaskExecutor): raise exception.ImportTaskError(message=exc.msg) except RuntimeError: raise NotImplementedError() + except Exception as e: + LOG.exception(_LE('Task initialization failed: %s'), str(e)) + raise def begin_processing(self, task_id): try: diff --git a/glance/tests/unit/async_/test_taskflow_executor.py b/glance/tests/unit/async_/test_taskflow_executor.py index eb337e7d6f..ef01e8d63d 100644 --- a/glance/tests/unit/async_/test_taskflow_executor.py +++ b/glance/tests/unit/async_/test_taskflow_executor.py @@ -143,3 +143,15 @@ class TestTaskExecutor(test_utils.BaseTestCase): 'backend': None, 'admin_repo': admin_repo, 'uri': 'http://cloud.foo/image.qcow2'}) + + @mock.patch('stevedore.driver.DriverManager') + @mock.patch.object(taskflow_executor, 'LOG') + def test_get_flow_fails(self, mock_log, mock_driver): + mock_driver.side_effect = IndexError('fail') + executor = taskflow_executor.TaskExecutor(self.context, + self.task_repo, + self.image_repo, + self.image_factory) + self.assertRaises(IndexError, executor._get_flow, self.task) + mock_log.exception.assert_called_once_with( + 'Task initialization failed: %s', 'fail')