Fix bug 838386.
Previously, the unit tests required kombu to be installed to run. This
patch makes it so the unit tests will still complete successfully, even
if kombu is not installed.
Change-Id: I06831a37f8c857bbfd0bce1b1c3aeda7d341a589
Reviewed-on: https://review.openstack.org/9900
Reviewed-by: Vish Ishaya <vishvananda@gmail.com>
Approved: John Griffith <john.griffith@solidfire.com>
Tested-by: Jenkins
class BaseRpcTestCase(test.TestCase):
def setUp(self, supports_timeouts=True):
super(BaseRpcTestCase, self).setUp()
- self.conn = self.rpc.create_connection(FLAGS, True)
- self.receiver = TestReceiver()
- self.conn.create_consumer('test', self.receiver, False)
- self.conn.consume_in_thread()
- self.context = context.get_admin_context()
self.supports_timeouts = supports_timeouts
+ self.context = context.get_admin_context()
+ if self.rpc:
+ self.conn = self.rpc.create_connection(FLAGS, True)
+ self.receiver = TestReceiver()
+ self.conn.create_consumer('test', self.receiver, False)
+ self.conn.consume_in_thread()
def tearDown(self):
- self.conn.close()
+ if self.rpc:
+ self.conn.close()
super(BaseRpcTestCase, self).tearDown()
def test_call_succeed(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
value = 42
result = self.rpc.call(FLAGS, self.context, 'test',
{"method": "echo", "args": {"value": value}})
self.assertEqual(value, result)
def test_call_succeed_despite_multiple_returns_yield(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
value = 42
result = self.rpc.call(FLAGS, self.context, 'test',
{"method": "echo_three_times_yield",
self.assertEqual(value + 2, result)
def test_multicall_succeed_once(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
value = 42
result = self.rpc.multicall(FLAGS, self.context,
'test',
self.assertEqual(value + i, x)
def test_multicall_three_nones(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
value = 42
result = self.rpc.multicall(FLAGS, self.context,
'test',
self.assertEqual(i, 2)
def test_multicall_succeed_three_times_yield(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
value = 42
result = self.rpc.multicall(FLAGS, self.context,
'test',
self.assertEqual(value + i, x)
def test_context_passed(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
"""Makes sure a context is passed through rpc call."""
value = 42
result = self.rpc.call(FLAGS, self.context,
self.assertEqual(self.context.to_dict(), result)
def test_nested_calls(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
"""Test that we can do an rpc.call inside another call."""
class Nested(object):
@staticmethod
self.assertEqual(value, result)
def test_call_timeout(self):
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
"""Make sure rpc.call will time out"""
if not self.supports_timeouts:
raise nose.SkipTest(_("RPC backend does not support timeouts"))
"""Base test class for all AMQP-based RPC tests"""
def test_proxycallback_handles_exceptions(self):
"""Make sure exceptions unpacking messages don't cause hangs."""
+ if not self.rpc:
+ raise nose.SkipTest('rpc driver not available.')
+
orig_unpack = rpc_amqp.unpack_context
info = {'unpacked': False}
from cinder import log as logging
from cinder import test
from cinder.rpc import amqp as rpc_amqp
-from cinder.rpc import impl_kombu
from cinder.tests.rpc import common
+try:
+ import kombu
+ from cinder.rpc import impl_kombu
+except ImportError:
+ kombu = None
+ impl_kombu = None
+
+
FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)
class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
def setUp(self):
- self.rpc = impl_kombu
- impl_kombu.register_opts(FLAGS)
+ if kombu:
+ self.rpc = impl_kombu
+ impl_kombu.register_opts(FLAGS)
+ else:
+ self.rpc = None
super(RpcKombuTestCase, self).setUp()
def tearDown(self):
- impl_kombu.cleanup()
+ if kombu:
+ impl_kombu.cleanup()
super(RpcKombuTestCase, self).tearDown()
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_reusing_connection(self):
"""Test that reusing a connection returns same one."""
conn_context = self.rpc.create_connection(FLAGS, new=False)
conn_context.close()
self.assertEqual(conn1, conn2)
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_topic_send_receive(self):
"""Test sending to a topic exchange/queue"""
self.assertEqual(self.received_message, message)
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_direct_send_receive(self):
"""Test sending to a direct exchange/queue"""
conn = self.rpc.create_connection(FLAGS)
self.assertEqual(self.received_message, message)
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_cast_interface_uses_default_options(self):
"""Test kombu rpc.cast"""
impl_kombu.cast(FLAGS, ctxt, 'fake_topic', {'msg': 'fake'})
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_cast_to_server_uses_server_params(self):
"""Test kombu rpc.cast"""
conn2.close()
self.assertEqual(self.received_message, message)
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_declare_consumer_errors_will_reconnect(self):
# Test that any exception with 'timeout' in it causes a
# reconnection
self.assertEqual(info['called'], 2)
self.assertTrue(isinstance(result, self.rpc.DirectConsumer))
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_declare_consumer_ioerrors_will_reconnect(self):
"""Test that an IOError exception causes a reconnection"""
info = _raise_exc_stub(self.stubs, 2, self.rpc.DirectConsumer,
self.assertEqual(info['called'], 3)
self.assertTrue(isinstance(result, self.rpc.DirectConsumer))
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_publishing_errors_will_reconnect(self):
# Test that any exception with 'timeout' in it causes a
# reconnection when declaring the publisher class and when
self.assertEqual(info['called'], 2)
@test.skip_test("kombu memory transport hangs here on precise")
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_iterconsume_errors_will_reconnect(self):
conn = self.rpc.Connection(FLAGS)
message = 'reconnect test message'
self.assertEqual(self.received_message, message)
# Only called once, because our stub goes away during reconnection
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_call_exception(self):
"""Test that exception gets passed back properly.
#Traceback should be included in exception message
self.assertTrue('raise NotImplementedError(value)' in unicode(exc))
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_call_converted_exception(self):
"""Test that exception gets passed back properly.
from cinder import flags
from cinder import test
-from cinder.rpc import impl_kombu
+
+try:
+ import kombu
+ from cinder.rpc import impl_kombu
+except ImportError:
+ kombu = None
+ impl_kombu = None
+
# Flag settings we will ensure get passed to amqplib
SSL_VERSION = "SSLv2"
def setUp(self):
super(RpcKombuSslTestCase, self).setUp()
- impl_kombu.register_opts(FLAGS)
- self.flags(kombu_ssl_keyfile=SSL_KEYFILE,
- kombu_ssl_ca_certs=SSL_CA_CERT,
- kombu_ssl_certfile=SSL_CERT,
- kombu_ssl_version=SSL_VERSION,
- rabbit_use_ssl=True)
+ if kombu:
+ impl_kombu.register_opts(FLAGS)
+ self.flags(kombu_ssl_keyfile=SSL_KEYFILE,
+ kombu_ssl_ca_certs=SSL_CA_CERT,
+ kombu_ssl_certfile=SSL_CERT,
+ kombu_ssl_version=SSL_VERSION,
+ rabbit_use_ssl=True)
+ @test.skip_if(kombu is None, "Test requires kombu")
def test_ssl_on_extended(self):
rpc = impl_kombu
conn = rpc.create_connection(FLAGS, True)