]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: Fix raise_if_exception for Python 3 31015/head
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 21 Oct 2019 10:33:04 +0000 (12:33 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 25 Oct 2019 12:48:55 +0000 (14:48 +0200)
Also: Added a small test

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/orchestrator.py
src/pybind/mgr/orchestrator_cli/module.py
src/pybind/mgr/selftest/module.py

index 09edecbbca4b37627041f45e481ad508709071c0..ed3b2b42503e013c3027eac007c74d471ecff6e3 100644 (file)
@@ -119,11 +119,15 @@ def raise_if_exception(c):
         # This is something like `return pickle.loads(pickle.dumps(r_obj))`
         # Without importing anything.
         r_cls = r_obj.__class__
-        if r_cls.__module__ == '__builtin__':
+        if r_cls.__module__ in ('__builtin__', 'builtins'):
             return r_obj
         my_cls = getattr(sys.modules[r_cls.__module__], r_cls.__name__)
         if id(my_cls) == id(r_cls):
             return r_obj
+        if hasattr(r_obj, '__reduce__'):
+            reduce_tuple = r_obj.__reduce__()
+            if len(reduce_tuple) >= 2:
+                return my_cls(*[copy_to_this_subinterpreter(a) for a in reduce_tuple[1]])
         my_obj = my_cls.__new__(my_cls)
         for k,v in r_obj.__dict__.items():
             setattr(my_obj, k, copy_to_this_subinterpreter(v))
index a73ba2a836389deb4afac7d047198b741d08254b..e65b3c2acd8b27b52d177d05e181ed04534a57f8 100644 (file)
@@ -466,3 +466,17 @@ Usage:
         self._set_backend('')
         assert self._select_orchestrator() is None
         self._set_backend(old_orch)
+
+        e = self.remote('selftest', 'remote_from_orchestrator_cli_self_test', "ZeroDivisionError")
+        try:
+            orchestrator.raise_if_exception(e)
+            assert False
+        except ZeroDivisionError as e:
+            assert e.args == ('hello', 'world')
+
+        e = self.remote('selftest', 'remote_from_orchestrator_cli_self_test', "OrchestratorError")
+        try:
+            orchestrator.raise_if_exception(e)
+            assert False
+        except orchestrator.OrchestratorError as e:
+            assert e.args == ('hello', 'world')
index a3fb51cde13547138cc26b7802a0871df7a2449a..444a92d63aa5c864de310ea14b170952fffdb61f 100644 (file)
@@ -444,6 +444,17 @@ class Module(MgrModule):
         else:
             raise RuntimeError("KeyError not raised")
 
+    def remote_from_orchestrator_cli_self_test(self, what):
+        import orchestrator
+        if what == 'OrchestratorError':
+            c = orchestrator.TrivialReadCompletion(result=None)
+            c.exception = orchestrator.OrchestratorError('hello', 'world')
+            return c
+        elif what == "ZeroDivisionError":
+            c = orchestrator.TrivialReadCompletion(result=None)
+            c.exception = ZeroDivisionError('hello', 'world')
+            return c
+        assert False, repr(what)
 
     def shutdown(self):
         self._workload = self.SHUTDOWN