diff --git a/nova/test.py b/nova/test.py index b6ae5ad5a..18c7b10cb 100644 --- a/nova/test.py +++ b/nova/test.py @@ -33,7 +33,6 @@ import os import fixtures from oslo.config import cfg from oslo.config import fixture as config_fixture -from oslo.messaging import conffixture as messaging_conffixture from oslo.utils import timeutils from oslo_concurrency import lockutils from oslotest import moxstubout @@ -48,7 +47,6 @@ from nova import objects from nova.objects import base as objects_base from nova.openstack.common.fixture import logging as log_fixture from nova.openstack.common import log as nova_logging -from nova import rpc from nova.tests import fixtures as nova_fixtures from nova.tests.unit import conf_fixture from nova.tests.unit import policy_fixture @@ -208,10 +206,6 @@ class TestCase(testtools.TestCase): self.useFixture(nova_fixtures.StandardLogging()) - rpc.add_extra_exmods('nova.test') - self.addCleanup(rpc.clear_extra_exmods) - self.addCleanup(rpc.cleanup) - # NOTE(sdague): because of the way we were using the lock # wrapper we eneded up with a lot of tests that started # relying on global external locking being set up for them. We @@ -231,12 +225,7 @@ class TestCase(testtools.TestCase): group='oslo_concurrency') self.useFixture(conf_fixture.ConfFixture(CONF)) - - self.messaging_conf = messaging_conffixture.ConfFixture(CONF) - self.messaging_conf.transport_driver = 'fake' - self.useFixture(self.messaging_conf) - - rpc.init(CONF) + self.useFixture(nova_fixtures.RPCFixture('nova.test')) if self.USES_DB: self.useFixture(nova_fixtures.Database()) diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index f31f48de7..e725c7dca 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -24,8 +24,9 @@ import uuid import fixtures from oslo.config import cfg - +from oslo.messaging import conffixture as messaging_conffixture from nova.db import migration +from nova import rpc from nova.db.sqlalchemy import api as session from nova import service @@ -217,3 +218,20 @@ class Database(fixtures.Fixture): def setUp(self): super(Database, self).setUp() self.reset() + + +class RPCFixture(fixtures.Fixture): + def __init__(self, *exmods): + super(RPCFixture, self).__init__() + self.exmods = [] + self.exmods.extend(exmods) + + def setUp(self): + super(RPCFixture, self).setUp() + self.addCleanup(rpc.cleanup) + rpc.add_extra_exmods(*self.exmods) + self.addCleanup(rpc.clear_extra_exmods) + self.messaging_conf = messaging_conffixture.ConfFixture(CONF) + self.messaging_conf.transport_driver = 'fake' + self.useFixture(self.messaging_conf) + rpc.init(CONF)