Use stevedore's make_test_instance

Replace the use of TestManager with make_test_instance
to get an instance of the type of manager expected.
The old TestManger class is deprecated.

Change-Id: I73f3202ac7a1420aaa303d5ea2e741b2fe5673e9
Partial-bug: #1273455
This commit is contained in:
Doug Hellmann 2014-01-27 17:44:44 -05:00
parent 68ca44526c
commit 3257d83bbb
7 changed files with 44 additions and 62 deletions

View File

@ -24,7 +24,6 @@ import datetime
import mock import mock
from stevedore import extension from stevedore import extension
from stevedore.tests import manager as extension_tests
from ceilometer import agent from ceilometer import agent
from ceilometer.openstack.common.fixture import config from ceilometer.openstack.common.fixture import config
@ -126,7 +125,7 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
self.transformer_manager) self.transformer_manager)
def create_extension_manager(self): def create_extension_manager(self):
return extension_tests.TestExtensionManager( return extension.ExtensionManager.make_test_instance(
[ [
extension.Extension( extension.Extension(
'test', 'test',
@ -149,8 +148,6 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
None, None,
self.PollsterExceptionAnother(), ), self.PollsterExceptionAnother(), ),
], ],
'fake',
invoke_on_load=False,
) )
@abc.abstractmethod @abc.abstractmethod

View File

@ -21,7 +21,6 @@ import contextlib
import mock import mock
from stevedore import extension from stevedore import extension
from stevedore.tests import manager as extension_tests
from ceilometer.alarm import service from ceilometer.alarm import service
from ceilometer.openstack.common.fixture import config from ceilometer.openstack.common.fixture import config
@ -43,14 +42,15 @@ class TestPartitionedAlarmService(test.BaseTestCase):
self.partitioned = service.PartitionedAlarmService() self.partitioned = service.PartitionedAlarmService()
self.partitioned.tg = mock.Mock() self.partitioned.tg = mock.Mock()
self.partitioned.partition_coordinator = mock.Mock() self.partitioned.partition_coordinator = mock.Mock()
self.extension_mgr = extension_tests.TestExtensionManager( self.extension_mgr = extension.ExtensionManager.make_test_instance(
[ [
extension.Extension( extension.Extension(
'threshold', 'threshold',
None, None,
None, None,
self.threshold_eval, ), self.threshold_eval, ),
]) ]
)
self.partitioned.extension_manager = self.extension_mgr self.partitioned.extension_manager = self.extension_mgr
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())

View File

@ -22,7 +22,6 @@ import mock
from oslo.config import cfg from oslo.config import cfg
from stevedore import extension from stevedore import extension
from stevedore.tests import manager as extension_tests
from ceilometer.alarm import service from ceilometer.alarm import service
from ceilometer.openstack.common import test from ceilometer.openstack.common import test
@ -32,14 +31,15 @@ class TestSingletonAlarmService(test.BaseTestCase):
def setUp(self): def setUp(self):
super(TestSingletonAlarmService, self).setUp() super(TestSingletonAlarmService, self).setUp()
self.threshold_eval = mock.Mock() self.threshold_eval = mock.Mock()
self.evaluators = extension_tests.TestExtensionManager( self.evaluators = extension.ExtensionManager.make_test_instance(
[ [
extension.Extension( extension.Extension(
'threshold', 'threshold',
None, None,
None, None,
self.threshold_eval), self.threshold_eval),
]) ]
)
self.api_client = mock.MagicMock() self.api_client = mock.MagicMock()
self.singleton = service.SingletonAlarmService() self.singleton = service.SingletonAlarmService()
self.singleton.tg = mock.Mock() self.singleton.tg = mock.Mock()

View File

