Example #1
0
    def test_number_of_workers(self):
        """Ensure the number of workers matches num cpus limited to 8."""
        def pid():
            i = 1
            while True:
                i = i + 1
                yield i

        with mock.patch.object(os, 'fork') as mock_fork:
            with mock.patch('oslo_concurrency.processutils.get_worker_count',
                            return_value=4):
                mock_fork.side_effect = pid
                server = wsgi.Server()
                server.configure = mock.Mock()
                fake_application = "fake-application"
                server.start(fake_application, None)
                self.assertEqual(4, len(server.children))
            with mock.patch('oslo_concurrency.processutils.get_worker_count',
                            return_value=24):
                mock_fork.side_effect = pid
                server = wsgi.Server()
                server.configure = mock.Mock()
                fake_application = "fake-application"
                server.start(fake_application, None)
                self.assertEqual(8, len(server.children))
            mock_fork.side_effect = pid
            server = wsgi.Server()
            server.configure = mock.Mock()
            fake_application = "fake-application"
            server.start(fake_application, None)
            cpus = processutils.get_worker_count()
            expected_workers = cpus if cpus < 8 else 8
            self.assertEqual(expected_workers, len(server.children))
Example #2
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()
     server_one.start(RedirectTestApp("one"), self.port_one, "127.0.0.1")
     server_two.start(RedirectTestApp("two"), self.port_two, "127.0.0.1")
     self.client = client.BaseClient("127.0.0.1", self.port_one)
Example #3
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()
     conf = utils.TestConfigOpts({'bind_host': '127.0.0.1'})
     server_one.start(RedirectTestApp("one"), conf, self.port_one)
     server_two.start(RedirectTestApp("two"), conf, self.port_two)
     self.client = client.BaseClient("127.0.0.1", self.port_one)
 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)
Example #5
0
 def setUp(self):
     super(TestClientRedirects, self).setUp()
     self.port_one = utils.get_unused_port()
     self.port_two = utils.get_unused_port()
     self.image_cache_dir = os.path.join(self.test_dir, 'cache')
     self.config(image_cache_dir=self.image_cache_dir)
     self.config(image_cache_driver='sqlite')
     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)
Example #6
0
 def setUp(self):
     super(TestClientExceptions, self).setUp()
     self.port = utils.get_unused_port()
     server = wsgi.Server()
     conf = utils.TestConfigOpts({'bind_host': '127.0.0.1'})
     server.start(ExceptionTestApp(), conf, self.port)
     self.client = client.BaseClient("127.0.0.1", self.port)
Example #7
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        notifier.set_defaults()

        # Shared data need to be initialized prior to fork()
        # so we need this before WSGI initialization in case it is
        # configured to use it
        cache_raw.initialize()

        if CONF.profiler.enabled:
            osprofiler.initializer.init_from_conf(conf=CONF,
                                                  context={},
                                                  project="glance",
                                                  service="api",
                                                  host=CONF.bind_host)

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        # Start RAW caching
        p = cache_raw.start_raw_caching(server)
        server.wait(p)

    except KNOWN_EXCEPTIONS as e:
        fail(e)
Example #8
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        gmr.TextGuruMeditation.setup_autorun(version)
        notifier.set_defaults()

        if CONF.profiler.enabled:
            osprofiler.initializer.init_from_conf(
                conf=CONF,
                context={},
                project="glance",
                service="api",
                host=CONF.bind_host
            )

        # NOTE(danms): Configure system-wide threading model to use eventlet
        glance.async_.set_threadpool_model('eventlet')

        # NOTE(abhishekk): Added initialize_prefetcher KW argument to Server
        # object so that prefetcher object should only be initialized in case
        # of API service and ignored in case of registry. Once registry is
        # removed this parameter should be removed as well.
        initialize_prefetcher = False
        if CONF.paste_deploy.flavor == 'keystone+cachemanagement':
            initialize_prefetcher = True
        server = wsgi.Server(initialize_glance_store=True,
                             initialize_prefetcher=initialize_prefetcher)
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        server.wait()
    except Exception as e:
        fail(e)
