Esempio n. 1
0
def setup_sahara_engine():
    periodic.setup()

    engine = _get_infrastructure_engine()
    service_ops.setup_ops(engine)

    remote_driver = _get_remote_driver()
    remote.setup_remote(remote_driver, engine)
Esempio n. 2
0
    def test_setup_disabled(self, mock_conf, mock_thread_group):
        mock_conf.periodic_enable = False

        add_timer = mock_thread_group.ThreadGroup().add_dynamic_timer

        p.setup()

        self.assertFalse(add_timer._mock_called)
Esempio n. 3
0
    def test_setup_enabled(self, mock_conf, mock_thread_group):
        mock_conf.periodic_enable = True
        mock_conf.periodic_fuzzy_delay = 20
        mock_conf.periodic_interval_max = 30

        add_timer = mock_thread_group.ThreadGroup().add_dynamic_timer

        p.setup()

        self.assertTrue(add_timer._mock_called)
Esempio n. 4
0
def setup_sahara_api(app, mode):
    periodic.setup(app)

    #TODO(dmitryme): move periodics to engine, until then the remote
    # initialization here is a temporal hack
    remote_driver = _get_remote_driver()
    remote.setup_remote(remote_driver, None)

    ops = _get_ops_driver(mode)
    service_api.setup_service_api(ops)
    edp_api.setup_edp_api(ops)
Esempio n. 5
0
    def test_setup_enabled(self, mock_conf, mock_thread_group):
        mock_conf.periodic_enable = True
        mock_conf.periodic_fuzzy_delay = 20
        mock_conf.periodic_interval_max = 30
        mock_conf.periodic_workers_number = 1
        mock_conf.periodic_coordinator_backend_url = ''

        add_timer = mock_thread_group.ThreadGroup().add_dynamic_timer

        p.setup()

        self.assertTrue(add_timer._mock_called)
Esempio n. 6
0
    def test_setup_enabled(self, mock_conf, mock_thread_group):
        mock_conf.periodic_enable = True
        mock_conf.periodic_fuzzy_delay = 20
        mock_conf.periodic_interval_max = 30
        mock_conf.periodic_workers_number = 1
        mock_conf.periodic_coordinator_backend_url = ''

        add_timer = mock_thread_group.ThreadGroup().add_dynamic_timer

        p.setup()

        self.assertTrue(add_timer._mock_called)
Esempio n. 7
0
def make_app():
    """App builder (wsgi)

    Entry point for Sahara REST API server
    """
    app = flask.Flask('sahara.api')

    @app.route('/', methods=['GET'])
    def version_list():
        context.set_ctx(None)
        return api_utils.render({
            "versions": [
                {"id": "v1.0", "status": "CURRENT"}
            ]
        })

    @app.teardown_request
    def teardown_request(_ex=None):
        context.set_ctx(None)

    app.register_blueprint(api_v10.rest, url_prefix='/v1.0')
    app.register_blueprint(api_v10.rest, url_prefix='/v1.1')
    app.register_blueprint(api_v11.rest, url_prefix='/v1.1')

    plugins_base.setup_plugins()
    periodic.setup(app)

    engine = _get_infrastructure_engine()
    service_api.setup_service_api(engine)

    remote_driver = _get_remote_driver()
    remote.setup_remote(remote_driver, engine)

    def make_json_error(ex):
        status_code = (ex.code
                       if isinstance(ex, werkzeug_exceptions.HTTPException)
                       else 500)
        description = (ex.description
                       if isinstance(ex, werkzeug_exceptions.HTTPException)
                       else str(ex))
        return api_utils.render({'error': status_code,
                                 'error_message': description},
                                status=status_code)

    for code in six.iterkeys(werkzeug_exceptions.default_exceptions):
        app.error_handler_spec[None][code] = make_json_error

    if CONF.debug and not CONF.log_exchange:
        LOG.debug('Logging of request/response exchange could be enabled using'
                  ' flag --log-exchange')

    if CONF.log_exchange:
        cfg = app.config
        app.wsgi_app = log_exchange.LogExchange.factory(cfg)(app.wsgi_app)

    app.wsgi_app = auth_valid.filter_factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name
    )(app.wsgi_app)

    return app
Esempio n. 8
0
def make_app():
    """App builder (wsgi)

    Entry point for Sahara REST API server
    """
    app = flask.Flask('sahara.api')

    @app.route('/', methods=['GET'])
    def version_list():
        context.set_ctx(None)
        return api_utils.render(
            {"versions": [{
                "id": "v1.0",
                "status": "CURRENT"
            }]})

    @app.teardown_request
    def teardown_request(_ex=None):
        context.set_ctx(None)

    app.register_blueprint(api_v10.rest, url_prefix='/v1.0')
    app.register_blueprint(api_v10.rest, url_prefix='/v1.1')
    app.register_blueprint(api_v11.rest, url_prefix='/v1.1')

    plugins_base.setup_plugins()
    periodic.setup(app)

    engine = _get_infrastructure_engine()
    service_api.setup_service_api(engine)

    remote_driver = _get_remote_driver()
    remote.setup_remote(remote_driver, engine)

    def make_json_error(ex):
        status_code = (ex.code if isinstance(
            ex, werkzeug_exceptions.HTTPException) else 500)
        description = (ex.description if isinstance(
            ex, werkzeug_exceptions.HTTPException) else str(ex))
        return api_utils.render(
            {
                'error': status_code,
                'error_message': description
            },
            status=status_code)

    for code in six.iterkeys(werkzeug_exceptions.default_exceptions):
        app.error_handler_spec[None][code] = make_json_error

    if CONF.debug and not CONF.log_exchange:
        LOG.debug('Logging of request/response exchange could be enabled using'
                  ' flag --log-exchange')

    if CONF.log_exchange:
        cfg = app.config
        app.wsgi_app = log_exchange.LogExchange.factory(cfg)(app.wsgi_app)

    app.wsgi_app = auth_valid.filter_factory(app.config)(app.wsgi_app)

    app.wsgi_app = auth_token.filter_factory(
        app.config,
        auth_host=CONF.os_auth_host,
        auth_port=CONF.os_auth_port,
        auth_protocol=CONF.os_auth_protocol,
        admin_user=CONF.os_admin_username,
        admin_password=CONF.os_admin_password,
        admin_tenant_name=CONF.os_admin_tenant_name)(app.wsgi_app)

    return app