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']
|
sample['counter_type'] = sample['type']
|
||||||
LOG.debug("UDP: Storing %s", str(sample))
|
LOG.debug("UDP: Storing %s", str(sample))
|
||||||
self.dispatcher_manager.map_method('record_metering_data',
|
self.dispatcher_manager.map_method('record_metering_data',
|
||||||
None,
|
|
||||||
sample)
|
sample)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception(_("UDP: Unable to store meter"))
|
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.
|
RPC publisher, this method receives them for processing.
|
||||||
"""
|
"""
|
||||||
self.dispatcher_manager.map_method('record_metering_data',
|
self.dispatcher_manager.map_method('record_metering_data',
|
||||||
context=context,
|
|
||||||
data=data)
|
data=data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class Base(object):
|
|||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def record_metering_data(self, context, data):
|
def record_metering_data(self, data):
|
||||||
"""Recording metering data interface."""
|
"""Recording metering data interface."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
@ -40,7 +40,7 @@ class DatabaseDispatcher(dispatcher.Base):
|
|||||||
super(DatabaseDispatcher, self).__init__(conf)
|
super(DatabaseDispatcher, self).__init__(conf)
|
||||||
self.storage_conn = storage.get_connection(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
|
# We may have receive only one counter on the wire
|
||||||
if not isinstance(data, list):
|
if not isinstance(data, list):
|
||||||
data = [data]
|
data = [data]
|
||||||
|
@ -78,7 +78,7 @@ class FileDispatcher(dispatcher.Base):
|
|||||||
dispatcher_logger.addHandler(rfh)
|
dispatcher_logger.addHandler(rfh)
|
||||||
self.log = dispatcher_logger
|
self.log = dispatcher_logger
|
||||||
|
|
||||||
def record_metering_data(self, context, data):
|
def record_metering_data(self, data):
|
||||||
if self.log:
|
if self.log:
|
||||||
self.log.info(data)
|
self.log.info(data)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class TestDispatcherDB(test.BaseTestCase):
|
|||||||
|
|
||||||
with mock.patch.object(self.dispatcher.storage_conn,
|
with mock.patch.object(self.dispatcher.storage_conn,
|
||||||
'record_metering_data') as record_metering_data:
|
'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)
|
record_metering_data.assert_called_once_with(msg)
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class TestDispatcherDB(test.BaseTestCase):
|
|||||||
|
|
||||||
self.dispatcher.storage_conn = ErrorConnection()
|
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, \
|
assert not self.dispatcher.storage_conn.called, \
|
||||||
'Should not have called the storage connection'
|
'Should not have called the storage connection'
|
||||||
@ -86,7 +86,7 @@ class TestDispatcherDB(test.BaseTestCase):
|
|||||||
|
|
||||||
with mock.patch.object(self.dispatcher.storage_conn,
|
with mock.patch.object(self.dispatcher.storage_conn,
|
||||||
'record_metering_data') as record_metering_data:
|
'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)
|
record_metering_data.assert_called_once_with(expected)
|
||||||
|
|
||||||
@ -107,6 +107,6 @@ class TestDispatcherDB(test.BaseTestCase):
|
|||||||
|
|
||||||
with mock.patch.object(self.dispatcher.storage_conn,
|
with mock.patch.object(self.dispatcher.storage_conn,
|
||||||
'record_metering_data') as record_metering_data:
|
'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)
|
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.
|
# 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.
|
# After the method call above, the file should have been created.
|
||||||
self.assertTrue(os.path.exists(handler.baseFilename))
|
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.
|
# 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.
|
# After the method call above, the file should have been created.
|
||||||
self.assertTrue(os.path.exists(handler.baseFilename))
|
self.assertTrue(os.path.exists(handler.baseFilename))
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ class TestCollector(tests_base.BaseTestCase):
|
|||||||
self.srv.record_metering_data(None, self.counter)
|
self.srv.record_metering_data(None, self.counter)
|
||||||
|
|
||||||
mock_dispatcher.record_metering_data.assert_called_once_with(
|
mock_dispatcher.record_metering_data.assert_called_once_with(
|
||||||
context=None,
|
|
||||||
data=self.counter)
|
data=self.counter)
|
||||||
|
|
||||||
def test_udp_receive(self):
|
def test_udp_receive(self):
|
||||||
@ -102,7 +101,6 @@ 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):
|
||||||
@ -129,7 +127,6 @@ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user