make publisher procedure call configurable
allow configurable publisher to cast to procedure other than record_metering_data Change-Id: I69d0ba99b4f31b293e4d372dd85b663bc60042ff
This commit is contained in:
parent
30319310ed
commit
e3acc106e9
@ -110,6 +110,7 @@ class RPCPublisher(publisher.PublisherBase):
|
|||||||
options = urlparse.parse_qs(parsed_url.query)
|
options = urlparse.parse_qs(parsed_url.query)
|
||||||
self.per_meter_topic = bool(int(
|
self.per_meter_topic = bool(int(
|
||||||
options.get('per_meter_topic', [0])[-1]))
|
options.get('per_meter_topic', [0])[-1]))
|
||||||
|
self.target = options.get('target', ['record_metering_data'])[0]
|
||||||
|
|
||||||
def publish_counters(self, context, counters, source):
|
def publish_counters(self, context, counters, source):
|
||||||
"""Publish counters on RPC.
|
"""Publish counters on RPC.
|
||||||
@ -130,7 +131,7 @@ class RPCPublisher(publisher.PublisherBase):
|
|||||||
|
|
||||||
topic = cfg.CONF.publisher_rpc.metering_topic
|
topic = cfg.CONF.publisher_rpc.metering_topic
|
||||||
msg = {
|
msg = {
|
||||||
'method': 'record_metering_data',
|
'method': self.target,
|
||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'args': {'data': meters},
|
'args': {'data': meters},
|
||||||
}
|
}
|
||||||
@ -143,7 +144,7 @@ class RPCPublisher(publisher.PublisherBase):
|
|||||||
sorted(meters, key=operator.itemgetter('counter_name')),
|
sorted(meters, key=operator.itemgetter('counter_name')),
|
||||||
operator.itemgetter('counter_name')):
|
operator.itemgetter('counter_name')):
|
||||||
msg = {
|
msg = {
|
||||||
'method': 'record_metering_data',
|
'method': self.target,
|
||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'args': {'data': list(meter_list)},
|
'args': {'data': list(meter_list)},
|
||||||
}
|
}
|
||||||
|
@ -221,6 +221,21 @@ class TestPublish(base.TestCase):
|
|||||||
self.assertEqual(self.published[0][0],
|
self.assertEqual(self.published[0][0],
|
||||||
cfg.CONF.publisher_rpc.metering_topic)
|
cfg.CONF.publisher_rpc.metering_topic)
|
||||||
self.assertIsInstance(self.published[0][1]['args']['data'], list)
|
self.assertIsInstance(self.published[0][1]['args']['data'], list)
|
||||||
|
self.assertEqual(self.published[0][1]['method'],
|
||||||
|
'record_metering_data')
|
||||||
|
|
||||||
|
def test_publish_target(self):
|
||||||
|
publisher = rpc.RPCPublisher(
|
||||||
|
network_utils.urlsplit('rpc://?target=custom_procedure_call'))
|
||||||
|
publisher.publish_counters(None,
|
||||||
|
self.test_data,
|
||||||
|
'test')
|
||||||
|
self.assertEqual(len(self.published), 1)
|
||||||
|
self.assertEqual(self.published[0][0],
|
||||||
|
cfg.CONF.publisher_rpc.metering_topic)
|
||||||
|
self.assertIsInstance(self.published[0][1]['args']['data'], list)
|
||||||
|
self.assertEqual(self.published[0][1]['method'],
|
||||||
|
'custom_procedure_call')
|
||||||
|
|
||||||
def test_published_with_per_meter_topic(self):
|
def test_published_with_per_meter_topic(self):
|
||||||
publisher = rpc.RPCPublisher(
|
publisher = rpc.RPCPublisher(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user