def test_appconfig_dir_ignores_hidden_files(self): config_dir = { 'server.conf.d/01.conf': """ [app:main] use = egg:swift#proxy port = 8080 """, 'server.conf.d/.01.conf.swp': """ [app:main] use = egg:swift#proxy port = 8081 """, } # strip indent from test config contents config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items()) with temptree(*zip(*config_dir.items())) as path: conf_dir = os.path.join(path, 'server.conf.d') conf = wsgi.appconfig(conf_dir) expected = { '__file__': os.path.join(path, 'server.conf.d'), 'here': os.path.join(path, 'server.conf.d'), 'port': '8080', } self.assertEquals(conf, expected)
def test_run_server_with_latest_eventlet(self): config = """ [DEFAULT] swift_dir = TEMPDIR [pipeline:main] pipeline = proxy-server [app:proxy-server] use = egg:swift#proxy """ def argspec_stub(server): return mock.MagicMock(args=["capitalize_response_headers"]) contents = dedent(config) with temptree(["proxy-server.conf"]) as t: conf_file = os.path.join(t, "proxy-server.conf") with open(conf_file, "w") as f: f.write(contents.replace("TEMPDIR", t)) _fake_rings(t) with nested( mock.patch("swift.proxy.server.Application." "modify_wsgi_pipeline"), mock.patch("swift.common.wsgi.wsgi"), mock.patch("swift.common.wsgi.eventlet"), mock.patch("swift.common.wsgi.inspect", getargspec=argspec_stub), ) as (_, _wsgi, _, _): conf = wsgi.appconfig(conf_file) logger = logging.getLogger("test") sock = listen(("localhost", 0)) wsgi.run_server(conf, logger, sock) _wsgi.server.assert_called() args, kwargs = _wsgi.server.call_args self.assertEquals(kwargs.get("capitalize_response_headers"), False)
def test_run_server_debug(self): config = """ [DEFAULT] eventlet_debug = yes client_timeout = 30 max_clients = 1000 swift_dir = TEMPDIR [pipeline:main] pipeline = proxy-server [app:proxy-server] use = egg:swift#proxy # while "set" values normally override default set client_timeout = 20 # this section is not in conf during run_server set max_clients = 10 """ contents = dedent(config) with temptree(['proxy-server.conf']) as t: conf_file = os.path.join(t, 'proxy-server.conf') with open(conf_file, 'w') as f: f.write(contents.replace('TEMPDIR', t)) _fake_rings(t) with mock.patch('swift.proxy.server.Application.' 'modify_wsgi_pipeline'): with mock.patch('swift.common.wsgi.wsgi') as _wsgi: mock_server = _wsgi.server _wsgi.server = lambda *args, **kwargs: mock_server( *args, **kwargs) with mock.patch('swift.common.wsgi.eventlet') as _eventlet: conf = wsgi.appconfig(conf_file) logger = logging.getLogger('test') sock = listen(('localhost', 0)) wsgi.run_server(conf, logger, sock) self.assertEquals('HTTP/1.0', _wsgi.HttpProtocol.default_request_version) self.assertEquals(30, _wsgi.WRITE_TIMEOUT) _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True) _eventlet.debug.hub_exceptions.assert_called_with(True) self.assertTrue(mock_server.called) args, kwargs = mock_server.call_args server_sock, server_app, server_logger = args self.assertEquals(sock, server_sock) self.assert_(isinstance(server_app, swift.proxy.server.Application)) self.assertEquals(20, server_app.client_timeout) self.assertEqual(server_logger, None) self.assert_('custom_pool' in kwargs) self.assertEquals(1000, kwargs['custom_pool'].size)
def test_run_server_conf_dir(self): config_dir = { 'proxy-server.conf.d/pipeline.conf': """ [pipeline:main] pipeline = proxy-server """, 'proxy-server.conf.d/app.conf': """ [app:proxy-server] use = egg:swift#proxy """, 'proxy-server.conf.d/default.conf': """ [DEFAULT] eventlet_debug = yes client_timeout = 30 """ } # strip indent from test config contents config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items()) with temptree(*zip(*config_dir.items())) as conf_root: conf_dir = os.path.join(conf_root, 'proxy-server.conf.d') with open(os.path.join(conf_dir, 'swift.conf'), 'w') as f: f.write('[DEFAULT]\nswift_dir = %s' % conf_root) _fake_rings(conf_root) with mock.patch('swift.proxy.server.Application.' 'modify_wsgi_pipeline'): with mock.patch('swift.common.wsgi.wsgi') as _wsgi: with mock.patch('swift.common.wsgi.eventlet') as _eventlet: with mock.patch.dict('os.environ', {'TZ': ''}): with mock.patch('swift.common.wsgi.inspect'): conf = wsgi.appconfig(conf_dir) logger = logging.getLogger('test') sock = listen(('localhost', 0)) wsgi.run_server(conf, logger, sock) self.assert_(os.environ['TZ'] is not '') self.assertEquals('HTTP/1.0', _wsgi.HttpProtocol.default_request_version) self.assertEquals(30, _wsgi.WRITE_TIMEOUT) _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True) _eventlet.debug.hub_exceptions.assert_called_with(True) _wsgi.server.assert_called() args, kwargs = _wsgi.server.call_args server_sock, server_app, server_logger = args self.assertEquals(sock, server_sock) self.assert_(isinstance(server_app, swift.proxy.server.Application)) self.assert_(isinstance(server_logger, wsgi.NullLogger)) self.assert_('custom_pool' in kwargs)
def test_run_server(self): config = """ [DEFAULT] client_timeout = 30 max_clients = 1000 swift_dir = TEMPDIR [pipeline:main] pipeline = proxy-server [app:proxy-server] use = egg:swift#proxy # while "set" values normally override default set client_timeout = 20 # this section is not in conf during run_server set max_clients = 10 """ contents = dedent(config) with temptree(["proxy-server.conf"]) as t: conf_file = os.path.join(t, "proxy-server.conf") with open(conf_file, "w") as f: f.write(contents.replace("TEMPDIR", t)) _fake_rings(t) with mock.patch("swift.proxy.server.Application." "modify_wsgi_pipeline"): with mock.patch("swift.common.wsgi.wsgi") as _wsgi: with mock.patch("swift.common.wsgi.eventlet") as _eventlet: with mock.patch("swift.common.wsgi.inspect"): conf = wsgi.appconfig(conf_file) logger = logging.getLogger("test") sock = listen(("localhost", 0)) wsgi.run_server(conf, logger, sock) self.assertEquals("HTTP/1.0", _wsgi.HttpProtocol.default_request_version) self.assertEquals(30, _wsgi.WRITE_TIMEOUT) _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True) _eventlet.debug.hub_exceptions.assert_called_with(False) _wsgi.server.assert_called() args, kwargs = _wsgi.server.call_args server_sock, server_app, server_logger = args self.assertEquals(sock, server_sock) self.assert_(isinstance(server_app, swift.proxy.server.Application)) self.assertEquals(20, server_app.client_timeout) self.assert_(isinstance(server_logger, wsgi.NullLogger)) self.assert_("custom_pool" in kwargs) self.assertEquals(1000, kwargs["custom_pool"].size)
def test_run_server_conf_dir(self): config_dir = { "proxy-server.conf.d/pipeline.conf": """ [pipeline:main] pipeline = proxy-server """, "proxy-server.conf.d/app.conf": """ [app:proxy-server] use = egg:swift#proxy """, "proxy-server.conf.d/default.conf": """ [DEFAULT] client_timeout = 30 """, } # strip indent from test config contents config_dir = dict((f, dedent(c)) for (f, c) in config_dir.items()) with temptree(*zip(*config_dir.items())) as conf_root: conf_dir = os.path.join(conf_root, "proxy-server.conf.d") with open(os.path.join(conf_dir, "swift.conf"), "w") as f: f.write("[DEFAULT]\nswift_dir = %s" % conf_root) _fake_rings(conf_root) with mock.patch("swift.proxy.server.Application." "modify_wsgi_pipeline"): with mock.patch("swift.common.wsgi.wsgi") as _wsgi: with mock.patch("swift.common.wsgi.eventlet") as _eventlet: with mock.patch.dict("os.environ", {"TZ": ""}): with mock.patch("swift.common.wsgi.inspect"): conf = wsgi.appconfig(conf_dir) logger = logging.getLogger("test") sock = listen(("localhost", 0)) wsgi.run_server(conf, logger, sock) self.assert_(os.environ["TZ"] is not "") self.assertEquals("HTTP/1.0", _wsgi.HttpProtocol.default_request_version) self.assertEquals(30, _wsgi.WRITE_TIMEOUT) _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True) _eventlet.debug.hub_exceptions.assert_called_with(False) _wsgi.server.assert_called() args, kwargs = _wsgi.server.call_args server_sock, server_app, server_logger = args self.assertEquals(sock, server_sock) self.assert_(isinstance(server_app, swift.proxy.server.Application)) self.assert_(isinstance(server_logger, wsgi.NullLogger)) self.assert_("custom_pool" in kwargs)
def test_run_server(self): config = """ [DEFAULT] eventlet_debug = yes client_timeout = 30 swift_dir = TEMPDIR [pipeline:main] pipeline = proxy-server [app:proxy-server] use = egg:swift#proxy """ contents = dedent(config) with temptree(['proxy-server.conf']) as t: conf_file = os.path.join(t, 'proxy-server.conf') with open(conf_file, 'w') as f: f.write(contents.replace('TEMPDIR', t)) _fake_rings(t) with patch('swift.common.wsgi.wsgi') as _wsgi: with patch('swift.common.wsgi.eventlet') as _eventlet: conf = wsgi.appconfig(conf_file) logger = logging.getLogger('test') sock = listen(('localhost', 0)) wsgi.run_server(conf, logger, sock) self.assertEquals('HTTP/1.0', _wsgi.HttpProtocol.default_request_version) self.assertEquals(30, _wsgi.WRITE_TIMEOUT) _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True) _eventlet.debug.hub_exceptions.assert_called_with(True) _wsgi.server.assert_called() args, kwargs = _wsgi.server.call_args server_sock, server_app, server_logger = args self.assertEquals(sock, server_sock) self.assert_(isinstance(server_app, swift.proxy.server.Application)) self.assert_(isinstance(server_logger, wsgi.NullLogger)) self.assert_('custom_pool' in kwargs)
def test_run_server_with_latest_eventlet(self): config = """ [DEFAULT] swift_dir = TEMPDIR [pipeline:main] pipeline = proxy-server [app:proxy-server] use = egg:swift#proxy """ def argspec_stub(server): return mock.MagicMock(args=['capitalize_response_headers']) contents = dedent(config) with temptree(['proxy-server.conf']) as t: conf_file = os.path.join(t, 'proxy-server.conf') with open(conf_file, 'w') as f: f.write(contents.replace('TEMPDIR', t)) _fake_rings(t) with nested( mock.patch('swift.proxy.server.Application.' 'modify_wsgi_pipeline'), mock.patch('swift.common.wsgi.wsgi'), mock.patch('swift.common.wsgi.eventlet'), mock.patch('swift.common.wsgi.inspect', getargspec=argspec_stub)) as (_, _wsgi, _, _): conf = wsgi.appconfig(conf_file) logger = logging.getLogger('test') sock = listen(('localhost', 0)) wsgi.run_server(conf, logger, sock) self.assertTrue(_wsgi.server.called) args, kwargs = _wsgi.server.call_args self.assertEquals(kwargs.get('capitalize_response_headers'), False)