diff --git a/oslo/messaging/_drivers/amqpdriver.py b/oslo/messaging/_drivers/amqpdriver.py index 1734dc77b..5a84c1a89 100644 --- a/oslo/messaging/_drivers/amqpdriver.py +++ b/oslo/messaging/_drivers/amqpdriver.py @@ -322,3 +322,8 @@ class AMQPDriverBase(base.BaseDriver): conn.declare_fanout_consumer(target.topic, listener) return listener + + def cleanup(self): + if self._connection_pool: + self._connection_pool.empty() + self._connection_pool = None diff --git a/oslo/messaging/_drivers/base.py b/oslo/messaging/_drivers/base.py index 98cbc613b..40b938bff 100644 --- a/oslo/messaging/_drivers/base.py +++ b/oslo/messaging/_drivers/base.py @@ -72,3 +72,7 @@ class BaseDriver(object): @abc.abstractmethod def listen(self, target): """Construct a Listener for the given target.""" + + @abc.abstractmethod + def cleanup(self): + """Release all resources.""" diff --git a/oslo/messaging/_drivers/impl_fake.py b/oslo/messaging/_drivers/impl_fake.py index db78d8add..f6defc092 100644 --- a/oslo/messaging/_drivers/impl_fake.py +++ b/oslo/messaging/_drivers/impl_fake.py @@ -164,3 +164,6 @@ class FakeDriver(base.BaseDriver): self._default_exchange) return FakeListener(self, target, exchange) + + def cleanup(self): + pass diff --git a/oslo/messaging/transport.py b/oslo/messaging/transport.py index d27dc1430..390899262 100644 --- a/oslo/messaging/transport.py +++ b/oslo/messaging/transport.py @@ -85,6 +85,10 @@ class Transport(object): def _listen(self, target): return self._driver.listen(target) + def cleanup(self): + """Release all resources associated with this transport.""" + self._driver.cleanup() + class InvalidTransportURL(exceptions.MessagingException): """Raised if transport URL is invalid.""" diff --git a/tests/test_rabbit.py b/tests/test_rabbit.py index 04b90a6ed..3cb2203da 100644 --- a/tests/test_rabbit.py +++ b/tests/test_rabbit.py @@ -29,9 +29,6 @@ class TestRabbitDriver(test_utils.BaseTestCase): self.config(rpc_backend='rabbit') self.config(fake_rabbit=True) - # FIXME(markmc): this should be a cleanup method on the driver itself - self.addCleanup(rabbit_driver.cleanup) - def test_driver_load(self): transport = messaging.get_transport(self.conf) self.assertTrue(isinstance(transport._driver, @@ -39,6 +36,8 @@ class TestRabbitDriver(test_utils.BaseTestCase): def test_send_receive(self): transport = messaging.get_transport(self.conf) + self.addCleanup(transport.cleanup) + driver = transport._driver target = messaging.Target(topic='testtopic')