summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-18 15:33:49 +0000
committerGerrit Code Review <review@openstack.org>2012-06-18 15:33:49 +0000
commitf5ca941543847e62426cf1166a68053d711d4e32 (patch)
tree88f4e95725d1e79d12efc48ec7f94938f5d214ba
parent9f938720f158889252fa1db44be96745fa48e1ff (diff)
parent91fc479399ab12d8ba670c3627582ebfc3950af8 (diff)
Merge "rpc: Update rpc_backend handling."
-rw-r--r--openstack/common/rpc/__init__.py10
-rw-r--r--tests/unit/rpc/test_common.py25
2 files changed, 33 insertions, 2 deletions
diff --git a/openstack/common/rpc/__init__.py b/openstack/common/rpc/__init__.py
index dc4b185..95b4dce 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')