def test_is_eventlet_bug105(self): fake_dns = mock.Mock() fake_dns.getaddrinfo.side_effect = socket.gaierror(errno.EBADF) with mock.patch.dict('sys.modules', {'eventlet.support.greendns': fake_dns}): self.assertTrue(utils.is_eventlet_bug105()) self.assertTrue(fake_dns.getaddrinfo.called)
def test_is_eventlet_bug105(self): fake_dns = mock.Mock() fake_dns.getaddrinfo.side_effect = socket.gaierror(errno.EBADF) with mock.patch.dict('sys.modules', { 'eventlet.support.greendns': fake_dns}): self.assertTrue(utils.is_eventlet_bug105()) fake_dns.getaddrinfo.assert_called_once()
def test_is_eventlet_bug105_neg(self): fake_dns = mock.Mock() fake_dns.getaddrinfo.return_value = [ (socket.AF_INET6, socket.SOCK_STREAM, 0, '', (u'127.0.0.1', 80)), ] with mock.patch.dict('sys.modules', {'eventlet.support.greendns': fake_dns}): self.assertFalse(utils.is_eventlet_bug105()) fake_dns.getaddrinfo.assert_called_once_with('::1', 80)
def test_is_eventlet_bug105_neg(self): fake_dns = mock.Mock() fake_dns.getaddrinfo.return_value = [ (socket.AF_INET6, socket.SOCK_STREAM, 0, '', (u'127.0.0.1', 80)), ] with mock.patch.dict('sys.modules', { 'eventlet.support.greendns': fake_dns}): self.assertFalse(utils.is_eventlet_bug105()) fake_dns.getaddrinfo.assert_called_once()
class TestWSGIServer(test.TestCase): """WSGI server tests.""" def test_no_app(self): server = manila.wsgi.Server("test_app", None, host="127.0.0.1", port=0) self.assertEqual("test_app", server.name) def test_start_random_port(self): server = manila.wsgi.Server("test_random_port", None, host="127.0.0.1") server.start() self.assertNotEqual(0, server.port) server.stop() server.wait() @testtools.skipIf(not netutils.is_ipv6_enabled(), "Test requires an IPV6 configured interface") @testtools.skipIf(utils.is_eventlet_bug105(), 'Eventlet bug #105 affect test results.') def test_start_random_port_with_ipv6(self): server = manila.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_start_with_default_tcp_options(self): server = manila.wsgi.Server("test_tcp_options", None, host="127.0.0.1") self.mock_object(netutils, 'set_tcp_keepalive') server.start() netutils.set_tcp_keepalive.assert_called_once_with( mock.ANY, tcp_keepalive=True, tcp_keepalive_count=None, tcp_keepalive_interval=None, tcp_keepidle=600) def test_start_with_custom_tcp_options(self): CONF.set_default("tcp_keepalive", False) CONF.set_default("tcp_keepalive_count", 33) CONF.set_default("tcp_keepalive_interval", 22) CONF.set_default("tcp_keepidle", 11) server = manila.wsgi.Server("test_tcp_options", None, host="127.0.0.1") self.mock_object(netutils, 'set_tcp_keepalive') server.start() netutils.set_tcp_keepalive.assert_called_once_with( mock.ANY, tcp_keepalive=False, tcp_keepalive_count=33, tcp_keepalive_interval=22, tcp_keepidle=11) def test_app(self): self.mock_object(eventlet, 'spawn', mock.Mock(side_effect=eventlet.spawn)) 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 = manila.wsgi.Server("test_app", hello_world, host="127.0.0.1", port=0) server.start() response = urllib.request.urlopen('http://127.0.0.1:%d/' % server.port) self.assertEqual(six.b(greetings), response.read()) # Verify provided parameters to eventlet.spawn func eventlet.spawn.assert_called_once_with( func=eventlet.wsgi.server, sock=mock.ANY, site=server.app, protocol=server._protocol, custom_pool=server._pool, log=server._logger, socket_timeout=server.client_socket_timeout, keepalive=manila.wsgi.CONF.wsgi_keep_alive, ) server.stop() @ddt.data(0, 0.1, 1, None) def test_init_server_with_socket_timeout(self, client_socket_timeout): CONF.set_default("client_socket_timeout", client_socket_timeout) server = manila.wsgi.Server("test_app", lambda *args, **kwargs: None, host="127.0.0.1", port=0) self.assertEqual(client_socket_timeout, server.client_socket_timeout) @testtools.skipIf(six.PY3, "bug/1482633") def test_app_using_ssl(self): 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 = manila.wsgi.Server("test_app", hello_world, host="127.0.0.1", port=0) server.start() if hasattr(ssl, '_create_unverified_context'): response = urllib.request.urlopen( 'https://127.0.0.1:%d/' % server.port, context=ssl._create_unverified_context()) else: response = urllib.request.urlopen('https://127.0.0.1:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop() @testtools.skipIf(not netutils.is_ipv6_enabled(), "Test requires an IPV6 configured interface") @testtools.skipIf(utils.is_eventlet_bug105(), 'Eventlet bug #105 affect test results.') @testtools.skipIf(six.PY3, "bug/1482633") def test_app_using_ipv6_and_ssl(self): 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 = manila.wsgi.Server("test_app", hello_world, host="::1", port=0) server.start() if hasattr(ssl, '_create_unverified_context'): response = urllib.request.urlopen( 'https://[::1]:%d/' % server.port, context=ssl._create_unverified_context()) else: response = urllib.request.urlopen('https://[::1]:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop() def test_reset_pool_size_to_default(self): server = manila.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)
class TestWSGIServer(test.TestCase): """WSGI server tests.""" def test_no_app(self): server = manila.wsgi.Server("test_app", None) self.assertEqual("test_app", server.name) def test_start_random_port(self): server = manila.wsgi.Server("test_random_port", None, host="127.0.0.1") self.assertEqual(0, server.port) server.start() self.assertNotEqual(0, server.port) server.stop() server.wait() @testtools.skipIf(not utils.is_ipv6_configured(), "Test requires an IPV6 configured interface") @testtools.skipIf(utils.is_eventlet_bug105(), 'Eventlet bug #105 affect test results.') def test_start_random_port_with_ipv6(self): server = manila.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_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 = manila.wsgi.Server("test_app", hello_world) server.start() response = urllib2.urlopen('http://127.0.0.1:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop() def test_app_using_ssl(self): 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 = manila.wsgi.Server("test_app", hello_world) server.start() response = urllib2.urlopen('https://127.0.0.1:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop() @testtools.skipIf(not utils.is_ipv6_configured(), "Test requires an IPV6 configured interface") @testtools.skipIf(utils.is_eventlet_bug105(), 'Eventlet bug #105 affect test results.') def test_app_using_ipv6_and_ssl(self): 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 = manila.wsgi.Server("test_app", hello_world, host="::1", port=0) server.start() response = urllib2.urlopen('https://[::1]:%d/' % server.port) self.assertEqual(greetings, response.read()) server.stop()