Simplify the dispatcher method prototype
`record_metering_data' is receiving a context that is never used in the dispatch drivers. So let's remove it to simplify our code and interfaces. Change-Id: I811fe86b86749de4c4d52a57e761021604f7b818
This commit is contained in:
parent
9d9dc47338
commit
fe1158de8c
@ -81,7 +81,6 @@ class CollectorService(service.DispatchedService, rpc_service.Service):
|
||||
sample['counter_type'] = sample['type']
|
||||
LOG.debug("UDP: Storing %s", str(sample))
|
||||
self.dispatcher_manager.map_method('record_metering_data',
|
||||
None,
|
||||
sample)
|
||||
except Exception:
|
||||
LOG.exception(_("UDP: Unable to store meter"))
|
||||
@ -107,7 +106,6 @@ class CollectorService(service.DispatchedService, rpc_service.Service):
|
||||
RPC publisher, this method receives them for processing.
|
||||
"""
|
||||
self.dispatcher_manager.map_method('record_metering_data',
|
||||
context=context,
|
||||
data=data)
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@ class Base(object):
|
||||
self.conf = conf
|
||||
|
||||
@abc.abstractmethod
|
||||
def record_metering_data(self, context, data):
|
||||
def record_metering_data(self, data):
|
||||
"""Recording metering data interface."""
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -40,7 +40,7 @@ class DatabaseDispatcher(dispatcher.Base):
|
||||
super(DatabaseDispatcher, self).__init__(conf)
|
||||
self.storage_conn = storage.get_connection(conf)
|
||||
|
||||
def record_metering_data(self, context, data):
|
||||
def record_metering_data(self, data):
|
||||
# We may have receive only one counter on the wire
|
||||
if not isinstance(data, list):
|
||||
data = [data]
|
||||
|
@ -78,7 +78,7 @@ class FileDispatcher(dispatcher.Base):
|
||||
dispatcher_logger.addHandler(rfh)
|
||||
self.log = dispatcher_logger
|
||||
|
||||
def record_metering_data(self, context, data):
|
||||
def record_metering_data(self, data):
|
||||
if self.log:
|
||||
self.log.info(data)
|
||||
|
||||
|
@ -45,7 +45,7 @@ class TestDispatcherDB(test.BaseTestCase):
|
||||
|
||||
with mock.patch.object(self.dispatcher.storage_conn,
|
||||
'record_metering_data') as record_metering_data:
|
||||
self.dispatcher.record_metering_data(self.ctx, msg)
|
||||
self.dispatcher.record_metering_data(msg)
|
||||
|
||||
record_metering_data.assert_called_once_with(msg)
|
||||
|
||||
@ -65,7 +65,7 @@ class TestDispatcherDB(test.BaseTestCase):
|
||||
|
||||
self.dispatcher.storage_conn = ErrorConnection()
|
||||
|
||||
self.dispatcher.record_metering_data(self.ctx, msg)
|
||||
self.dispatcher.record_metering_data(msg)
|
||||
|
||||
assert not self.dispatcher.storage_conn.called, \
|
||||
'Should not have called the storage connection'
|
||||
@ -86,7 +86,7 @@ class TestDispatcherDB(test.BaseTestCase):
|
||||
|
||||
with mock.patch.object(self.dispatcher.storage_conn,
|
||||
'record_metering_data') as record_metering_data:
|
||||
self.dispatcher.record_metering_data(self.ctx, msg)
|
||||
self.dispatcher.record_metering_data(msg)
|
||||
|
||||
record_metering_data.assert_called_once_with(expected)
|
||||
|
||||
@ -107,6 +107,6 @@ class TestDispatcherDB(test.BaseTestCase):
|
||||
|
||||
with mock.patch.object(self.dispatcher.storage_conn,
|
||||
'record_metering_data') as record_metering_data:
|
||||
self.dispatcher.record_metering_data(self.ctx, msg)
|
||||
self.dispatcher.record_metering_data(msg)
|
||||
|
||||
record_metering_data.assert_called_once_with(expected)
|
||||
|
@ -59,7 +59,7 @@ class TestDispatcherFile(test.BaseTestCase):
|
||||
)
|
||||
|
||||
# The record_metering_data method should exist and not produce errors.
|
||||
dispatcher.record_metering_data(None, msg)
|
||||
dispatcher.record_metering_data(msg)
|
||||
# After the method call above, the file should have been created.
|
||||
self.assertTrue(os.path.exists(handler.baseFilename))
|
||||
|
||||
@ -91,7 +91,7 @@ class TestDispatcherFile(test.BaseTestCase):
|
||||
)
|
||||
|
||||
# The record_metering_data method should exist and not produce errors.
|
||||
dispatcher.record_metering_data(None, msg)
|
||||
dispatcher.record_metering_data(msg)
|
||||
# After the method call above, the file should have been created.
|
||||
self.assertTrue(os.path.exists(handler.baseFilename))
|
||||
|
||||
|
@ -77,7 +77,6 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
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):
|
||||
@ -102,7 +101,6 @@ 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):
|
||||
@ -129,7 +127,6 @@ class TestCollector(tests_base.BaseTestCase):
|
||||
self._verify_udp_socket(udp_socket)
|
||||
|
||||
mock_dispatcher.record_metering_data.assert_called_once_with(
|
||||
None,
|
||||
self.counter)
|
||||
|
||||
@staticmethod
|
||||
|
Loading…
Reference in New Issue
Block a user