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:
parent
68ca44526c
commit
3257d83bbb
@ -24,7 +24,6 @@ import datetime
|
||||
|
||||
import mock
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as extension_tests
|
||||
|
||||
from ceilometer import agent
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
@ -126,7 +125,7 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
|
||||
self.transformer_manager)
|
||||
|
||||
def create_extension_manager(self):
|
||||
return extension_tests.TestExtensionManager(
|
||||
return extension.ExtensionManager.make_test_instance(
|
||||
[
|
||||
extension.Extension(
|
||||
'test',
|
||||
@ -149,8 +148,6 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
|
||||
None,
|
||||
self.PollsterExceptionAnother(), ),
|
||||
],
|
||||
'fake',
|
||||
invoke_on_load=False,
|
||||
)
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -21,7 +21,6 @@ import contextlib
|
||||
|
||||
import mock
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as extension_tests
|
||||
|
||||
from ceilometer.alarm import service
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
@ -43,14 +42,15 @@ class TestPartitionedAlarmService(test.BaseTestCase):
|
||||
self.partitioned = service.PartitionedAlarmService()
|
||||
self.partitioned.tg = mock.Mock()
|
||||
self.partitioned.partition_coordinator = mock.Mock()
|
||||
self.extension_mgr = extension_tests.TestExtensionManager(
|
||||
self.extension_mgr = extension.ExtensionManager.make_test_instance(
|
||||
[
|
||||
extension.Extension(
|
||||
'threshold',
|
||||
None,
|
||||
None,
|
||||
self.threshold_eval, ),
|
||||
])
|
||||
]
|
||||
)
|
||||
self.partitioned.extension_manager = self.extension_mgr
|
||||
|
||||
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
|
||||
|
@ -22,7 +22,6 @@ import mock
|
||||
from oslo.config import cfg
|
||||
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as extension_tests
|
||||
|
||||
from ceilometer.alarm import service
|
||||
from ceilometer.openstack.common import test
|
||||
@ -32,14 +31,15 @@ class TestSingletonAlarmService(test.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestSingletonAlarmService, self).setUp()
|
||||
self.threshold_eval = mock.Mock()
|
||||
self.evaluators = extension_tests.TestExtensionManager(
|
||||
self.evaluators = extension.ExtensionManager.make_test_instance(
|
||||
[
|
||||
extension.Extension(
|
||||
'threshold',
|
||||
None,
|
||||
None,
|
||||
self.threshold_eval),
|
||||
])
|
||||
]
|
||||
)
|
||||
self.api_client = mock.MagicMock()
|
||||
self.singleton = service.SingletonAlarmService()
|
||||
self.singleton.tg = mock.Mock()
|
||||
|
@ -21,7 +21,6 @@ import mock
|
||||
from mock import patch
|
||||
import msgpack
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as test_manager
|
||||
|
||||
from ceilometer import collector
|
||||
from ceilometer.openstack.common.fixture import config
|
||||
@ -52,6 +51,16 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
resource_metadata={},
|
||||
).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 recvfrom(size):
|
||||
# Make the loop stop
|
||||
@ -71,13 +80,7 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
|
||||
def test_record_metering_data(self):
|
||||
mock_dispatcher = mock.MagicMock()
|
||||
self.srv.dispatcher_manager = test_manager.TestExtensionManager(
|
||||
[extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
mock_dispatcher
|
||||
),
|
||||
])
|
||||
self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
|
||||
|
||||
self.srv.record_metering_data(None, self.counter)
|
||||
|
||||
@ -86,13 +89,7 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
|
||||
def test_udp_receive(self):
|
||||
mock_dispatcher = mock.MagicMock()
|
||||
self.srv.dispatcher_manager = test_manager.TestExtensionManager(
|
||||
[extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
mock_dispatcher
|
||||
),
|
||||
])
|
||||
self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
|
||||
self.counter['source'] = 'mysource'
|
||||
self.counter['counter_name'] = self.counter['name']
|
||||
self.counter['counter_volume'] = self.counter['volume']
|
||||
@ -110,13 +107,7 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
|
||||
def test_udp_receive_storage_error(self):
|
||||
mock_dispatcher = mock.MagicMock()
|
||||
self.srv.dispatcher_manager = test_manager.TestExtensionManager(
|
||||
[extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
mock_dispatcher
|
||||
),
|
||||
])
|
||||
self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
|
||||
mock_dispatcher.record_metering_data.side_effect = self._raise_error
|
||||
|
||||
self.counter['source'] = 'mysource'
|
||||
|
@ -20,7 +20,6 @@
|
||||
import mock
|
||||
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as test_manager
|
||||
|
||||
from ceilometer.compute.notifications import instance
|
||||
from ceilometer import notification
|
||||
@ -86,6 +85,16 @@ class TestNotification(tests_base.BaseTestCase):
|
||||
self.CONF = self.useFixture(config.Config()).conf
|
||||
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.event.converter.setup_events', mock.MagicMock())
|
||||
def test_process_notification(self):
|
||||
@ -96,13 +105,9 @@ class TestNotification(tests_base.BaseTestCase):
|
||||
with mock.patch('ceilometer.openstack.common.rpc.create_connection'):
|
||||
self.srv.start()
|
||||
self.srv.pipeline_manager.pipelines[0] = mock.MagicMock()
|
||||
self.srv.notification_manager = test_manager.TestExtensionManager(
|
||||
[extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
instance.Instance(),
|
||||
),
|
||||
])
|
||||
self.srv.notification_manager = self._make_test_manager(
|
||||
instance.Instance()
|
||||
)
|
||||
self.srv.process_notification(TEST_NOTICE)
|
||||
self.assertTrue(
|
||||
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.to_event.return_value = mock.MagicMock(
|
||||
event_type='test.test')
|
||||
self.srv.dispatcher_manager = test_manager.TestExtensionManager(
|
||||
[extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
mock_dispatcher
|
||||
),
|
||||
])
|
||||
self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
|
||||
mock_dispatcher.record_events.return_value = [
|
||||
(models.Event.DUPLICATE, object())]
|
||||
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.to_event.return_value = mock.MagicMock(
|
||||
event_type='test.test')
|
||||
self.srv.dispatcher_manager = test_manager.TestExtensionManager(
|
||||
[extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
mock_dispatcher
|
||||
),
|
||||
])
|
||||
self.srv.dispatcher_manager = self._make_test_manager(mock_dispatcher)
|
||||
mock_dispatcher.record_events.return_value = [
|
||||
(models.Event.UNKNOWN_PROBLEM, object())]
|
||||
message = {'event_type': "foo", 'message_id': "abc"}
|
||||
|
@ -25,7 +25,6 @@ import datetime
|
||||
import mock
|
||||
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as test_manager
|
||||
|
||||
## NOTE(dhellmann): These imports are not in the generally approved
|
||||
## 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.
|
||||
self.notifications = []
|
||||
|
||||
ext_mgr = test_manager.TestExtensionManager([
|
||||
extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
self.Pollster(),
|
||||
ext_mgr = extension.ExtensionManager.make_test_instance(
|
||||
extensions=[
|
||||
extension.Extension('test',
|
||||
None,
|
||||
None,
|
||||
self.Pollster(),
|
||||
),
|
||||
])
|
||||
],
|
||||
)
|
||||
self.ext_mgr = ext_mgr
|
||||
self.gatherer = nova_notifier.DeletedInstanceStatsGatherer(ext_mgr)
|
||||
# Initialize the global _gatherer in nova_notifier to use the
|
||||
|
2
tox.ini
2
tox.ini
@ -6,7 +6,7 @@ envlist = py26,py27,py33,pep8
|
||||
[testenv]
|
||||
deps = -r{toxinidir}/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
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
LANG=en_US.UTF-8
|
||||
|
Loading…
Reference in New Issue
Block a user