Allow no configured sources, provide a default file
This fixes bug #1073654 Change-Id: I7cfb5016ab8a70bf9738baa497f6fe173f307242 Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
415453bfe8
commit
445d711dd0
@ -37,13 +37,10 @@ if __name__ == '__main__':
|
||||
cfg.CONF(sys.argv[1:])
|
||||
logging.setup('ceilometer.api')
|
||||
|
||||
root = app.app
|
||||
root = app.make_app()
|
||||
|
||||
# Enable debug mode
|
||||
if cfg.CONF.verbose or cfg.CONF.debug:
|
||||
root.debug = True
|
||||
|
||||
# Install the middleware wrapper
|
||||
root = acl.install(root, cfg.CONF)
|
||||
|
||||
root.run(host='0.0.0.0', port=cfg.CONF.metering_api_port)
|
||||
|
@ -24,23 +24,36 @@ from ceilometer.openstack.common import cfg
|
||||
from ceilometer.openstack.common import jsonutils
|
||||
from ceilometer import storage
|
||||
from ceilometer.api import v1
|
||||
from ceilometer.api import acl
|
||||
|
||||
|
||||
app = flask.Flask('ceilometer.api')
|
||||
app.register_blueprint(v1.blueprint, url_prefix='/v1')
|
||||
|
||||
storage.register_opts(cfg.CONF)
|
||||
|
||||
|
||||
@app.before_request
|
||||
def attach_config():
|
||||
flask.request.cfg = cfg.CONF
|
||||
storage_engine = storage.get_engine(cfg.CONF)
|
||||
flask.request.storage_engine = storage_engine
|
||||
flask.request.storage_conn = storage_engine.get_connection(cfg.CONF)
|
||||
def make_app(enable_acl=True, attach_storage=True):
|
||||
app = flask.Flask('ceilometer.api')
|
||||
app.register_blueprint(v1.blueprint, url_prefix='/v1')
|
||||
|
||||
try:
|
||||
with open("sources.json", "r") as f:
|
||||
sources = jsonutils.load(f)
|
||||
except IOError:
|
||||
sources = {}
|
||||
|
||||
@app.before_request
|
||||
def attach_sources():
|
||||
with open("sources.json", "r") as f:
|
||||
flask.request.sources = jsonutils.load(f)
|
||||
@app.before_request
|
||||
def attach_config():
|
||||
flask.request.cfg = cfg.CONF
|
||||
flask.request.sources = sources
|
||||
|
||||
if attach_storage:
|
||||
@app.before_request
|
||||
def attach_storage():
|
||||
storage_engine = storage.get_engine(cfg.CONF)
|
||||
flask.request.storage_engine = storage_engine
|
||||
flask.request.storage_conn = \
|
||||
storage_engine.get_connection(cfg.CONF)
|
||||
|
||||
# Install the middleware wrapper
|
||||
if enable_acl:
|
||||
return acl.install(app, cfg.CONF)
|
||||
return app
|
||||
|
@ -26,13 +26,14 @@ import flask
|
||||
from ceilometer.tests import db as db_test_base
|
||||
from ceilometer.api import v1
|
||||
from ceilometer.api import app
|
||||
from ceilometer.openstack.common import cfg
|
||||
|
||||
|
||||
class TestBase(db_test_base.TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBase, self).setUp()
|
||||
self.app = flask.Flask('test')
|
||||
self.app = app.make_app(enable_acl=False, attach_storage=False)
|
||||
self.app.register_blueprint(v1.blueprint)
|
||||
self.test_app = self.app.test_client()
|
||||
|
||||
@ -40,8 +41,6 @@ class TestBase(db_test_base.TestBase):
|
||||
def attach_storage_connection():
|
||||
flask.request.storage_conn = self.conn
|
||||
|
||||
self.app.before_request(app.attach_sources)
|
||||
|
||||
def get(self, path, **kwds):
|
||||
if kwds:
|
||||
query = path + '?' + urllib.urlencode(kwds)
|
||||
|
3
etc/ceilometer/sources.json
Normal file
3
etc/ceilometer/sources.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"openstack": {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user