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 <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-02-25 17:44:53 +01:00
parent 1d44a182cb
commit d066837415
2 changed files with 35 additions and 8 deletions

View File

@ -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))])

View File

@ -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)