Merge "send-counter: fix & test"

This commit is contained in:
Jenkins 2013-03-03 23:55:00 +00:00 committed by Gerrit Code Review
commit 2fa5e50f3d
2 changed files with 35 additions and 8 deletions

View File

@ -24,9 +24,11 @@ import logging
import sys import sys
from oslo.config import cfg from oslo.config import cfg
from stevedore import dispatch
from ceilometer import counter 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 timeutils
from ceilometer.openstack.common import context from ceilometer.openstack.common import context
@ -68,7 +70,7 @@ cfg.CONF.register_cli_opts([
help='counter metadata'), help='counter metadata'),
]) ])
cfg.CONF(sys.argv[1:]) service.prepare_service(sys.argv)
# Set up logging to use the console # Set up logging to use the console
console = logging.StreamHandler(sys.stderr) console = logging.StreamHandler(sys.stderr)
@ -79,8 +81,15 @@ root_logger = logging.getLogger('')
root_logger.addHandler(console) root_logger.addHandler(console)
root_logger.setLevel(logging.DEBUG) root_logger.setLevel(logging.DEBUG)
publish.publish_counter(context.get_admin_context(), publish_manager = dispatch.NameDispatchExtensionManager(
counter.Counter(name=cfg.CONF.counter_name, 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, type=cfg.CONF.counter_type,
unit=cfg.CONF.counter_unit, unit=cfg.CONF.counter_unit,
volume=cfg.CONF.counter_volume, volume=cfg.CONF.counter_volume,
@ -89,7 +98,4 @@ publish.publish_counter(context.get_admin_context(),
resource_id=cfg.CONF.counter_resource, resource_id=cfg.CONF.counter_resource,
timestamp=cfg.CONF.counter_timestamp, timestamp=cfg.CONF.counter_timestamp,
resource_metadata=cfg.CONF.counter_metadata resource_metadata=cfg.CONF.counter_metadata
and eval(cfg.CONF.counter_metadata)), and eval(cfg.CONF.counter_metadata))])
cfg.CONF.metering_topic,
cfg.CONF.metering_secret,
cfg.CONF.counter_source)

View File

@ -37,3 +37,24 @@ class BinDbsyncTestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
os.unlink(self.tempfile) 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)