Merge "Use map_method from stevedore 0.12"

This commit is contained in:
Jenkins 2013-11-27 12:57:14 +00:00 committed by Gerrit Code Review
commit a2f80f2a19
4 changed files with 29 additions and 24 deletions

View File

@ -80,9 +80,9 @@ class CollectorService(service.DispatchedService, rpc_service.Service):
sample['counter_unit'] = sample['unit'] sample['counter_unit'] = sample['unit']
sample['counter_type'] = sample['type'] sample['counter_type'] = sample['type']
LOG.debug("UDP: Storing %s", str(sample)) LOG.debug("UDP: Storing %s", str(sample))
self.dispatcher_manager.map( self.dispatcher_manager.map_method('record_metering_data',
lambda ext, data: ext.obj.record_metering_data(data), None,
sample) sample)
except Exception: except Exception:
LOG.exception(_("UDP: Unable to store meter")) 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 When the notification messages are re-published through the
RPC publisher, this method receives them for processing. RPC publisher, this method receives them for processing.
""" """
self.dispatcher_manager.map(self._record_metering_data_for_ext, self.dispatcher_manager.map_method('record_metering_data',
context=context, context=context,
data=data) 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)
def collector(): def collector():

View File

@ -56,15 +56,12 @@ class DeletedInstanceStatsGatherer(object):
self.mgr = extensions self.mgr = extensions
self.inspector = inspector.get_hypervisor_inspector() 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): def __call__(self, instance):
cache = {} cache = {}
samples = self.mgr.map(self._get_samples_from_plugin, samples = self.mgr.map_method('get_samples',
cache=cache, self,
instance=instance) cache,
instance)
# samples is a list of lists, so flatten it before returning # samples is a list of lists, so flatten it before returning
# the results # the results
results = [] results = []

View File

@ -64,6 +64,22 @@ class TestCollector(tests_base.BaseTestCase):
udp_socket.bind.assert_called_once_with((conf.udp_address, udp_socket.bind.assert_called_once_with((conf.udp_address,
conf.udp_port)) 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): def test_udp_receive(self):
mock_dispatcher = mock.MagicMock() mock_dispatcher = mock.MagicMock()
self.srv.dispatcher_manager = test_manager.TestExtensionManager( self.srv.dispatcher_manager = test_manager.TestExtensionManager(
@ -86,6 +102,7 @@ class TestCollector(tests_base.BaseTestCase):
self._verify_udp_socket(udp_socket) self._verify_udp_socket(udp_socket)
mock_dispatcher.record_metering_data.assert_called_once_with( mock_dispatcher.record_metering_data.assert_called_once_with(
None,
self.counter) self.counter)
def test_udp_receive_storage_error(self): def test_udp_receive_storage_error(self):
@ -112,6 +129,7 @@ class TestCollector(tests_base.BaseTestCase):
self._verify_udp_socket(udp_socket) self._verify_udp_socket(udp_socket)
mock_dispatcher.record_metering_data.assert_called_once_with( mock_dispatcher.record_metering_data.assert_called_once_with(
None,
self.counter) self.counter)
@staticmethod @staticmethod

View File

@ -12,7 +12,7 @@ eventlet>=0.13.0
anyjson>=0.3.3 anyjson>=0.3.3
Flask>=0.10,<1.0 Flask>=0.10,<1.0
pecan>=0.2.0 pecan>=0.2.0
stevedore>=0.10 stevedore>=0.12
msgpack-python msgpack-python
python-glanceclient>=0.9.0 python-glanceclient>=0.9.0
python-novaclient>=2.15.0 python-novaclient>=2.15.0