def test__run(self, logging_mock, eventlet_mock): server = wsgi.Server('test') server._run("app", "socket") eventlet_mock.wsgi.server.assert_called_once_with( 'socket', 'app', max_size=server.num_threads, log=mock.ANY, keepalive=CONF.wsgi_keep_alive, socket_timeout=server.client_socket_timeout ) self.assertTrue(len(logging_mock.mock_calls))
def test_start_multiple_workers(self, ProcessLauncher): launcher = ProcessLauncher.return_value server = wsgi.Server("test_multiple_processes") server.start(None, 0, host="127.0.0.1", workers=2) launcher.launch_service.assert_called_once_with(mock.ANY, workers=2) server.stop() launcher.stop.assert_called_once_with() server.wait() launcher.wait.assert_called_once_with()
def test__run(self, eventlet_mock): server = wsgi.Server('test') server._run("app", "socket") eventlet_mock.wsgi.server.assert_called_once_with( 'socket', 'app', max_size=server.num_threads, log=mock.ANY, keepalive=CONF.wsgi_keep_alive, log_format=CONF.wsgi_log_format, socket_timeout=server.client_socket_timeout, debug=False, )
def _run_wsgi(app_name): app = config.load_paste_app(app_name) if not app: LOG.error(_('No known API applications configured.')) return server = wsgi.Server("Neutron") server.start(app, cfg.CONF.bind_port, cfg.CONF.bind_host) # Dump all option values here after all options are parsed cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) LOG.info(_("Neutron service started, listening on %(host)s:%(port)s"), {'host': cfg.CONF.bind_host, 'port': cfg.CONF.bind_port}) return server
def _run_wsgi(app_name): app = config.load_paste_app(app_name) if not app: LOG.error(_LE('No known API applications configured.')) return server = wsgi.Server("Neutron") server.start(app, cfg.CONF.bind_port, cfg.CONF.bind_host, workers=_get_api_workers()) LOG.info(_LI("Neutron service started, listening on %(host)s:%(port)s"), { 'host': cfg.CONF.bind_host, 'port': cfg.CONF.bind_port }) return server
def _test_wrap_ssl(self, exists_mock, wrap_socket_mock, **kwargs): exists_mock.return_value = True sock = mock.Mock() CONF.set_default("ssl_cert_file", 'certificate.crt') CONF.set_default("ssl_key_file", 'privatekey.key') ssl_kwargs = {'server_side': True, 'certfile': CONF.ssl_cert_file, 'keyfile': CONF.ssl_key_file, 'cert_reqs': ssl.CERT_NONE, } if kwargs: ssl_kwargs.update(**kwargs) server = wsgi.Server("test_app") server.wrap_ssl(sock) wrap_socket_mock.assert_called_once_with(sock, **ssl_kwargs)
def _run_wsgi(self, workers=1): """Start WSGI server with a test application.""" # Mock start method to check that children are started again on # receiving SIGHUP. with mock.patch("neutron.wsgi.WorkerService.start") as start_method: start_method.side_effect = self._fake_start server = wsgi.Server("Test") server.start(self.application, 0, "0.0.0.0", workers=workers) # Memorize a port that was chosen for the service self.port = server.port os.write(self.pipeout, bytes(self.port)) server.wait()
def main(): cfg.CONF.register_opts(metadata_conf.METADATA_PROXY_HANDLER_OPTS) cfg.CONF.register_opts(common_params.DF_OPTS, 'df') cfg.CONF.register_opts(metadata_service_app.DF_METADATA_OPTS, 'df_metadata') config.init(sys.argv[1:]) config.setup_logging() environment_setup() service = wsgi.Server('dragonflow-metadata-service', disable_ssl=True) service.start( metadata_service_app.DFMetadataProxyHandler(cfg.CONF), host=cfg.CONF.df_metadata.ip, port=cfg.CONF.df_metadata.port, ) service.wait() environment_destroy()
def main(): metadata_conf.register_meta_conf_opts( metadata_conf.METADATA_PROXY_HANDLER_OPTS) config.init(sys.argv[1:]) config.setup_logging() nb_api = api_nb.NbApi.get_instance() service_instance = metadata_service.DFMetadataProxyHandler( cfg.CONF, nb_api) df_service.register_service('df-metadata-service', nb_api) service = wsgi.Server('dragonflow-metadata-service', disable_ssl=True) service.start( service_instance, host=cfg.CONF.df_metadata.ip, port=cfg.CONF.df_metadata.port, ) service.wait()
def _run_wsgi(self, workers=0): """Start WSGI server with a test application.""" # Mock reset method to check that it is being called # on receiving SIGHUP. with mock.patch("neutron.wsgi.WorkerService.reset") as reset_method: reset_method.side_effect = self._fake_reset server = wsgi.Server("Test") server.start(self.application, 0, "0.0.0.0", workers=workers) # Memorize a port that was chosen for the service self.port = server.port os.write(self.pipeout, str(self.port)) server.wait()
def test_app_using_ssl_combined_cert_and_key(self): CONF.set_default('use_ssl', True) CONF.set_default("ssl_cert_file", os.path.join(TEST_VAR_DIR, 'certandkey.pem')) greetings = 'Hello, World!!!' @webob.dec.wsgify def hello_world(req): return greetings server = wsgi.Server("test_app") server.start(hello_world, 0, host="127.0.0.1") response = urllib2.urlopen('https://127.0.0.1:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop()
def test_app(self): greetings = 'Hello, World!!!' def hello_world(env, start_response): if env['PATH_INFO'] != '/': start_response('404 Not Found', [('Content-Type', 'text/plain')]) return ['Not Found\r\n'] start_response('200 OK', [('Content-Type', 'text/plain')]) return [greetings] server = wsgi.Server("test_app") server.start(hello_world, 0, host="127.0.0.1") response = urllib2.urlopen('http://127.0.0.1:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop()
def main(): metadata_conf.register_meta_conf_opts( metadata_conf.METADATA_PROXY_HANDLER_OPTS) config.init(sys.argv[1:]) config.setup_logging() environment_setup() cfg.CONF.set_override('enable_df_pub_sub', False, group='df') nb_api = api_nb.NbApi.get_instance(False) service_instance = metadata_service.DFMetadataProxyHandler( cfg.CONF, nb_api) df_service.register_service('df-metadata-service', nb_api, service_instance) service = wsgi.Server('dragonflow-metadata-service', disable_ssl=True) service.start( service_instance, host=cfg.CONF.df_metadata.ip, port=cfg.CONF.df_metadata.port, ) service.wait() environment_destroy()
def test_app_using_ipv6_and_ssl(self): CONF.set_default('use_ssl', True) CONF.set_default("ssl_cert_file", os.path.join(TEST_VAR_DIR, 'certificate.crt')) CONF.set_default("ssl_key_file", os.path.join(TEST_VAR_DIR, 'privatekey.key')) greetings = 'Hello, World!!!' @webob.dec.wsgify def hello_world(req): return greetings server = wsgi.Server("test_app") server.start(hello_world, 0, host="::1") response = urllib2.urlopen('https://[::1]:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop()
def test_disable_ssl(self): CONF.set_default('use_ssl', True) greetings = 'Hello, World!!!' def hello_world(env, start_response): if env['PATH_INFO'] != '/': start_response('404 Not Found', [('Content-Type', 'text/plain')]) return ['Not Found\r\n'] start_response('200 OK', [('Content-Type', 'text/plain')]) return [greetings] server = wsgi.Server("test_app", disable_ssl=True) server.start(hello_world, 0, host="127.0.0.1") response = open_no_proxy('http://127.0.0.1:%d/' % server.port) self.assertEqual(greetings.encode('utf-8'), response.read()) server.stop()
def test_ipv6_listen_called_with_scope(self): server = wsgi.Server("test_app") with mock.patch.object(wsgi.eventlet, 'listen') as mock_listen: with mock.patch.object(socket, 'getaddrinfo') as mock_get_addr: mock_get_addr.return_value = [ (socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP, '', ('fe80::204:acff:fe96:da87%eth0', 1234, 0, 2)) ] with mock.patch.object(server, 'pool') as mock_pool: server.start(None, 1234, host="fe80::204:acff:fe96:da87%eth0") mock_get_addr.assert_called_once_with( "fe80::204:acff:fe96:da87%eth0", 1234, socket.AF_UNSPEC, socket.SOCK_STREAM ) mock_listen.assert_called_once_with( ('fe80::204:acff:fe96:da87%eth0', 1234, 0, 2), family=socket.AF_INET6, backlog=cfg.CONF.backlog ) mock_pool.spawn.assert_has_calls([ mock.call( server._run, None, mock_listen.return_value.dup.return_value) ])
def run(self): handler = NetworkMetadataProxyHandler(self.network_id, self.router_id) proxy = wsgi.Server('neutron-network-metadata-proxy') proxy.start(handler, self.port) proxy.wait()
def test_start_random_port(self): server = wsgi.Server("test_random_port") server.start(None, 0, host="127.0.0.1") self.assertNotEqual(0, server.port) server.stop() server.wait()