From: Sebastian Wagner Date: Mon, 16 Dec 2019 10:01:42 +0000 (+0100) Subject: mgr/orchestrator: Raise more expressive Error, if completion already finished X-Git-Tag: v15.1.0~379^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4b6135449554a5408cf49d83a007b872000462ca;p=ceph.git mgr/orchestrator: Raise more expressive Error, if completion already finished Eases debugging of tracebacks. Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 27d3b8f3d35..ab61c4e297e 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -318,6 +318,9 @@ class _Promise(object): Sets the whole completion to be faild with this exception and end the evaluation. """ + if self._state == self.FINISHED: + raise ValueError( + 'Invalid State: called fail, but Completion is already finished: {}'.format(str(e))) assert self._state in (self.INITIALIZED, self.RUNNING) logger.exception('_Promise failed') self._exception = e diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py index 584c407cb4c..4dd9db76cd9 100644 --- a/src/pybind/mgr/tests/test_orchestrator.py +++ b/src/pybind/mgr/tests/test_orchestrator.py @@ -228,6 +228,11 @@ def test_fail(): c._first_promise.fail(KeyError()) assert isinstance(c.exception, KeyError) + with pytest.raises(ValueError, + match='Invalid State: called fail, but Completion is already finished: {}'.format( + str(ZeroDivisionError()))): + c._first_promise.fail(ZeroDivisionError()) + def test_pretty_print(): mgr = mock.MagicMock()