diff options
author | Mark McLoughlin <markmc@redhat.com> | 2012-07-20 17:04:54 +0100 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2012-07-20 17:05:43 +0100 |
commit | a224d7048068330fb62624c2d2a542d0ad30d8dc (patch) | |
tree | 2c79eb4ba888c91592cc03c123d1b208ae7ddfb8 /tests/unit/rpc | |
parent | a852c832e4576e69eb3b15a5989375c79a3aac46 (diff) | |
download | oslo-a224d7048068330fb62624c2d2a542d0ad30d8dc.tar.gz oslo-a224d7048068330fb62624c2d2a542d0ad30d8dc.tar.xz oslo-a224d7048068330fb62624c2d2a542d0ad30d8dc.zip |
Use BaseTestCase for all tests which override config
Fixes bug #1027120
We already have nice helper methods for overriding config and cleaning
up the overrides, so let's use them.
Change-Id: Ibd501743d1c4ec21cb2b0d22382cb681ee5768ed
Diffstat (limited to 'tests/unit/rpc')
-rw-r--r-- | tests/unit/rpc/common.py | 4 | ||||
-rw-r--r-- | tests/unit/rpc/test_common.py | 15 | ||||
-rw-r--r-- | tests/unit/rpc/test_kombu.py | 9 | ||||
-rw-r--r-- | tests/unit/rpc/test_kombu_ssl.py | 29 |
4 files changed, 19 insertions, 38 deletions
diff --git a/tests/unit/rpc/common.py b/tests/unit/rpc/common.py index 3497688..5f21328 100644 --- a/tests/unit/rpc/common.py +++ b/tests/unit/rpc/common.py @@ -21,7 +21,6 @@ Unit Tests for remote procedure calls shared between all implementations import logging import time -import unittest import eventlet from eventlet import greenthread @@ -33,13 +32,14 @@ from openstack.common.gettextutils import _ from openstack.common.rpc import amqp as rpc_amqp from openstack.common.rpc import common as rpc_common from openstack.common.rpc import dispatcher as rpc_dispatcher +from tests import utils as test_utils FLAGS = cfg.CONF LOG = logging.getLogger(__name__) -class BaseRpcTestCase(unittest.TestCase): +class BaseRpcTestCase(test_utils.BaseTestCase): def setUp(self, supports_timeouts=True, topic='test', topic_nested='nested'): super(BaseRpcTestCase, self).setUp() diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py index 8755b75..09f7b59 100644 --- a/tests/unit/rpc/test_common.py +++ b/tests/unit/rpc/test_common.py @@ -19,7 +19,6 @@ Unit Tests for 'common' functons used through rpc code. import logging import sys -import unittest from openstack.common import cfg from openstack.common import context @@ -30,6 +29,7 @@ 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 +from tests import utils as test_utils FLAGS = cfg.CONF @@ -45,7 +45,7 @@ class FakeUserDefinedException(Exception): Exception.__init__(self, "Test Message") -class RpcCommonTestCase(unittest.TestCase): +class RpcCommonTestCase(test_utils.BaseTestCase): def test_serialize_remote_exception(self): expected = { 'class': 'Exception', @@ -114,8 +114,7 @@ class RpcCommonTestCase(unittest.TestCase): def test_deserialize_remote_exception_user_defined_exception(self): """Ensure a user defined exception can be deserialized.""" - FLAGS.set_override('allowed_rpc_exception_modules', - [self.__class__.__module__]) + self.config(allowed_rpc_exception_modules=[self.__class__.__module__]) failure = { 'class': 'FakeUserDefinedException', 'module': self.__class__.__module__, @@ -127,7 +126,6 @@ class RpcCommonTestCase(unittest.TestCase): self.assertTrue(isinstance(after_exc, FakeUserDefinedException)) #assure the traceback was added self.assertTrue('raise FakeUserDefinedException' in unicode(after_exc)) - FLAGS.reset() def test_deserialize_remote_exception_cannot_recreate(self): """Ensure a RemoteError is returned on initialization failure. @@ -136,8 +134,7 @@ class RpcCommonTestCase(unittest.TestCase): RemoteError with the exception informations should still be returned. """ - FLAGS.set_override('allowed_rpc_exception_modules', - [self.__class__.__module__]) + self.config(allowed_rpc_exception_modules=[self.__class__.__module__]) failure = { 'class': 'FakeIDontExistException', 'module': self.__class__.__module__, @@ -149,10 +146,9 @@ class RpcCommonTestCase(unittest.TestCase): self.assertTrue(isinstance(after_exc, rpc_common.RemoteError)) #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') + self.config(rpc_backend='nova.rpc.impl_qpid') rpc._RPCIMPL = None self.mod = None @@ -170,6 +166,5 @@ class RpcCommonTestCase(unittest.TestCase): rpc._get_impl() importutils.import_module = orig_import_module - FLAGS.reset() self.assertEqual(self.mod, 'nova.openstack.common.rpc.impl_qpid') diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py index e280e1e..2cdca15 100644 --- a/tests/unit/rpc/test_kombu.py +++ b/tests/unit/rpc/test_kombu.py @@ -68,8 +68,8 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase): def setUp(self): self.stubs = stubout.StubOutForTesting() if kombu: - FLAGS.set_override('fake_rabbit', True) - FLAGS.set_override('rpc_response_timeout', 5) + self.config(fake_rabbit=True) + self.config(rpc_response_timeout=5) self.rpc = impl_kombu else: self.rpc = None @@ -80,7 +80,6 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase): self.stubs.SmartUnsetAll() if kombu: impl_kombu.cleanup() - FLAGS.reset() super(RpcKombuTestCase, self).tearDown() @testutils.skip_if(kombu is None, "Test requires kombu") @@ -365,7 +364,7 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase): exception is converted to a string. """ - FLAGS.set_override('allowed_rpc_exception_modules', ['exceptions']) + self.config(allowed_rpc_exception_modules=['exceptions']) value = "This is the exception message" self.assertRaises(NotImplementedError, self.rpc.call, @@ -385,8 +384,6 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase): #Traceback should be included in exception message self.assertTrue('raise NotImplementedError(value)' in unicode(exc)) - FLAGS.reset() - @testutils.skip_if(kombu is None, "Test requires kombu") def test_call_converted_exception(self): """Test that exception gets passed back properly. diff --git a/tests/unit/rpc/test_kombu_ssl.py b/tests/unit/rpc/test_kombu_ssl.py index 2aecc3f..6d9265b 100644 --- a/tests/unit/rpc/test_kombu_ssl.py +++ b/tests/unit/rpc/test_kombu_ssl.py @@ -22,10 +22,10 @@ Unit Tests for remote procedure calls using kombu + ssl import eventlet eventlet.monkey_patch() -import unittest - from openstack.common import cfg from openstack.common import testutils +from tests import utils as test_utils + try: import kombu @@ -44,27 +44,16 @@ SSL_KEYFILE = "/tmp/keyfile.blah.blah" FLAGS = cfg.CONF -class RpcKombuSslTestCase(unittest.TestCase): +class RpcKombuSslTestCase(test_utils.BaseTestCase): def setUp(self): super(RpcKombuSslTestCase, self).setUp() - override = { - '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, - 'fake_rabbit': True, - } - - if kombu: - for k, v in override.iteritems(): - FLAGS.set_override(k, v) - - def tearDown(self): - super(RpcKombuSslTestCase, self).tearDown() - if kombu: - FLAGS.reset() + self.config(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, + fake_rabbit=True) @testutils.skip_if(kombu is None, "Test requires kombu") def test_ssl_on_extended(self): |