Example #1
0
    def __init__(self, name, loader=None):
        """Initialize, but do not start the WSGI server.

        :param name: The name of the WSGI server given to the loader.
        :param loader: Loads the WSGI application using the given name.
        :returns: None

        """
        self.name = name
        self.manager = self._get_manager()
        self.loader = loader or wsgi_common.Loader()
        self.app = self.loader.load_app(name)
        self.host = getattr(CONF, '%s_listen' % name, "0.0.0.0")
        self.port = getattr(CONF, '%s_listen_port' % name, 0)
        self.workers = (getattr(CONF, '%s_workers' % name, None) or
                        processutils.get_worker_count())
        if self.workers and self.workers < 1:
            worker_name = '%s_workers' % name
            msg = (_("%(worker_name)s value of %(workers)d is invalid, "
                     "must be greater than 0.") %
                   {'worker_name': worker_name,
                    'workers': self.workers})
            raise exception.InvalidInput(msg)

        self.server = wsgi.Server(name,
                                  self.app,
                                  host=self.host,
                                  port=self.port)
 def test_start_random_port_with_ipv6(self):
     server = wsgi.Server("test_random_port",
                          None,
                          host="::1")
     server.start()
     self.assertEqual("::1", server.host)
     self.assertNotEqual(0, server.port)
     server.stop()
     server.wait()
 def test_server_pool_waitall(self):
     # test pools waitall method gets called while stopping server
     server = wsgi.Server("test_server", None,
                          host="127.0.0.1")
     server.start()
     with mock.patch.object(server._pool,
                            'waitall') as mock_waitall:
         server.stop()
         server.wait()
         mock_waitall.assert_called_once_with()
    def test_reset_pool_size_to_default(self):
        server = wsgi.Server("test_resize", None, host="127.0.0.1")
        server.start()

        # Stopping the server, which in turn sets pool size to 0
        server.stop()
        self.assertEqual(0, server._pool.size)

        # Resetting pool size to default
        server.reset()
        server.start()
        self.assertEqual(1000, server._pool.size)
 def test_start_random_port(self):
     server = wsgi.Server("test_random_port", None, host="127.0.0.1")
     server.start()
     self.assertNotEqual(0, server.port)
     server.stop()
     server.wait()
 def test_no_app(self):
     server = wsgi.Server("test_app", None,
                          host="127.0.0.1", port=0)
     self.assertEqual("test_app", server.name)