summaryrefslogtreecommitdiff
path: root/heat/tests/test_rpc_client.py
diff options
context:
space:
mode:
authorSteve Baker <sbaker@redhat.com>2014-11-19 16:41:13 +1300
committerSteve Baker <sbaker@redhat.com>2014-11-20 16:27:46 +1300
commit9822e483ca98623d65a6b0614852444bd76c2294 (patch)
tree7767033af9a9b6e4ef9ff15ab4efaae6f3976feb /heat/tests/test_rpc_client.py
parent3bc511f35445e0fbe1b83dce69c2181ca4089b01 (diff)
downloadheat-9822e483ca98623d65a6b0614852444bd76c2294.tar.gz
Handle remote thrown NotFound RPC exceptions
This is a short-term fix for a regression caused by If81b68717bd2f9d9be1291c07b18626493c9b5cc which results in undeletable config and deployment resource if the underlying config or deployment no longer exists. Longer term there will be a ClientPlugin for making heat RPC calls which wraps the remote exceptions and raises the original type. The EngineClient methods local_error_name and ignore_error_named will still be useful when this ClientPlugin exists, they just won't be called directly from resources. Change-Id: I8407e04c0404dd6560273d7d74744b5bb7774520
Diffstat (limited to 'heat/tests/test_rpc_client.py')
-rw-r--r--heat/tests/test_rpc_client.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py
index a904c77e1..9f24c05e0 100644
--- a/heat/tests/test_rpc_client.py
+++ b/heat/tests/test_rpc_client.py
@@ -20,9 +20,11 @@ Unit Tests for heat.rpc.client
import copy
import mock
+from oslo.messaging._drivers import common as rpc_common
import stubout
import testtools
+from heat.common import exception
from heat.common import identifier
from heat.common import messaging
from heat.rpc import client as rpc_client
@@ -43,6 +45,40 @@ class EngineRpcAPITestCase(testtools.TestCase):
self.rpcapi = rpc_client.EngineClient()
super(EngineRpcAPITestCase, self).setUp()
+ def _to_remote_error(self, error):
+ """Converts the given exception to the one with the _Remote suffix.
+ """
+ exc_info = (type(error), error, None)
+ serialized = rpc_common.serialize_remote_exception(exc_info)
+ remote_error = rpc_common.deserialize_remote_exception(
+ serialized, ["heat.common.exception"])
+ return remote_error
+
+ def test_local_error_name(self):
+ ex = exception.NotFound()
+ self.assertEqual('NotFound', self.rpcapi.local_error_name(ex))
+
+ exr = self._to_remote_error(ex)
+ self.assertEqual('NotFound_Remote', exr.__class__.__name__)
+ self.assertEqual('NotFound', self.rpcapi.local_error_name(exr))
+
+ def test_ignore_error_named(self):
+ ex = exception.NotFound()
+ exr = self._to_remote_error(ex)
+
+ self.rpcapi.ignore_error_named(ex, 'NotFound')
+ self.rpcapi.ignore_error_named(exr, 'NotFound')
+ self.assertRaises(
+ exception.NotFound,
+ self.rpcapi.ignore_error_named,
+ ex,
+ 'NotSupported')
+ self.assertRaises(
+ exception.NotFound,
+ self.rpcapi.ignore_error_named,
+ exr,
+ 'NotSupported')
+
def _test_engine_api(self, method, rpc_method, **kwargs):
ctxt = utils.dummy_context()
expected_retval = 'foo' if method == 'call' else None