From d0668374153d630995a1df31581550981939a169 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 25 Feb 2013 17:44:53 +0100 Subject: [PATCH] send-counter: fix & test This fixes the bin/ceilometer-send-counter program that has been broken after the implementation of multi-publisher. We also add a test to see if it runs! This fixes bug #1133226 Change-Id: I922c7a000e942ee28d840f4cd65d13898d6d23a8 Signed-off-by: Julien Danjou --- bin/ceilometer-send-counter | 22 ++++++++++++++-------- tests/test_bin.py | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/bin/ceilometer-send-counter b/bin/ceilometer-send-counter index 76f36cdcb1..6349cfdec7 100755 --- a/bin/ceilometer-send-counter +++ b/bin/ceilometer-send-counter @@ -24,9 +24,11 @@ import logging import sys from oslo.config import cfg +from stevedore import dispatch from ceilometer import counter -from ceilometer import publish +from ceilometer import pipeline +from ceilometer import service from ceilometer.openstack.common import timeutils from ceilometer.openstack.common import context @@ -68,7 +70,7 @@ cfg.CONF.register_cli_opts([ help='counter metadata'), ]) -cfg.CONF(sys.argv[1:]) +service.prepare_service(sys.argv) # Set up logging to use the console console = logging.StreamHandler(sys.stderr) @@ -79,8 +81,15 @@ root_logger = logging.getLogger('') root_logger.addHandler(console) root_logger.setLevel(logging.DEBUG) -publish.publish_counter(context.get_admin_context(), - counter.Counter(name=cfg.CONF.counter_name, +publish_manager = dispatch.NameDispatchExtensionManager( + namespace=pipeline.PUBLISHER_NAMESPACE, + check_func=lambda x: True, + invoke_on_load=True) +pipeline_manager = pipeline.setup_pipeline(publish_manager) + +with pipeline_manager.publisher(context.get_admin_context(), + cfg.CONF.counter_source) as p: + p([counter.Counter(name=cfg.CONF.counter_name, type=cfg.CONF.counter_type, unit=cfg.CONF.counter_unit, volume=cfg.CONF.counter_volume, @@ -89,7 +98,4 @@ publish.publish_counter(context.get_admin_context(), resource_id=cfg.CONF.counter_resource, timestamp=cfg.CONF.counter_timestamp, resource_metadata=cfg.CONF.counter_metadata - and eval(cfg.CONF.counter_metadata)), - cfg.CONF.metering_topic, - cfg.CONF.metering_secret, - cfg.CONF.counter_source) + and eval(cfg.CONF.counter_metadata))]) diff --git a/tests/test_bin.py b/tests/test_bin.py index 35a99c973e..240c5435c4 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -37,3 +37,24 @@ class BinDbsyncTestCase(unittest.TestCase): def tearDown(self): os.unlink(self.tempfile) + + +class BinSendCounterTestCase(unittest.TestCase): + def setUp(self): + self.tempfile = tempfile.mktemp() + with open(self.tempfile, 'w') as tmp: + tmp.write("[DEFAULT]\n") + tmp.write( + "rpc_backend=ceilometer.openstack.common.rpc.impl_fake\n") + tmp.write( + "pipeline_cfg_file=../etc/ceilometer/pipeline.yaml\n") + + def test_send_counter_run(self): + subp = subprocess.Popen(["../bin/ceilometer-send-counter", + "--config-file=%s" % self.tempfile, + "--counter-resource=someuuid", + "--counter-name=mycounter"]) + self.assertEqual(subp.wait(), 0) + + def tearDown(self): + os.unlink(self.tempfile)