Exemplo n.º 1
0
    def start(self):
        log.debug(
            'Starting rest api',
            host=self.config['host'],
            port=self.config['port'],
        )

        # WSGI expects an stdlib logger. With structlog there's conflict of
        # method names. Rest unhandled exception will be re-raised here:
        wsgi_log = logging.getLogger(__name__ + '.pywsgi')

        # server.stop() clears the handle and the pool, this is okay since a
        # new WSGIServer is created on each start
        pool = gevent.pool.Pool()
        wsgiserver = WSGIServer(
            (self.config['host'], self.config['port']),
            self.flask_app,
            log=wsgi_log,
            error_log=wsgi_log,
            spawn=pool,
        )

        try:
            wsgiserver.init_socket()
        except socket.error as e:
            if e.errno == errno.EADDRINUSE:
                raise APIServerPortInUseError()
            raise

        self.wsgiserver = wsgiserver

        log.debug('REST API started',
                  node=pex(self.rest_api.raiden_api.address))

        super().start()
Exemplo n.º 2
0
 def start(self, host='127.0.0.1', port=5001):
     try:
         # WSGI expects a stdlib logger, with structlog there's conflict of method names
         wsgi_log = logging.getLogger(__name__ + '.pywsgi')
         self.wsgiserver = WSGIServer(
             (host, port),
             self.flask_app,
             log=wsgi_log,
             error_log=wsgi_log,
         )
         self.wsgiserver.start()
     except socket.error as e:
         if e.errno == errno.EADDRINUSE:
             raise APIServerPortInUseError()
         raise
Exemplo n.º 3
0
def test_run_error_reporting(cli_runner, monkeypatch):
    caught_exceptions = {
        APIServerPortInUseError(): ReturnCode.PORT_ALREADY_IN_USE,
        ConfigurationError(): ReturnCode.RAIDEN_CONFIGURATION_ERROR,
        ConnectTimeout(): ReturnCode.GENERIC_COMMUNICATION_ERROR,
        ConnectionError(): ReturnCode.GENERIC_COMMUNICATION_ERROR,
        EthereumNonceTooLow(): ReturnCode.ETH_ACCOUNT_ERROR,
        EthNodeInterfaceError(): ReturnCode.ETH_INTERFACE_ERROR,
        KeystoreAuthenticationError(): ReturnCode.ETH_ACCOUNT_ERROR,
        KeystoreFileNotFound(): ReturnCode.ETH_ACCOUNT_ERROR,
        RaidenUnrecoverableError(): ReturnCode.FATAL,
        ReplacementTransactionUnderpriced(): ReturnCode.ETH_ACCOUNT_ERROR,
        RequestsConnectionError(): ReturnCode.GENERIC_COMMUNICATION_ERROR,
        Exception(): ReturnCode.FATAL,
    }

    for exception, code in caught_exceptions.items():
        monkeypatch.setattr(cli, "run_services", mock_raises(exception))
        result = cli_runner(cli.run, "--accept-disclaimer")
        assert result.exception.code == code
Exemplo n.º 4
0
    def start(self, host='127.0.0.1', port=5001):
        # WSGI expects an stdlib logger. With structlog there's conflict of
        # method names. Rest unhandled exception will be re-raised here:
        wsgi_log = logging.getLogger(__name__ + '.pywsgi')
        wsgiserver = WSGIServer(
            (host, port),
            self.flask_app,
            log=wsgi_log,
            error_log=wsgi_log,
        )

        try:
            wsgiserver.init_socket()
        except socket.error as e:
            if e.errno == errno.EADDRINUSE:
                raise APIServerPortInUseError()
            raise

        self.wsgiserver = wsgiserver
        super().start()
Exemplo n.º 5
0
 def _run(self, host='127.0.0.1', port=5001):
     try:
         # WSGI expects a stdlib logger, with structlog there's conflict of method names
         wsgi_log = logging.getLogger(__name__ + '.pywsgi')
         self.wsgiserver = WSGIServer(
             (host, port),
             self.flask_app,
             log=wsgi_log,
             error_log=wsgi_log,
         )
         # rest unhandled exception will be re-raised here:
         self.wsgiserver.serve_forever()
     except socket.error as e:
         if e.errno == errno.EADDRINUSE:
             raise APIServerPortInUseError()
         raise
     except gevent.GreenletExit:  # killed without exception
         raise  # re-raise to keep killed status
     except Exception:
         self.stop()  # ensure cleanup and wait on subtasks
         raise