Example #9
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        log.setup('glance')

        glance_store.register_opts(config.CONF)
        glance_store.create_stores(config.CONF)
        glance_store.verify_default_store()

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

        server = wsgi.Server()
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        systemd.notify_once()
        server.wait()
    except exception.WorkerCreationFailure as e:
        fail(2, e)
    except RuntimeError as e:
        fail(1, e)
Example #10
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]
        sock1 = socket.socket()
        sock1.connect(("127.0.0.1", port))

        fd = sock1.makefile('rw')
        fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
        fd.flush()

        buf = fd.read()
        # Should succeed - no timeout
        self.assertTrue(re.search(greetings, buf))

        sock2 = socket.socket()
        sock2.connect(("127.0.0.1", port))
        time.sleep(0.2)

        fd = sock2.makefile('rw')
        fd.write(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
        fd.flush()

        buf = fd.read()
        # Should fail - connection timed out so we get nothing from the server
        self.assertFalse(buf)
Example #11
0
 def test_reserved_stores_not_allowed(self, mock_configure_socket,
                                      mock_prefetcher):
     """Ensure the reserved stores are not allowed"""
     enabled_backends = {'os_glance_file_store': 'file'}
     self.config(enabled_backends=enabled_backends)
     server = wsgi.Server(threads=1, initialize_glance_store=True)
     self.assertRaises(RuntimeError, server.configure)
Example #12
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')
     server.start(ExceptionTestApp, self.port)
     self.client = client.BaseClient("127.0.0.1", self.port)
Example #13
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        notifier.set_defaults()

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   oslo_messaging, {},
                                                   notifier.get_transport(),
                                                   "glance", "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('glance-registry'),
                     default_port=9191)
        server.wait()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
Example #14
0
    def test_client_socket_timeout(self):
        CONF.set_default("workers", 0)
        CONF.set_default("client_socket_timeout", 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=1.1))
Example #15
0
    def test_client_socket_timeout(self):
        self.config(workers=0)
        self.config(client_socket_timeout=1)
        """Verify connections are timed out as per 'client_socket_timeout'"""
        greetings = b'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):
            # Socket timeouts are handled rather inconsistently on Windows.
            # recv may either return nothing OR raise a ConnectionAbortedError.
            exp_exc = OSError if os.name == 'nt' else ()

            try:
                sock = socket.socket()
                sock.connect(('127.0.0.1', port))
                time.sleep(delay)
                sock.send(b'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
                return sock.recv(1024)
            except exp_exc:
                return None

        # 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=1.1))
Example #16
0
 def test_time_is_monkey_patched(self):
     """
     Test GET with no redirect
     """
     server = wsgi.Server()
     server.create_pool()
     self.assertTrue(eventlet.patcher.is_monkey_patched(time))
     self.assertTrue(eventlet.patcher.is_monkey_patched(socket))
Example #17
0
 def setUp(self):
     super(TestClientExceptions, self).setUp()
     self.port = utils.get_unused_port()
     self.image_cache_dir = os.path.join(self.test_dir, 'cache')
     self.config(image_cache_dir=self.image_cache_dir)
     self.config(image_cache_driver='sqlite')
     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)
Example #18
0
def main():
    try:
        config.parse_args()
        log.setup('glance')

        server = wsgi.Server()
        server.start(config.load_paste_app('glance-registry'),
                     default_port=9191)
        server.wait()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
Example #19
0
def main():
    try:
        config.parse_args(default_config_files='glance-sync.conf')
        log.setup('glance')

        server = wsgi.Server()
        server.start(config.load_paste_app('glance-sync'), default_port=9595)
        server.wait()
    except exception.WorkerCreationFailure as e:
        fail(2, e)
    except RuntimeError as e:
        fail(1, e)
