]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Use openstack rpc functions to generate _Remote exceptions
authorJianing YANG <jianingy@unitedstack.com>
Thu, 8 Aug 2013 07:36:00 +0000 (15:36 +0800)
committerJianing YANG <jianingy@unitedstack.com>
Thu, 8 Aug 2013 09:38:31 +0000 (17:38 +0800)
use serialize_remote_exception and deserialize_remote_exception
to generate _Remote exceptions in api testing.

Change-Id: I30865306830678db493b83512bbcfac3b27ff13b

heat/tests/test_api_openstack_v1.py

index 80d37a689664566b860084613bd379f3dfb0a8ae..6975ddd93b52be7a0b9f84407d9a2d25f811204e 100644 (file)
@@ -49,21 +49,12 @@ def request_with_middleware(middleware, func, req, *args, **kwargs):
 
 def to_remote_error(error):
     """Converts the given exception to the one with the _Remote suffix.
-
-    This is how RPC exceptions are recreated on the caller's side, so
-    this helps better simulate how the exception mechanism actually works.
     """
-    ex_type = type(error)
-    kwargs = error.kwargs if hasattr(error, 'kwargs') else {}
-    message = error.message
-    module = ex_type().__class__.__module__
-    str_override = lambda self: "%s\n<Traceback>" % message
-    new_ex_type = type(ex_type.__name__ + rpc_common._REMOTE_POSTFIX,
-                       (ex_type,),
-                       {'__str__': str_override, '__unicode__': str_override})
-
-    new_ex_type.__module__ = '%s%s' % (module, rpc_common._REMOTE_POSTFIX)
-    return new_ex_type(**kwargs)
+    exc_info = (type(error), error, None)
+    serialized = rpc_common.serialize_remote_exception(exc_info)
+    remote_error = rpc_common.deserialize_remote_exception(cfg.CONF,
+                                                           serialized)
+    return remote_error
 
 
 class InstantiationDataTest(HeatTestCase):