From 3942c72dae57bcb54c4aec413e1bfae5d377447f Mon Sep 17 00:00:00 2001 From: liu-sheng Date: Tue, 23 Jun 2015 20:42:22 +0800 Subject: [PATCH] Remove the unused get_targets method of plugin base As marked in TODO list, the get_targets method need to be removed in J+2, This change do: * Remove the get_targets method and relevant test * Add a test for info method of plugin base Change-Id: Id4274593ad81b397dd6fcf99737fd349e72ed773 --- ceilometer/agent/plugin_base.py | 13 +------- ceilometer/tests/agent/test_plugin.py | 43 ++++++++++++++++----------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/ceilometer/agent/plugin_base.py b/ceilometer/agent/plugin_base.py index c731b5551..814f18628 100644 --- a/ceilometer/agent/plugin_base.py +++ b/ceilometer/agent/plugin_base.py @@ -104,6 +104,7 @@ class NotificationBase(PluginBase): Strings are defining the event types to be given to this plugin. """ + @abc.abstractmethod def get_targets(self, conf): """Return a sequence of oslo.messaging.Target. @@ -112,18 +113,6 @@ class NotificationBase(PluginBase): :param conf: Configuration. """ - # TODO(sileht): Backwards compatibility, remove in J+2 - if hasattr(self, 'get_exchange_topics'): - LOG.warn(_('get_exchange_topics API of NotificationPlugin is' - 'deprecated, implements get_targets instead.')) - - targets = [] - for exchange, topics in self.get_exchange_topics(conf): - targets.extend(oslo_messaging.Target(topic=topic, - exchange=exchange) - for topic in topics) - return targets - @abc.abstractmethod def process_notification(self, message): """Return a sequence of Counter instances for the given message. diff --git a/ceilometer/tests/agent/test_plugin.py b/ceilometer/tests/agent/test_plugin.py index ad5d9057c..3f1603710 100644 --- a/ceilometer/tests/agent/test_plugin.py +++ b/ceilometer/tests/agent/test_plugin.py @@ -28,22 +28,31 @@ class NotificationBaseTestCase(base.BaseTestCase): class FakePlugin(plugin_base.NotificationBase): event_types = ['compute.*'] - @staticmethod - def get_exchange_topics(conf): - return [plugin_base.ExchangeTopics(exchange="exchange1", - topics=["t1", "t2"]), - plugin_base.ExchangeTopics(exchange="exchange2", - topics=['t3'])] - def process_notification(self, message): - return message + pass - def test_get_targets_compat(self): - targets = self.FakePlugin(mock.Mock()).get_targets(self.CONF) - self.assertEqual(3, len(targets)) - self.assertEqual('t1', targets[0].topic) - self.assertEqual('exchange1', targets[0].exchange) - self.assertEqual('t2', targets[1].topic) - self.assertEqual('exchange1', targets[1].exchange) - self.assertEqual('t3', targets[2].topic) - self.assertEqual('exchange2', targets[2].exchange) + def get_targets(self, conf): + pass + + def test_plugin_info(self): + plugin = self.FakePlugin(mock.Mock()) + plugin.to_samples_and_publish = mock.Mock() + ctxt = {'user_id': 'fake_user_id', 'project_id': 'fake_project_id'} + publisher_id = 'fake.publisher_id' + event_type = 'fake.event' + payload = {'foo': 'bar'} + metadata = {'message_id': '3577a84f-29ec-4904-9566-12c52289c2e8', + 'timestamp': '2015-06-1909:19:35.786893'} + plugin.info(ctxt, publisher_id, event_type, payload, metadata) + notification = { + 'priority': 'info', + 'event_type': 'fake.event', + 'timestamp': '2015-06-1909:19:35.786893', + '_context_user_id': 'fake_user_id', + '_context_project_id': 'fake_project_id', + 'publisher_id': 'fake.publisher_id', + 'payload': {'foo': 'bar'}, + 'message_id': '3577a84f-29ec-4904-9566-12c52289c2e8' + } + plugin.to_samples_and_publish.assert_called_with(mock.ANY, + notification)