]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orchestrator: use deepcopy for copying exceptions
authorKefu Chai <kchai@redhat.com>
Wed, 29 Jan 2020 15:27:47 +0000 (23:27 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 6 Feb 2020 01:53:17 +0000 (09:53 +0800)
since rexec module has been removed in python3, we cannot use it
anymore.

Fixes: https://tracker.ceph.com/issues/43657
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/orchestrator.py

index 410d5946a585f4b035c5d17459f28d0321435af4..09fed945d5555f002191264817deda752e972a54 100644 (file)
@@ -4,6 +4,7 @@ ceph-mgr orchestrator interface
 
 Please see the ceph-mgr module developer's guide for more information.
 """
+import copy
 import functools
 import logging
 import sys
@@ -629,27 +630,9 @@ def raise_if_exception(c):
     :raises OrchestratorError: Some user error or a config error.
     :raises Exception: Some internal error
     """
-    def copy_to_this_subinterpreter(r_obj):
-        # This is something like `return pickle.loads(pickle.dumps(r_obj))`
-        # Without importing anything.
-        r_cls = r_obj.__class__
-        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))
-        return my_obj
-
     if c.exception is not None:
         try:
-            e = copy_to_this_subinterpreter(c.exception)
+            e = copy.deepcopy(c.exception)
         except (KeyError, AttributeError):
             raise Exception('{}: {}'.format(type(c.exception), c.exception))
         raise e