From e3acc106e9377895fcbe761ccaa1399367ea58ca Mon Sep 17 00:00:00 2001 From: Gordon Chung Date: Mon, 15 Jul 2013 09:44:08 -0400 Subject: [PATCH] make publisher procedure call configurable allow configurable publisher to cast to procedure other than record_metering_data Change-Id: I69d0ba99b4f31b293e4d372dd85b663bc60042ff --- ceilometer/publisher/rpc.py | 5 +++-- tests/publisher/test_rpc_publisher.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ceilometer/publisher/rpc.py b/ceilometer/publisher/rpc.py index 25001b027..2b26676a4 100644 --- a/ceilometer/publisher/rpc.py +++ b/ceilometer/publisher/rpc.py @@ -110,6 +110,7 @@ class RPCPublisher(publisher.PublisherBase): options = urlparse.parse_qs(parsed_url.query) self.per_meter_topic = bool(int( options.get('per_meter_topic', [0])[-1])) + self.target = options.get('target', ['record_metering_data'])[0] def publish_counters(self, context, counters, source): """Publish counters on RPC. @@ -130,7 +131,7 @@ class RPCPublisher(publisher.PublisherBase): topic = cfg.CONF.publisher_rpc.metering_topic msg = { - 'method': 'record_metering_data', + 'method': self.target, 'version': '1.0', 'args': {'data': meters}, } @@ -143,7 +144,7 @@ class RPCPublisher(publisher.PublisherBase): sorted(meters, key=operator.itemgetter('counter_name')), operator.itemgetter('counter_name')): msg = { - 'method': 'record_metering_data', + 'method': self.target, 'version': '1.0', 'args': {'data': list(meter_list)}, } diff --git a/tests/publisher/test_rpc_publisher.py b/tests/publisher/test_rpc_publisher.py index a6c47ad04..799df67a1 100644 --- a/tests/publisher/test_rpc_publisher.py +++ b/tests/publisher/test_rpc_publisher.py @@ -221,6 +221,21 @@ class TestPublish(base.TestCase): 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'], + '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): publisher = rpc.RPCPublisher(