From 489cc76b40e4d60c5b3c9d70c02a32dfdc6929e4 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Fri, 2 Aug 2013 14:44:16 +0100 Subject: [PATCH] Port to oslo.messaging The oslo.messaging library takes the existing RPC code from oslo and wraps it in a sane API with well defined semantics around which we can make a commitment to retain compatibility in future. The patch is large, but the changes can be summarized as: * oslo.messaging>=1.3.0a4 is required; a proper 1.3.0 release will be pushed before the icehouse release candidates. * The new rpc module has init() and cleanup() methods which manage the global oslo.messaging transport state. The TRANSPORT and NOTIFIER globals are conceptually similar to the current RPCIMPL global, except we're free to create and use alternate Transport objects in e.g. the cells code. * The rpc.get_{client,server,notifier}() methods are just helpers which wrap the global messaging state, specifiy serializers and specify the use of the eventlet executor. * In oslo.messaging, a request context is expected to be a dict so we add a RequestContextSerializer which can serialize to and from dicts using RequestContext.{to,from}_dict() * The allowed_rpc_exception_modules configuration option is replaced by an allowed_remote_exmods get_transport() parameter. This is not something that users ever need to configure, but it is something each project using oslo.messaging needs to be able to customize. * The nova.rpcclient module is removed; it was only a helper class to allow us split a lot of the more tedious changes out of this patch. * Finalizing the port from RpcProxy to RPCClient is straightforward. We put the default topic, version and namespace into a Target and contstruct the client using that. * Porting endpoint classes (like ComputeManager) just involves setting a target attribute on the class. * The @client_exceptions() decorator has been renamed to @expected_exceptions since it's used on the server side to designate exceptions we expect the decorated method to raise. * We maintain a global NOTIFIER object and create specializations of it with specific publisher IDs in order to avoid notification driver loading overhead. * rpc.py contains transport aliases for backwards compatibility purposes. setup.cfg also contains notification driver aliases for backwards compat. * The messaging options are moved about in nova.conf.sample because the options are advertised via a oslo.config.opts entry point and picked up by the generator. * We use messaging.ConfFixture in tests to override oslo.messaging config options, rather than making assumptions about the options registered by the library. The porting of cells code is particularly tricky: * messaging.TransportURL parse() and str() replaces the [un]parse_transport_url() methods. Note the complication that an oslo.messaging transport URL can actually have multiple hosts in order to support message broker clustering. Also the complication of transport aliases in rpc.get_transport_url(). * proxy_rpc_to_manager() is fairly nasty. Right now, we're proxying the on-the-wire message format over this call, but you can't supply such messages to oslo.messaging's cast()/call() methods. Rather than change the inter-cell RPC API to suit oslo.messaging, we instead just unpack the topic, server, method and args from the message on the remote side. cells_api.RPCClientCellsProxy is a mock RPCClient implementation which allows us to wrap up a RPC in the message format currently used for inter-cell RPCs. * Similarly, proxy_rpc_to_manager uses the on-the-wire format for exception serialization, but this format is an implementation detail of oslo.messaging's transport drivers. So, we need to duplicate the exception serialization code in cells.messaging. We may find a way to reconcile this in future - for example a ExceptionSerializer class might work, but with the current format it might be difficult for the deserializer to generically detect a serialized exception. * CellsRPCDriver.start_servers() and InterCellRPCAPI._get_client() need close review, but they're pretty straightforward ports of code to listen on some specialized topics and connect to a remote cell using its transport URL. blueprint: oslo-messaging Change-Id: Ib613e6300f2c215be90f924afbd223a3da053a69 --- nova/test.py | 13 +++++++++++++ nova/utils.py | 6 +++--- requirements.txt | 1 + setup.cfg | 8 ++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nova/test.py b/nova/test.py index a613ee914..eaf01f742 100644 --- a/nova/test.py +++ b/nova/test.py @@ -35,6 +35,7 @@ import uuid import fixtures from oslo.config import cfg +from oslo.messaging import conffixture as messaging_conffixture import testtools from nova import context @@ -47,6 +48,7 @@ from nova.openstack.common.fixture import moxstubout from nova.openstack.common import log as logging from nova.openstack.common import timeutils from nova import paths +from nova import rpc from nova import service from nova.tests import conf_fixture from nova.tests import policy_fixture @@ -232,10 +234,21 @@ class TestCase(testtools.TestCase): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) + rpc.add_extra_exmods('nova.test') + self.addCleanup(rpc.clear_extra_exmods) + self.addCleanup(rpc.cleanup) + fs = '%(levelname)s [%(name)s] %(message)s' self.log_fixture = self.useFixture(fixtures.FakeLogger(format=fs)) self.useFixture(conf_fixture.ConfFixture(CONF)) + self.messaging_conf = messaging_conffixture.ConfFixture(CONF) + self.messaging_conf.transport_driver = 'fake' + self.messaging_conf.response_timeout = 15 + self.useFixture(self.messaging_conf) + + rpc.init(CONF) + if self.USES_DB: global _DB_CACHE if not _DB_CACHE: diff --git a/nova/utils.py b/nova/utils.py index 40f6d9b0f..b8cf911f6 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -39,6 +39,7 @@ from xml.sax import saxutils import eventlet import netaddr from oslo.config import cfg +from oslo import messaging import six from nova import exception @@ -49,7 +50,6 @@ from nova.openstack.common import importutils from nova.openstack.common import lockutils from nova.openstack.common import log as logging from nova.openstack.common import processutils -from nova.openstack.common.rpc import common as rpc_common from nova.openstack.common import timeutils notify_decorator = 'nova.notifications.notify_decorator' @@ -929,8 +929,8 @@ class ExceptionHelper(object): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except rpc_common.ClientException as e: - raise (e._exc_info[1], None, e._exc_info[2]) + except messaging.ExpectedException as e: + raise (e.exc_info[1], None, e.exc_info[2]) return wrapper diff --git a/requirements.txt b/requirements.txt index c360250e4..16e41feb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,3 +32,4 @@ wsgiref>=0.1.2 oslo.config>=1.2.0 oslo.rootwrap pycadf>=0.1.9 +oslo.messaging>=1.3.0a4 diff --git a/setup.cfg b/setup.cfg index 729158a24..6bb33ebc1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -127,6 +127,14 @@ nova.api.v3.extensions.server.rebuild = nova.api.v3.extensions.server.update = access_ips = nova.api.openstack.compute.plugins.v3.access_ips:AccessIPs +# These are for backwards compat with Havana notification_driver configuration values +oslo.messaging.notify.drivers = + nova.openstack.common.notififier.log_notifier = oslo.messaging.notify._impl_log:LogDriver + nova.openstack.common.notififier.no_op_notifier = oslo.messaging.notify._impl_noop:NoOpDriver + nova.openstack.common.notififier.rpc_notifier2 = oslo.messaging.notify._impl_messaging:MessagingV2Driver + nova.openstack.common.notififier.rpc_notifier = oslo.messaging.notify._impl_messaging:MessagingDriver + nova.openstack.common.notififier.test_notifier = oslo.messaging.notify._impl_test:TestDriver + [build_sphinx] all_files = 1 build-dir = doc/build