diff options
author | Russell Bryant <rbryant@redhat.com> | 2013-03-30 01:05:12 -0400 |
---|---|---|
committer | Russell Bryant <rbryant@redhat.com> | 2013-04-12 10:42:50 -0400 |
commit | 6901a3ba3e09ae091480b650ec23c2f2d9543152 (patch) | |
tree | 34062944991e1611b1f66965da7f1870fc1589fd /tests/unit/rpc | |
parent | 9dcf688ea80f52cdb5413514198b2aa81d5a4e09 (diff) | |
download | oslo-6901a3ba3e09ae091480b650ec23c2f2d9543152.tar.gz oslo-6901a3ba3e09ae091480b650ec23c2f2d9543152.tar.xz oslo-6901a3ba3e09ae091480b650ec23c2f2d9543152.zip |
Add rpc method namespace support.
RPC endpoints already had the ability to expose multiple APIs ... sort
of. You could pass multiple callback objects to the dispatcher and it
would check all of them for a method call.
This patch adds the ability to set a namespace on a callback object.
This makes exposing multiple APIs a bit more like you would expect it to
work. You can invoke a method on a specific callback object, as opposed
to having it check all of them for the method.
This will allow you to create, manage, and version APIs without any
potential conflicts with other APIs being exposed by the same endpoint.
An example of where I would like to use this is in Nova, where we have
some methods that we would like to expose on *all* rpc endpoints.
This includes no public API changes and is fully backwards compatible.
Implement blueprint rpc-multi-api.
Change-Id: Ief4433e2e1c32cfb05b4cd27b87fe32b40f4341d
Diffstat (limited to 'tests/unit/rpc')
-rw-r--r-- | tests/unit/rpc/test_dispatcher.py | 44 | ||||
-rw-r--r-- | tests/unit/rpc/test_proxy.py | 12 |
2 files changed, 50 insertions, 6 deletions
diff --git a/tests/unit/rpc/test_dispatcher.py b/tests/unit/rpc/test_dispatcher.py index fe49776..8998a90 100644 --- a/tests/unit/rpc/test_dispatcher.py +++ b/tests/unit/rpc/test_dispatcher.py @@ -58,6 +58,18 @@ class RpcDispatcherTestCase(utils.BaseTestCase): self.test_method_ctxt = ctxt self.test_method_arg1 = arg1 + class API4(object): + RPC_API_VERSION = '1.0' + RPC_API_NAMESPACE = 'testapi' + + def __init__(self): + self.test_method_ctxt = None + self.test_method_arg1 = None + + def test_method(self, ctxt, arg1): + self.test_method_ctxt = ctxt + self.test_method_arg1 = arg1 + def setUp(self): super(RpcDispatcherTestCase, self).setUp() self.ctxt = context.RequestContext('fake_user', 'fake_project') @@ -67,7 +79,7 @@ class RpcDispatcherTestCase(utils.BaseTestCase): v3 = self.API3() disp = dispatcher.RpcDispatcher([v2, v3]) - disp.dispatch(self.ctxt, version, 'test_method', arg1=1) + disp.dispatch(self.ctxt, version, 'test_method', None, arg1=1) self.assertEqual(v2.test_method_ctxt, expectations[0]) self.assertEqual(v2.test_method_arg1, expectations[1]) @@ -104,7 +116,7 @@ class RpcDispatcherTestCase(utils.BaseTestCase): v1 = self.API1() disp = dispatcher.RpcDispatcher([v1]) - disp.dispatch(self.ctxt, None, 'test_method', arg1=1) + disp.dispatch(self.ctxt, None, 'test_method', None, arg1=1) self.assertEqual(v1.test_method_ctxt, self.ctxt) self.assertEqual(v1.test_method_arg1, 1) @@ -114,11 +126,35 @@ class RpcDispatcherTestCase(utils.BaseTestCase): disp = dispatcher.RpcDispatcher([v1]) self.assertRaises(AttributeError, disp.dispatch, - self.ctxt, "1.0", "does_not_exist") + self.ctxt, "1.0", "does_not_exist", None) def test_missing_method_version_no_match(self): v1 = self.API1() disp = dispatcher.RpcDispatcher([v1]) self.assertRaises(rpc_common.UnsupportedRpcVersion, disp.dispatch, - self.ctxt, "2.0", "does_not_exist") + self.ctxt, "2.0", "does_not_exist", None) + + def test_method_without_namespace(self): + v1 = self.API1() + v4 = self.API4() + disp = dispatcher.RpcDispatcher([v1, v4]) + + disp.dispatch(self.ctxt, '1.0', 'test_method', None, arg1=1) + + self.assertEqual(v1.test_method_ctxt, self.ctxt) + self.assertEqual(v1.test_method_arg1, 1) + self.assertEqual(v4.test_method_ctxt, None) + self.assertEqual(v4.test_method_arg1, None) + + def test_method_with_namespace(self): + v1 = self.API1() + v4 = self.API4() + disp = dispatcher.RpcDispatcher([v1, v4]) + + disp.dispatch(self.ctxt, '1.0', 'test_method', 'testapi', arg1=1) + + self.assertEqual(v1.test_method_ctxt, None) + self.assertEqual(v1.test_method_arg1, None) + self.assertEqual(v4.test_method_ctxt, self.ctxt) + self.assertEqual(v4.test_method_arg1, 1) diff --git a/tests/unit/rpc/test_proxy.py b/tests/unit/rpc/test_proxy.py index 97bb9d5..fe4bffb 100644 --- a/tests/unit/rpc/test_proxy.py +++ b/tests/unit/rpc/test_proxy.py @@ -144,6 +144,14 @@ class RpcProxyTestCase(utils.BaseTestCase): 'fanout_cast_to_server', server_params={'blah': 1}, supports_topic_override=False) + def test_make_namespaced_msg(self): + msg = proxy.RpcProxy.make_namespaced_msg('test_method', 'x', a=1, b=2) + expected = {'method': 'test_method', 'namespace': 'x', + 'args': {'a': 1, 'b': 2}} + self.assertEqual(msg, expected) + def test_make_msg(self): - self.assertEqual(proxy.RpcProxy.make_msg('test_method', a=1, b=2), - {'method': 'test_method', 'args': {'a': 1, 'b': 2}}) + msg = proxy.RpcProxy.make_msg('test_method', a=1, b=2) + expected = {'method': 'test_method', 'namespace': None, + 'args': {'a': 1, 'b': 2}} + self.assertEqual(msg, expected) |