Example #20
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        notifier.set_defaults()

        osprofiler.web.disable()

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
Example #21
0
def main():
    try:
        config.parse_args()
        log.setup('glance')

        glance.store.create_stores()
        glance.store.verify_default_store()

        server = wsgi.Server()
        server.start(config.load_paste_app(), default_port=9292)
        server.wait()
    except exception.WorkerCreationFailure as e:
        fail(2, e)
    except RuntimeError as e:
        fail(1, e)
Example #22
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))
Example #23
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._wsgi_logger,
                                                debug=False,
                                                custom_pool=server.pool,
                                                keepalive=False)
Example #24
0
 def test_correct_configure_socket(self, mock_prefetcher):
     mock_socket = mock.Mock()
     self.useFixture(
         fixtures.MonkeyPatch('glance.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)
Example #25
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        gmr.TextGuruMeditation.setup_autorun(version)
        notifier.set_defaults()

        if CONF.profiler.enabled:
            osprofiler.initializer.init_from_conf(
                conf=CONF,
                context={},
                project="glance",
                service="api",
                host=CONF.bind_host
            )

        if CONF.enforce_secure_rbac != CONF.oslo_policy.enforce_new_defaults:
            fail_message = (
                "[DEFAULT] enforce_secure_rbac does not match "
                "[oslo_policy] enforce_new_defaults. Please set both to "
                "True to enable secure RBAC personas. Otherwise, make sure "
                "both are False.")
            raise exception.ServerError(fail_message)

        # NOTE(danms): Configure system-wide threading model to use eventlet
        glance.async_.set_threadpool_model('eventlet')

        # NOTE(abhishekk): Added initialize_prefetcher KW argument to Server
        # object so that prefetcher object should only be initialized in case
        # of API service and ignored in case of registry. Once registry is
        # removed this parameter should be removed as well.
        initialize_prefetcher = False
        if CONF.paste_deploy.flavor == 'keystone+cachemanagement':
            initialize_prefetcher = True
        server = wsgi.Server(initialize_glance_store=True,
                             initialize_prefetcher=initialize_prefetcher)
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        server.wait()
    except Exception as e:
        fail(e)
Example #26
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        notifier.set_defaults()

        if CONF.profiler.enabled:
            osprofiler.initializer.init_from_conf(conf=CONF,
                                                  context={},
                                                  project="glance",
                                                  service="api",
                                                  host=CONF.bind_host)

        server = wsgi.Server(initialize_glance_store=True)
        server.start(config.load_paste_app('glance-api'), default_port=9292)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
Example #27
0
def main():
    try:
        config.parse_args()
        config.set_config_defaults()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')
        notifier.set_defaults()

        if CONF.profiler.enabled:
            osprofiler.initializer.init_from_conf(conf=CONF,
                                                  context={},
                                                  project="glance",
                                                  service="registry",
                                                  host=CONF.bind_host)

        server = wsgi.Server()
        server.start(config.load_paste_app('glance-registry'),
                     default_port=9191)
        server.wait()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
Example #28
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        logging.setup(CONF, 'glance')

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   notifier.messaging, {},
                                                   notifier.get_transport(),
                                                   "glance", "api",
                                                   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('glance-api'), default_port=9292)
        server.wait()
    except KNOWN_EXCEPTIONS as e:
        fail(e)
Example #29
0
def main():
    try:
        config.parse_args()
        wsgi.set_eventlet_hub()
        log.setup('glance')

        if cfg.CONF.profiler.enabled:
            _notifier = osprofiler.notifier.create("Messaging",
                                                   notifier.messaging, {},
                                                   notifier.get_transport(),
                                                   "glance", "registry",
                                                   cfg.CONF.bind_host)
            osprofiler.notifier.set(_notifier)

        else:
            osprofiler.web.disable()

        server = wsgi.Server()
        server.start(config.load_paste_app('glance-registry'),
                     default_port=9191)
        server.wait()
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)
Example #30
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)