30
31
from gzip import GzipFile
31
32
from shutil import rmtree
32
33
from tempfile import mkdtemp
34
from swift.common.middleware.memcache import MemcacheMiddleware
34
36
from test import get_config
35
37
from test.functional.swift_test_client import Account, Connection, \
40
42
from test.unit import debug_logger, FakeMemcache
42
44
from swift.common import constraints, utils, ring, storage_policy
43
from swift.common.wsgi import monkey_patch_mimetools
44
from swift.common.middleware import catch_errors, gatekeeper, healthcheck, \
45
proxy_logging, container_sync, bulk, tempurl, slo, dlo, ratelimit, \
46
tempauth, container_quotas, account_quotas
45
from swift.common.ring import Ring
46
from swift.common.wsgi import monkey_patch_mimetools, loadapp
47
47
from swift.common.utils import config_true_value
48
from swift.proxy import server as proxy_server
49
48
from swift.account import server as account_server
50
49
from swift.container import server as container_server
51
50
from swift.obj import server as object_server, mem_server as mem_object_server
103
102
_testdir = _test_servers = _test_sockets = _test_coros = None
106
class FakeMemcacheMiddleware(object):
105
class FakeMemcacheMiddleware(MemcacheMiddleware):
108
Caching middleware that fakes out caching in swift.
107
Caching middleware that fakes out caching in swift if memcached
108
does not appear to be running.
111
111
def __init__(self, app, conf):
112
super(FakeMemcacheMiddleware, self).__init__(app, conf)
113
113
self.memcache = FakeMemcache()
115
def __call__(self, env, start_response):
116
env['swift.cache'] = self.memcache
117
return self.app(env, start_response)
120
def fake_memcache_filter_factory(conf):
122
return FakeMemcacheMiddleware(app, conf)
126
116
# swift.conf contents for in-process functional test runs
127
117
functests_swift_conf = '''
137
127
def in_process_setup(the_object_server=object_server):
138
128
print >>sys.stderr, 'IN-PROCESS SERVERS IN USE FOR FUNCTIONAL TESTS'
139
129
print >>sys.stderr, 'Using object_server: %s' % the_object_server.__name__
130
_dir = os.path.normpath(os.path.join(os.path.abspath(__file__),
131
os.pardir, os.pardir, os.pardir))
132
proxy_conf = os.path.join(_dir, 'etc', 'proxy-server.conf-sample')
133
if os.path.exists(proxy_conf):
134
print >>sys.stderr, 'Using proxy-server config from %s' % proxy_conf
137
print >>sys.stderr, 'Failed to find conf file %s' % proxy_conf
141
140
monkey_patch_mimetools()
163
162
if constraints.SWIFT_CONSTRAINTS_LOADED:
164
163
# Use the swift constraints that are loaded for the test framework
166
config.update(constraints.EFFECTIVE_CONSTRAINTS)
165
_c = dict((k, str(v))
166
for k, v in constraints.EFFECTIVE_CONSTRAINTS.items())
168
169
# In-process swift constraints were not loaded, somethings wrong
184
185
'devices': _testdir,
185
186
'swift_dir': _testdir,
186
187
'mount_check': 'false',
188
'client_timeout': '4',
188
189
'allow_account_management': 'true',
189
190
'account_autocreate': 'true',
191
'content-disposition, content-encoding, x-delete-at,'
192
' x-object-manifest, x-static-large-object',
193
191
'allow_versions': 'True',
194
192
# Below are values used by the functional test framework, as well as
195
193
# by the various in-process swift servers
261
259
# Default to only 4 seconds for in-process functional test runs
262
260
eventlet.wsgi.WRITE_TIMEOUT = 4
264
prosrv = proxy_server.Application(config, logger=debug_logger('proxy'))
265
262
acc1srv = account_server.AccountController(
266
263
config, logger=debug_logger('acct1'))
267
264
acc2srv = account_server.AccountController(
274
271
config, logger=debug_logger('obj1'))
275
272
obj2srv = the_object_server.ObjectController(
276
273
config, logger=debug_logger('obj2'))
279
(prosrv, acc1srv, acc2srv, con1srv, con2srv, obj1srv, obj2srv)
282
catch_errors.filter_factory,
283
gatekeeper.filter_factory,
284
healthcheck.filter_factory,
285
proxy_logging.filter_factory,
286
fake_memcache_filter_factory,
287
container_sync.filter_factory,
289
tempurl.filter_factory,
292
ratelimit.filter_factory,
293
tempauth.filter_factory,
294
container_quotas.filter_factory,
295
account_quotas.filter_factory,
296
proxy_logging.filter_factory,
300
for filter_factory in reversed(pipeline):
301
app_filter = filter_factory(config)
302
with mock.patch('swift.common.utils') as mock_utils:
303
mock_utils.get_logger.return_value = None
304
app = app_filter(app)
305
app.logger = prosrv.logger
275
logger = debug_logger('proxy')
277
def get_logger(name, *args, **kwargs):
280
with mock.patch('swift.common.utils.get_logger', get_logger):
281
with mock.patch('swift.common.middleware.memcache.MemcacheMiddleware',
282
FakeMemcacheMiddleware):
283
app = loadapp(proxy_conf, global_conf=config)
307
285
nl = utils.NullLogger()
308
286
prospa = eventlet.spawn(eventlet.wsgi.server, prolis, app, nl)
319
297
# Create accounts "test" and "test2"
320
298
def create_account(act):
321
299
ts = utils.normalize_timestamp(time())
322
partition, nodes = prosrv.account_ring.get_nodes(act)
300
account_ring = Ring(_testdir, ring_name='account')
301
partition, nodes = account_ring.get_nodes(act)
323
302
for node in nodes:
324
303
# Note: we are just using the http_connect method in the object
325
304
# controller here to talk to the account server nodes.