@ -21,7 +21,6 @@ import mock
from mock import patch from mock import patch
import msgpack import msgpack
from stevedore import extension from stevedore import extension
from stevedore.tests import manager as test_manager
from ceilometer import collector from ceilometer import collector
from ceilometer.openstack.common.fixture import config from ceilometer.openstack.common.fixture import config
@ -52,6 +51,16 @@ class TestCollector(tests_base.BaseTestCase):
resource_metadata={}, resource_metadata={},
).as_dict() ).as_dict()
def _make_test_manager(self, plugin):
return extension.ExtensionManager.make_test_instance([
extension.Extension(
'test',
None,
None,
plugin,
),
])
def _make_fake_socket(self): def _make_fake_socket(self):
def recvfrom(size): def recvfrom(size):
# Make the loop stop # Make the loop stop
@ -71,13 +80,7 @@ class TestCollector(tests_base.BaseTestCase):
def test_record_metering_data(self): def test_record_metering_data(self):
mock_dispatcher = mock.MagicMock() mock_dispatcher = mock.MagicMock()
self.srv.dispatcher_manager = test_manager.TestExtensionManager( self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
[extension.Extension('test',
None,
None,
mock_dispatcher
),
])
self.srv.record_metering_data(None, self.counter) self.srv.record_metering_data(None, self.counter)
@ -86,13 +89,7 @@ class TestCollector(tests_base.BaseTestCase):
def test_udp_receive(self): def test_udp_receive(self):
mock_dispatcher = mock.MagicMock() mock_dispatcher = mock.MagicMock()
self.srv.dispatcher_manager = test_manager.TestExtensionManager( self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
[extension.Extension('test',
None,
None,
mock_dispatcher
),
])
self.counter['source'] = 'mysource' self.counter['source'] = 'mysource'
self.counter['counter_name'] = self.counter['name'] self.counter['counter_name'] = self.counter['name']
self.counter['counter_volume'] = self.counter['volume'] self.counter['counter_volume'] = self.counter['volume']
@ -110,13 +107,7 @@ class TestCollector(tests_base.BaseTestCase):
def test_udp_receive_storage_error(self): def test_udp_receive_storage_error(self):
mock_dispatcher = mock.MagicMock() mock_dispatcher = mock.MagicMock()
self.srv.dispatcher_manager = test_manager.TestExtensionManager( self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
[extension.Extension('test',
None,
None,
mock_dispatcher
),
])
mock_dispatcher.record_metering_data.side_effect = self._raise_error mock_dispatcher.record_metering_data.side_effect = self._raise_error
self.counter['source'] = 'mysource' self.counter['source'] = 'mysource'

View File

