From aec7e491dd60cf6c2472be9b0ba09f95149038fc Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 14 Feb 2020 15:32:55 +0100 Subject: [PATCH] mgr/cephadm: Fix logging of exceptions `multiprocessing.pool.Pool#map_async` no longer has the exception context, therefore calling `logging.exception` did not print the exception anymore. Now, let's call `fail` while we have the exception context. Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/module.py | 16 +++++++++------- src/pybind/mgr/orchestrator/_interface.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index a64d046315e4d..ca00adbeeb8d1 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -140,10 +140,15 @@ class AsyncCompletion(orchestrator.Completion): self._on_complete_ = None self._finalize(result) except Exception as e: - self.fail(e) + try: + self.fail(e) + except Exception: + logger.exception(f'failed to fail AsyncCompletion: >{repr(self)}<') + if 'UNITTEST' in os.environ: + assert False def error_callback(e): - self.fail(e) + pass def run(value): def do_work(*args, **kwargs): @@ -155,11 +160,8 @@ class AsyncCompletion(orchestrator.Completion): self.progress_reference.progress += 1.0 / len(value) return res except Exception as e: - if six.PY3: - raise - else: - # Py2 only: _worker_pool doesn't call error_callback - self.fail(e) + self.fail(e) + raise assert CephadmOrchestrator.instance if self.many: diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 8901c4a9c1fb3..ba5284b034b9b 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -385,7 +385,7 @@ class _Promise(object): assert self._state in (self.INITIALIZED, self.RUNNING) logger.exception('_Promise failed') self._exception = e - self._value = 'exception' + self._value = f'_exception: {e}' if self._next_promise: self._next_promise.fail(e) self._state = self.FINISHED -- 2.39.5