diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-06-13 09:47:21 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-06-13 10:02:41 -0400 |
| commit | 91fc479399ab12d8ba670c3627582ebfc3950af8 (patch) | |
| tree | 56a7308acbf7a7bb732ccf60af1268cbce1e9baa | |
| parent | 341ae3b475f9aab85c9202995529b1d041a71b2b (diff) | |
| download | oslo-91fc479399ab12d8ba670c3627582ebfc3950af8.tar.gz oslo-91fc479399ab12d8ba670c3627582ebfc3950af8.tar.xz oslo-91fc479399ab12d8ba670c3627582ebfc3950af8.zip | |
rpc: Update rpc_backend handling.
Part of blueprint common-rpc.
This patch updates the rpc_backend option handling in a couple of ways.
1) Set the default based on wherever this code has been copied to.
2) If we fail to import the backend, replace 'nova.rpc' with
'nova.openstack.common.rpc' just in case the value came from an older
nova configuration file. Backwards compatibility is a good thing.
Change-Id: I9ad7c084a2f0813ca1559115e7612f0a24fcce67
| -rw-r--r-- | openstack/common/rpc/__init__.py | 10 | ||||
| -rw-r--r-- | tests/unit/rpc/test_common.py | 25 |
2 files changed, 33 insertions, 2 deletions
diff --git a/openstack/common/rpc/__init__.py b/openstack/common/rpc/__init__.py index 26bd048..169aeca 100644 --- a/openstack/common/rpc/__init__.py +++ b/openstack/common/rpc/__init__.py @@ -31,7 +31,7 @@ from openstack.common import importutils rpc_opts = [ cfg.StrOpt('rpc_backend', - default='nova.rpc.impl_kombu', + default='%s.impl_kombu' % __package__, help="The messaging module to use, defaults to kombu."), cfg.IntOpt('rpc_thread_pool_size', default=64, @@ -248,5 +248,11 @@ def _get_impl(): """Delay import of rpc_backend until configuration is loaded.""" global _RPCIMPL if _RPCIMPL is None: - _RPCIMPL = importutils.import_module(cfg.CONF.rpc_backend) + try: + _RPCIMPL = importutils.import_module(cfg.CONF.rpc_backend) + except ImportError: + # For backwards compatibility with older nova config. + impl = cfg.CONF.rpc_backend.replace('nova.rpc', + 'nova.openstack.common.rpc') + _RPCIMPL = importutils.import_module(impl) return _RPCIMPL diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py index 73fb733..0b282eb 100644 --- a/tests/unit/rpc/test_common.py +++ b/tests/unit/rpc/test_common.py @@ -25,6 +25,8 @@ import unittest from openstack.common import cfg from openstack.common import context from openstack.common import exception +from openstack.common import importutils +from openstack.common import rpc from openstack.common.rpc import amqp as rpc_amqp from openstack.common.rpc import common as rpc_common from tests.unit.rpc import common @@ -148,3 +150,26 @@ class RpcCommonTestCase(unittest.TestCase): #assure the traceback was added self.assertTrue('raise FakeIDontExistException' in unicode(after_exc)) FLAGS.reset() + + def test_loading_old_nova_config(self): + FLAGS.set_override('rpc_backend', 'nova.rpc.impl_qpid') + rpc._RPCIMPL = None + + self.mod = None + + def fake_import_module(m): + if not self.mod: + # The first time import_module is called, before the replace() + self.mod = m + raise ImportError + self.mod = m + + orig_import_module = importutils.import_module + importutils.import_module = fake_import_module + + rpc._get_impl() + + importutils.import_module = orig_import_module + FLAGS.reset() + + self.assertEqual(self.mod, 'nova.openstack.common.rpc.impl_qpid') |
