From 3257d83bbb3e2302638581c995e44d6e84ad44c0 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 27 Jan 2014 17:44:44 -0500 Subject: [PATCH] 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 --- ceilometer/tests/agentbase.py | 5 +-- .../tests/alarm/test_partitioned_alarm_svc.py | 6 +-- .../tests/alarm/test_singleton_alarm_svc.py | 6 +-- ceilometer/tests/test_collector.py | 35 +++++++----------- ceilometer/tests/test_notification.py | 37 ++++++++----------- nova_tests/test_notifier.py | 15 ++++---- tox.ini | 2 +- 7 files changed, 44 insertions(+), 62 deletions(-) diff --git a/ceilometer/tests/agentbase.py b/ceilometer/tests/agentbase.py index 890ac1487..3f4a6e81f 100644 --- a/ceilometer/tests/agentbase.py +++ b/ceilometer/tests/agentbase.py @@ -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 diff --git a/ceilometer/tests/alarm/test_partitioned_alarm_svc.py b/ceilometer/tests/alarm/test_partitioned_alarm_svc.py index cdf728642..94c7b3f9a 100644 --- a/ceilometer/tests/alarm/test_partitioned_alarm_svc.py +++ b/ceilometer/tests/alarm/test_partitioned_alarm_svc.py @@ -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()) diff --git a/ceilometer/tests/alarm/test_singleton_alarm_svc.py b/ceilometer/tests/alarm/test_singleton_alarm_svc.py index 5c77d92d4..1d3b62bd7 100644 --- a/ceilometer/tests/alarm/test_singleton_alarm_svc.py +++ b/ceilometer/tests/alarm/test_singleton_alarm_svc.py @@ -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() diff --git a/ceilometer/tests/test_collector.py b/ceilometer/tests/test_collector.py index b8f5bcfd7..20bfe664c 100644 --- a/ceilometer/tests/test_collector.py +++ b/ceilometer/tests/test_collector.py @@ -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' diff --git a/ceilometer/tests/test_notification.py b/ceilometer/tests/test_notification.py index d284296d9..1ac69096b 100644 --- a/ceilometer/tests/test_notification.py +++ b/ceilometer/tests/test_notification.py @@ -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"} diff --git a/nova_tests/test_notifier.py b/nova_tests/test_notifier.py index 4bcf19609..2f1e37160 100644 --- a/nova_tests/test_notifier.py +++ b/nova_tests/test_notifier.py @@ -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 diff --git a/tox.ini b/tox.ini index 1e7445830..7aea4eb31 100644 --- a/tox.ini +++ b/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