def apply_config(self, config): super(WebServiceInterface, self).apply_config(config) self.http_port = config.get('port') self.pool_size = config.get('wsgi_pool_size') if not self.http_port: self.uses_static_port = False self.http_port = sockets.get_unused_port()
def get_shared_socket_fd(self, port): try: return self.__shared_sockets[port].fileno() except KeyError: host_port = get_unused_port() sock = create_socket('127.0.0.1:%s' % host_port, inheritable=True) self.__shared_sockets[port] = sock return sock.fileno()
def setUp(self): # XXX(Mouad): Gevent master fail n python3 with: name 'dup' is not defined. # A workaround is to mock lymph.utils.sockets.create_socket to return # a dummy socket for us. port = get_unused_port() sock = create_socket('127.0.0.1:%s' % port, inheritable=True) with mock.patch('lymph.utils.sockets.create_socket', return_value=sock): super(WebServiceTestCase, self).setUp()
def apply_config(self, config): super(WebServiceInterface, self).apply_config(config) self.http_port = config.get('port') self.pool_size = config.get('wsgi_pool_size') if not self.http_port: self.uses_static_port = False self.http_port = sockets.get_unused_port() if config.get('healthcheck.enabled', True): endpoint = config.get('healthcheck.endpoint', '/_health/') self.url_map.add(Rule(endpoint, endpoint='get_health_check_response'))
def apply_config(self, config): super(WebServiceInterface, self).apply_config(config) self.http_port = config.get("port") self.pool_size = config.get("wsgi_pool_size") self.request_trace_id_header = config.get("tracing.request_header") self.response_trace_id_header = config.get("tracing.response_header", "X-Trace-Id") if not self.http_port: self.uses_static_port = False self.http_port = sockets.get_unused_port() if config.get("healthcheck.enabled", True): endpoint = config.get("healthcheck.endpoint", "/_health/") self.url_map.add(Rule(endpoint, endpoint="get_health_check_response"))
def apply_config(self, config): super(WebServiceInterface, self).apply_config(config) self.http_port = config.get('port') self.pool_size = config.get('wsgi_pool_size') self.request_trace_id_header = config.get('tracing.request_header') self.response_trace_id_header = config.get('tracing.response_header', 'X-Trace-Id') def get_trace_id_from_request(): if self.request_trace_id_header is not None: trace.set_id(flask_current_request.get(self.request_trace_id_header)) def set_trace_id_to_response(response): response.headers[self.response_trace_id_header] = trace.get_id() return response self.application.before_request(get_trace_id_from_request) self.application.after_request(set_trace_id_to_response) if not self.http_port: self.uses_static_port = False self.http_port = sockets.get_unused_port()
def _start_backdoor_terminal(self): # XXX(Mouad): Imported here since this is still broken in Python3.x from gevent.backdoor import BackdoorServer try: ip = self.config.get_raw('debug.backdoor_ip') except KeyError: ip = '127.0.0.1' port = get_unused_port() endpoint = '%s:%s' % (ip, port) banner = "Welcome to backdoor Terminal of %s" % self.container.service_name backdoor = BackdoorServer( endpoint, locals={'container': self.container, 'dump_stacks': dump_stacks}, banner=banner) gevent.spawn(backdoor.serve_forever) self.container.backdoor_endpoint = endpoint
def apply_config(self, config): super(WebServiceInterface, self).apply_config(config) self.http_port = config.get('port', self.default_http_port) self.pool_size = config.get('wsgi_pool_size') if self.http_port is None: self.http_port = sockets.get_unused_port()