@ -20,7 +20,6 @@
import mock import mock
from stevedore import extension from stevedore import extension
from stevedore.tests import manager as test_manager
from ceilometer.compute.notifications import instance from ceilometer.compute.notifications import instance
from ceilometer import notification from ceilometer import notification
@ -86,6 +85,16 @@ class TestNotification(tests_base.BaseTestCase):
self.CONF = self.useFixture(config.Config()).conf self.CONF = self.useFixture(config.Config()).conf
self.CONF.set_override("connection", "log://", group='database') self.CONF.set_override("connection", "log://", group='database')
def _make_test_manager(self, plugin):
return extension.ExtensionManager.make_test_instance(
[
extension.Extension('test',
None,
None,
plugin),
]
)
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock()) @mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
@mock.patch('ceilometer.event.converter.setup_events', mock.MagicMock()) @mock.patch('ceilometer.event.converter.setup_events', mock.MagicMock())
def test_process_notification(self): def test_process_notification(self):
@ -96,13 +105,9 @@ class TestNotification(tests_base.BaseTestCase):
with mock.patch('ceilometer.openstack.common.rpc.create_connection'): with mock.patch('ceilometer.openstack.common.rpc.create_connection'):
self.srv.start() self.srv.start()
self.srv.pipeline_manager.pipelines[0] = mock.MagicMock() self.srv.pipeline_manager.pipelines[0] = mock.MagicMock()
self.srv.notification_manager = test_manager.TestExtensionManager( self.srv.notification_manager = self._make_test_manager(
[extension.Extension('test', instance.Instance()
None, )
None,
instance.Instance(),
),
])
self.srv.process_notification(TEST_NOTICE) self.srv.process_notification(TEST_NOTICE)
self.assertTrue( self.assertTrue(
self.srv.pipeline_manager.publisher.called) self.srv.pipeline_manager.publisher.called)
@ -129,13 +134,7 @@ class TestNotification(tests_base.BaseTestCase):
self.srv.event_converter = mock.MagicMock() self.srv.event_converter = mock.MagicMock()
self.srv.event_converter.to_event.return_value = mock.MagicMock( self.srv.event_converter.to_event.return_value = mock.MagicMock(
event_type='test.test') event_type='test.test')
self.srv.dispatcher_manager = test_manager.TestExtensionManager( self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
[extension.Extension('test',
None,
None,
mock_dispatcher
),
])
mock_dispatcher.record_events.return_value = [ mock_dispatcher.record_events.return_value = [
(models.Event.DUPLICATE, object())] (models.Event.DUPLICATE, object())]
message = {'event_type': "foo", 'message_id': "abc"} message = {'event_type': "foo", 'message_id': "abc"}
@ -147,13 +146,7 @@ class TestNotification(tests_base.BaseTestCase):
self.srv.event_converter = mock.MagicMock() self.srv.event_converter = mock.MagicMock()
self.srv.event_converter.to_event.return_value = mock.MagicMock( self.srv.event_converter.to_event.return_value = mock.MagicMock(
event_type='test.test') event_type='test.test')
self.srv.dispatcher_manager = test_manager.TestExtensionManager( self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
[extension.Extension('test',
None,
None,
mock_dispatcher
),
])
mock_dispatcher.record_events.return_value = [ mock_dispatcher.record_events.return_value = [
(models.Event.UNKNOWN_PROBLEM, object())] (models.Event.UNKNOWN_PROBLEM, object())]
message = {'event_type': "foo", 'message_id': "abc"} message = {'event_type': "foo", 'message_id': "abc"}

View File

@ -25,7 +25,6 @@ import datetime
import mock import mock
from stevedore import extension from stevedore import extension
from stevedore.tests import manager as test_manager
## NOTE(dhellmann): These imports are not in the generally approved ## NOTE(dhellmann): These imports are not in the generally approved
## alphabetical order, but they are in the order that actually ## alphabetical order, but they are in the order that actually
@ -187,13 +186,15 @@ class TestNovaNotifier(test.BaseTestCase):
# plugin and to invoke our notifier plugin. # plugin and to invoke our notifier plugin.
self.notifications = [] self.notifications = []
ext_mgr = test_manager.TestExtensionManager([ ext_mgr = extension.ExtensionManager.make_test_instance(
extensions=[
extension.Extension('test', extension.Extension('test',
None, None,
None, None,
self.Pollster(), self.Pollster(),
), ),
]) ],
)
self.ext_mgr = ext_mgr self.ext_mgr = ext_mgr
self.gatherer = nova_notifier.DeletedInstanceStatsGatherer(ext_mgr) self.gatherer = nova_notifier.DeletedInstanceStatsGatherer(ext_mgr)
# Initialize the global _gatherer in nova_notifier to use the # Initialize the global _gatherer in nova_notifier to use the

View File

@ -6,7 +6,7 @@ envlist = py26,py27,py33,pep8
[testenv] [testenv]
deps = -r{toxinidir}/requirements.txt deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
install_command = pip install -U {opts} {packages} install_command = pip install -U --allow-external pytidylib --allow-insecure pytidylib {opts} {packages}
usedevelop = True usedevelop = True
setenv = VIRTUAL_ENV={envdir} setenv = VIRTUAL_ENV={envdir}
LANG=en_US.UTF-8 LANG=en_US.UTF-8