Exemple #1
0
def launch_api_server(test_id, listen_ip, listen_port, http_server_port,
                      admin_port, conf_sections):
    kombu_mock = mock.Mock()
    kombu_patch = mock.patch('vnc_cfg_api_server.api_server.KombuAmqpClient')
    kombu_init_mock = kombu_patch.start()
    kombu_init_mock.side_effect = kombu_mock

    args_str = ""
    args_str = args_str + "--listen_ip_addr %s " % (listen_ip)
    args_str = args_str + "--listen_port %s " % (listen_port)
    args_str = args_str + "--http_server_port %s " % (http_server_port)
    args_str = args_str + "--admin_port %s " % (admin_port)

    args_str = args_str + "--cassandra_server_list 0.0.0.0:9160 "
    args_str = args_str + "--log_local "
    args_str = args_str + "--log_file api_server_%s.log " % (test_id)
    args_str = args_str + "--cluster_id %s " % (test_id)

    vnc_cgitb.enable(format='text')

    with tempfile.NamedTemporaryFile(mode='w+') as conf, \
         tempfile.NamedTemporaryFile(mode='w+') as logconf:
        cfg_parser = generate_conf_file_contents(conf_sections)
        cfg_parser.write(conf)
        conf.flush()

        cfg_parser = generate_logconf_file_contents()
        cfg_parser.write(logconf)
        logconf.flush()

        args_str = args_str + "--conf_file %s " % (conf.name)
        args_str = args_str + "--logging_conf %s " % (logconf.name)
        server = api_server.VncApiServer(args_str)
        gevent.getcurrent().api_server = server
        api_server.main(args_str, server)
Exemple #2
0
def get_apiserver():
    worker_id = int(uwsgi.worker_id())
    if worker_id > 0:
        vnc_api_server = api_server.VncApiServer(
            " -c /etc/contrail/contrail-api-%s.conf"
            " -c /etc/contrail/contrail-keystone-auth.conf" % (worker_id - 1))
    pipe_start_app = vnc_api_server.get_pipe_start_app()
    if pipe_start_app is None:
        pipe_start_app = vnc_api_server.api_bottle
    return pipe_start_app
def get_apiserver():
    worker_id = int(uwsgi.worker_id())
    if worker_id > 0:
        vnc_api_server = api_server.VncApiServer(
            " -c /etc/contrail/contrail-api-%s.conf"
            " -c /etc/contrail/contrail-keystone-auth.conf" % (worker_id - 1))

    pipe_start_app = vnc_api_server.get_pipe_start_app()
    if pipe_start_app is None:
        pipe_start_app = vnc_api_server.api_bottle

    @vnc_api_server.api_bottle.hook('before_request')
    def check_db_resync_status():
        try:
            if not vnc_api_server._db_conn._db_resync_done.isSet():
                err_msg = "Api server is Initializing:DB Resync in progress"
                raise bottle.HTTPError(503, err_msg)
        except AttributeError:
            err_msg = "Api server is Initializing:DB Resync in progress"
            raise bottle.HTTPError(503, err_msg)

    return pipe_start_app