Пример #1
0
 def setUp(self):
     super(TestClientRedirects, self).setUp()
     self.port_one = utils.get_unused_port()
     self.port_two = utils.get_unused_port()
     server_one = wsgi.Server()
     server_two = wsgi.Server()
     self.config(bind_host='127.0.0.1')
     self.config(workers=0)
     server_one.start(RedirectTestApp("one")(), self.port_one)
     server_two.start(RedirectTestApp("two")(), self.port_two)
     self.client = client.BaseClient("127.0.0.1", self.port_one)
Пример #2
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'xmonitor')
        notifier.set_defaults()

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "xmonitor", "registry",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
            osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
        else:
            osprofiler.web.disable()

        server = wsgi.Server()
        server.start(config.load_paste_app('xmonitor-registry'),
                     default_port=9191)
        server.wait()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
Пример #3
0
    def test_client_socket_timeout(self):
        CONF.set_default("workers", 0)
        CONF.set_default("client_socket_timeout", 0.1)
        """Verify connections are timed out as per 'client_socket_timeout'"""
        greetings = 'Hello, World!!!'

        def hello_world(env, start_response):
            start_response('200 OK', [('Content-Type', 'text/plain')])
            return [greetings]

        server = wsgi.Server()
        server.start(hello_world, 0)
        port = server.sock.getsockname()[1]

        def get_request(delay=0.0):
            sock = socket.socket()
            sock.connect(('127.0.0.1', port))
            time.sleep(delay)
            sock.send('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
            return sock.recv(1024)

        # Should succeed - no timeout
        self.assertIn(greetings, get_request())
        # Should fail - connection timed out so we get nothing from the server
        self.assertFalse(get_request(delay=0.2))
Пример #4
0
 def setUp(self):
     super(TestClientExceptions, self).setUp()
     self.port = utils.get_unused_port()
     server = wsgi.Server()
     self.config(bind_host='127.0.0.1')
     self.config(workers=0)
     server.start(ExceptionTestApp(), self.port)
     self.client = client.BaseClient("127.0.0.1", self.port)
Пример #5
0
    def test_number_of_workers(self):
        """Ensure the default number of workers matches num cpus."""
        def pid():
            i = 1
            while True:
                i = i + 1
                yield i

        with mock.patch.object(os, 'fork') as mock_fork:
            mock_fork.side_effect = pid
            server = wsgi.Server()
            server.configure = mock.Mock()
            fake_application = "fake-application"
            server.start(fake_application, None)
            self.assertEqual(processutils.get_worker_count(),
                             len(server.children))
Пример #6
0
    def test_http_keepalive(self, mock_configure_socket):
        self.config(http_keepalive=False)
        self.config(workers=0)

        server = wsgi.Server(threads=1)
        server.sock = 'fake_socket'
        # mocking eventlet.wsgi server method to check it is called with
        # configured 'http_keepalive' value.
        with mock.patch.object(eventlet.wsgi, 'server') as mock_server:
            fake_application = "fake-application"
            server.start(fake_application, 0)
            server.wait()
            mock_server.assert_called_once_with('fake_socket',
                                                fake_application,
                                                log=server._logger,
                                                debug=False,
                                                custom_pool=server.pool,
                                                keepalive=False,
                                                socket_timeout=900)
Пример #7
0
def main():
    config.parse_args()
    config.set_config_defaults()
    wsgi.set_eventlet_hub()
    logging.setup(CONF, 'xmonitor')
    notifier.set_defaults()
    if cfg.CONF.profiler.enabled:
        _notifier = osprofiler.notifier.create("Messaging", oslo_messaging, {},
                                               notifier.get_transport(),
                                               "xmonitor", "api",
                                               cfg.CONF.bind_host)
        osprofiler.notifier.set(_notifier)
        osprofiler.web.enable(cfg.CONF.profiler.hmac_keys)
    else:
        osprofiler.web.disable()

    server = wsgi.Server(initialize_glance_store=True)
    server.start(config.load_paste_app('xmonitor-api'), default_port=9696)
    server.wait()
Пример #8
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glare')

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "xmonitor", "artifacts",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)
        else:
            osprofiler.web.disable()

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glare-api'), default_port=9494)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
Пример #9
0
 def test_correct_configure_socket(self):
     mock_socket = mock.Mock()
     self.useFixture(
         fixtures.MonkeyPatch('xmonitor.common.wsgi.ssl.wrap_socket',
                              mock_socket))
     self.useFixture(
         fixtures.MonkeyPatch('xmonitor.common.wsgi.eventlet.listen',
                              lambda *x, **y: mock_socket))
     server = wsgi.Server()
     server.default_port = 1234
     server.configure_socket()
     self.assertIn(
         mock.call.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
         mock_socket.mock_calls)
     self.assertIn(
         mock.call.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
         mock_socket.mock_calls)
     if hasattr(socket, 'TCP_KEEPIDLE'):
         self.assertIn(
             mock.call().setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE,
                                    wsgi.CONF.tcp_keepidle),
             mock_socket.mock_calls)
Пример #10
0
 def test_create_pool(self):
     """Ensure the wsgi thread pool is an eventlet.greenpool.GreenPool."""
     actual = wsgi.Server(threads=1).create_pool()
     self.assertIsInstance(actual, eventlet.greenpool.GreenPool)