diff --git a/ceilometer/collector.py b/ceilometer/collector.py index 2522a556d..9db3ad43b 100644 --- a/ceilometer/collector.py +++ b/ceilometer/collector.py @@ -80,9 +80,9 @@ class CollectorService(service.DispatchedService, rpc_service.Service): sample['counter_unit'] = sample['unit'] sample['counter_type'] = sample['type'] LOG.debug("UDP: Storing %s", str(sample)) - self.dispatcher_manager.map( - lambda ext, data: ext.obj.record_metering_data(data), - sample) + self.dispatcher_manager.map_method('record_metering_data', + None, + sample) except Exception: LOG.exception(_("UDP: Unable to store meter")) @@ -106,19 +106,9 @@ class CollectorService(service.DispatchedService, rpc_service.Service): When the notification messages are re-published through the RPC publisher, this method receives them for processing. """ - self.dispatcher_manager.map(self._record_metering_data_for_ext, - context=context, - data=data) - - @staticmethod - def _record_metering_data_for_ext(ext, context, data): - """Wrapper for calling dispatcher plugin when a sample arrives - - When a message is received by record_metering_data(), it calls - this method with each plugin to allow it to process the data. - - """ - ext.obj.record_metering_data(context, data) + self.dispatcher_manager.map_method('record_metering_data', + context=context, + data=data) def collector(): diff --git a/ceilometer/compute/nova_notifier.py b/ceilometer/compute/nova_notifier.py index 64b1566fc..bb1946b3e 100644 --- a/ceilometer/compute/nova_notifier.py +++ b/ceilometer/compute/nova_notifier.py @@ -56,15 +56,12 @@ class DeletedInstanceStatsGatherer(object): self.mgr = extensions self.inspector = inspector.get_hypervisor_inspector() - def _get_samples_from_plugin(self, ext, cache, instance, *args, **kwds): - """Used with the extenaion manager map() method.""" - return ext.obj.get_samples(self, cache, instance) - def __call__(self, instance): cache = {} - samples = self.mgr.map(self._get_samples_from_plugin, - cache=cache, - instance=instance) + samples = self.mgr.map_method('get_samples', + self, + cache, + instance) # samples is a list of lists, so flatten it before returning # the results results = [] diff --git a/ceilometer/tests/test_collector.py b/ceilometer/tests/test_collector.py index e10a9e42b..ebc37d790 100644 --- a/ceilometer/tests/test_collector.py +++ b/ceilometer/tests/test_collector.py @@ -64,6 +64,22 @@ class TestCollector(tests_base.BaseTestCase): udp_socket.bind.assert_called_once_with((conf.udp_address, conf.udp_port)) + 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.record_metering_data(None, self.counter) + + mock_dispatcher.record_metering_data.assert_called_once_with( + context=None, + data=self.counter) + def test_udp_receive(self): mock_dispatcher = mock.MagicMock() self.srv.dispatcher_manager = test_manager.TestExtensionManager( @@ -86,6 +102,7 @@ class TestCollector(tests_base.BaseTestCase): self._verify_udp_socket(udp_socket) mock_dispatcher.record_metering_data.assert_called_once_with( + None, self.counter) def test_udp_receive_storage_error(self): @@ -112,6 +129,7 @@ class TestCollector(tests_base.BaseTestCase): self._verify_udp_socket(udp_socket) mock_dispatcher.record_metering_data.assert_called_once_with( + None, self.counter) @staticmethod diff --git a/requirements.txt b/requirements.txt index 15300dda9..a4d4ad16b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ eventlet>=0.13.0 anyjson>=0.3.3 Flask>=0.10,<1.0 pecan>=0.2.0 -stevedore>=0.10 +stevedore>=0.12 msgpack-python python-glanceclient>=0.9.0 python-novaclient>=2.15.0