Ejemplo n.º 1
0
def build_app(db=None):
    """
    Building routes and forming the root freezer-api app
    :param db: instance of elastic search db class if not freezer will try to
    initialize this instance itself
    :return: wsgi app
    """
    if not db:
        db = driver.get_db()
    # injecting FreezerContext & hooks
    middleware_list = [utils.FuncMiddleware(hook) for hook in
                       utils.before_hooks()]
    middleware_list.append(middleware.JSONTranslator())
    middleware_list.append(middleware.RequireJSON())
    app = falcon.API(middleware=middleware_list)

    for exception_class in freezer_api_exc.exception_handlers_catalog:
        app.add_error_handler(exception_class, exception_class.handle)

    endpoint_catalog = [
        ('/v1', v1.public_endpoints(db)),
        ('/', [('', versions.Resource())])
    ]
    for version_path, endpoints in endpoint_catalog:
        for route, resource in endpoints:
            app.add_route(version_path + route, resource)

    return app
Ejemplo n.º 2
0
def configure_app(app, db=None):
    """Build routes and exception handlers

    :param app: falcon WSGI app
    :param db: Database engine (ElasticSearch)
    :return:
    """
    if not db:
        db = driver.get_db()

    # setup freezer policy
    policy.setup_policy(CONF)

    for exception_class in freezer_api_exc.exception_handlers_catalog:
        app.add_error_handler(exception_class, exception_class.handle)

    endpoint_catalog = [
        ('/v1', v1.public_endpoints(db)),
        ('/', [('', versions.Resource())])
    ]
    for version_path, endpoints in endpoint_catalog:
        for route, resource in endpoints:
            app.add_route(version_path + route, resource)

    return app
Ejemplo n.º 3
0
def build_app_v2():
    """Building routes and forming the root freezer-api app
    This uses the 'middleware' named argument to specify middleware for falcon
    instead of the 'before' and 'after' hooks that were removed after 0.3.0
    (both approaches were available for versions 0.2.0 - 0.3.0)
    :return: falcon WSGI app
    """
    # injecting FreezerContext & hooks
    middleware_list = [
        utils.FuncMiddleware(hook) for hook in utils.before_hooks()
    ]
    middleware_list.append(middleware.RequireJSON())
    middleware_list.append(middleware.JSONTranslator())

    app = falcon.API(middleware=middleware_list)
    db = driver.get_db()

    # setup freezer policy
    policy.setup_policy(CONF)

    for exception_class in freezer_api_exc.exception_handlers_catalog:
        app.add_error_handler(exception_class, exception_class.handle)

    endpoint_catalog = [('', v2.public_endpoints(db))]
    for version_path, endpoints in endpoint_catalog:
        for route, resource in endpoints:
            app.add_route(version_path + route, resource)

    return app
Ejemplo n.º 4
0
def configure_app(app, db=None):
    """Build routes and exception handlers

    :param app: falcon WSGI app
    :param db: Database engine (ElasticSearch)
    :return:
    """
    if not db:
        db = driver.get_db()

    # setup freezer policy
    policy.setup_policy(CONF)

    for exception_class in freezer_api_exc.exception_handlers_catalog:
        app.add_error_handler(exception_class, exception_class.handle)

    endpoint_catalog = [('', v1.public_endpoints(db))]
    for version_path, endpoints in endpoint_catalog:
        for route, resource in endpoints:
            app.add_route(version_path + route, resource)

    return app
Ejemplo n.º 5
0
 def test_get_db_elastic(self, mock_logging, mock_elastic):
     driver.register_elk_opts()
     driver.get_db()
     self.assertTrue(mock_elastic.ElasticSearchEngine)
Ejemplo n.º 6
0
 def test_get_db_elastic(self, mock_logging, mock_elastic):
     db = driver.get_db()
     self.assertTrue(mock_elastic.ElasticSearchEngine)
Ejemplo n.º 7
0
    else:
        logging.warning(_i18n._LW("keystone authentication disabled"))

    app = middleware.HealthApp(app=app, path='/v1/health')

    return app

config_file = '/etc/freezer-api.conf'
config_files_list = [config_file] if os.path.isfile(config_file) else []
config.parse_args(args=[], default_config_files=config_files_list)
log.setup()
logging.info(_i18n._LI("Freezer API starting"))
logging.info(_i18n._LI("Freezer config file(s) used: %s")
             % ', '.join(cfg.CONF.config_file))
try:
    db = driver.get_db()
    application = get_application(db)
except Exception as err:
    message = _i18n._('Unable to start server: %s ') % err
    print(message)
    logging.fatal(message)
    sys.exit(1)


def main():
    # quick simple server for testing purposes or simple scenarios
    ip, port = '127.0.0.1', 9090
    if len(sys.argv) > 1:
        ip = sys.argv[1]
        if ':' in ip:
            ip, port = ip.split(':')
Ejemplo n.º 8
0
 def test_get_db_elastic(self, mock_logging):
     cfg.CONF.storage.db = 'elasticsearch'
     db = driver.get_db()
     self.assertIsInstance(db, elastic.ElasticSearchEngine)
Ejemplo n.º 9
0
 def test_get_db_elastic(self, monkeypatch):
     self.patch_logging(monkeypatch)
     cfg.CONF.storage.db = 'elasticsearch'
     db = driver.get_db()
     assert isinstance(db, elastic.ElasticSearchEngine)
Ejemplo n.º 10
0
 def test_get_db_simpledict(self, monkeypatch):
     self.patch_logging(monkeypatch)
     cfg.CONF.storage.db = 'simpledict'
     db = driver.get_db()
     assert isinstance(db, simpledict.SimpleDictStorageEngine)
Ejemplo n.º 11
0
 def test_get_db_elastic(self, monkeypatch):
     self.patch_logging(monkeypatch)
     cfg.CONF.storage.db = 'elasticsearch'
     db = driver.get_db()
     assert isinstance(db, elastic.ElasticSearchEngine)
Ejemplo n.º 12
0
 def test_get_db_simpledict(self, monkeypatch):
     self.patch_logging(monkeypatch)
     cfg.CONF.storage.db = 'simpledict'
     db = driver.get_db()
     assert isinstance(db, simpledict.SimpleDictStorageEngine)
Ejemplo n.º 13
0
    if 'keystone_authtoken' in config.CONF:
        app = auth_token.AuthProtocol(app, {})
    else:
        logging.warning("keystone authentication disabled")
    return app


config_file = '/etc/freezer-api.conf'
config_files_list = [config_file] if os.path.isfile(config_file) else []
config.parse_args(args=[], default_config_files=config_files_list)
log.setup()
logging.info("Freezer API starting")
logging.info("Freezer config file(s) used: {0}".format(', '.join(
    cfg.CONF.config_file)))
try:
    db = driver.get_db()
    application = get_application(db)
except Exception as err:
    message = 'Unable to start server: {0}'.format(err)
    print message
    logging.fatal(message)
    sys.exit(1)


def main():
    ip, port = '127.0.0.1', 9090
    httpd = simple_server.make_server(ip, port, application)
    message = 'Server listening on {0}:{1}'.format(ip, port)
    print message
    logging.info(message)
    try:
Ejemplo n.º 14
0
 def test_get_db_elastic(self, mock_LOG, mock_elastic, mock_get_db):
     mock_get_db.return_value = object()
     driver.register_storage_opts()
     driver.get_db()
     self.assertTrue(mock_elastic.ElasticSearchEngine)