Example #1
0
    def __init__(self):
        self.reject_response = HttpResponse()
        self.reject_response.status = '401 Unauthorized'
        self.reject_response.header('Content-Length').values.append('0')

        self.config = load_pyrox_config()

        self.redis = redis.StrictRedis(host=self.config.redis.host,
                                       port=self.config.redis.port,
                                       db=self.config.redis.db)

        self.admin_client = KeystoneClient(
            token=self.config.keystone.auth_token,
            timeout=self.config.keystone.timeout,
            endpoint=self.config.keystone.endpoint,
            insecure=self.config.keystone.insecure)
Example #2
0
def start_pyrox(other_cfg=None):
    config = load_pyrox_config(other_cfg) if other_cfg else load_pyrox_config()

    # Init logging
    logging_manager = get_log_manager()
    logging_manager.configure(config)

    # dst = config.routing.upstream_hosts
    # print("________ dst:{}".format(dst))
    # print("________ dst0/1:{0}/{1}".format(dst[0], dst[1]))

    _LOG.info('Upstream targets areeee: {}'.format(
        ['https://{0}:{1}'.format(dst[0], dst[1])
            for dst in config.routing.upstream_hosts]))

    # Set bind host
    bind_host = config.core.bind_host.split(':')
    if len(bind_host) != 2:
        raise ConfigurationError('bind_host must have a port specified')

    # Bind the sockets in the main process
    sockets = bind_sockets(port=bind_host[1], address=bind_host[0])

    # Bind the server port(s)
    _LOG.info('Pyrox listening on: http://{0}:{1}'.format(
        bind_host[0], bind_host[1]))

    # Start Tornado
    num_processes = config.core.processes

    if num_processes <= 0:
        num_processes = cpu_count()

    global _active_children_pids

    for i in range(num_processes):
        pid = os.fork()
        if pid == 0:
            print('Starting process {}'.format(i))
            start_proxy(sockets, config)
            sys.exit(0)
        else:
            _active_children_pids.append(pid)

    # Take over SIGTERM and SIGINT
    signal.signal(signal.SIGTERM, stop_parent)
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    while len(_active_children_pids):
        try:
            pid, status = os.wait()
        except OSError as oserr:
            if oserr.errno != errno.EINTR:
                _LOG.exception(oserr)
            continue
        except Exception as ex:
            _LOG.exception(ex)
            continue

        _LOG.info('Child process {} exited with status {}'.format(
            pid, status))
        _active_children_pids.remove(pid)
Example #3
0
def start_pyrox(cfg=None, cfg_location=None):
    config = cfg
    if config is None:
        config = load_pyrox_config(cfg_location)

    # Log some important things
    if config.routing.upstream_hosts is not None:
        _LOG.info('Upstream targets are: {}'.format(
            [dst for dst in config.routing.upstream_hosts]))

    # Set bind host
    bind_host = config.core.bind_host.split(':')
    if len(bind_host) != 2:
        raise ConfigurationError('bind_host must have a port specified')

    # Bind the sockets in the main process
    sockets = None

    try:
        sockets = bind_sockets(port=bind_host[1], address=bind_host[0])
    except Exception as ex:
        _LOG.exception(ex)
        return

    # Bind the server port(s)
    _LOG.info('Pyrox listening on: http://{0}:{1}'.format(
        bind_host[0], bind_host[1]))

    # Are we trying to profile Pyrox?
    if config.core.enable_profiling:
        _LOG.warning("""
**************************************************************************
Notice: Pyrox Profiling Mode Enabled

You have enabled Pyrox with profiling enabled in the Pyrox config. This
will restrict Pyrox to one resident process. It is not recommended that
you run Pyrox in production with this feature enabled.
**************************************************************************
""")
        start_proxy(sockets, config)
        return

    # Number of processess to spin
    num_processes = config.core.processes

    if num_processes <= 0:
        num_processes = cpu_count()

    global _active_children_pids

    for i in range(num_processes):
        pid = os.fork()
        if pid == 0:
            _LOG.info('Starting process {}'.format(i))
            start_proxy(sockets, config)
            sys.exit(0)
        else:
            _active_children_pids.append(pid)

    # Take over SIGTERM and SIGINT
    signal.signal(signal.SIGTERM, stop_parent)
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    while len(_active_children_pids):
        try:
            pid, status = os.wait()
        except OSError as oserr:
            if oserr.errno != errno.EINTR:
                _LOG.exception(oserr)
            continue
        except Exception as ex:
            _LOG.exception(ex)
            continue

        _LOG.info('Child process {} exited with status {}'.format(
            pid, status))
        _active_children_pids.remove(pid)
Example #4
0
 def setUp(self):
     self.cfg = load_pyrox_config('./examples/config/pyrox.conf')