~ubuntu-branches/ubuntu/vivid/swift/vivid

« back to all changes in this revision

Viewing changes to test/functional/__init__.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2014-12-19 14:33:19 UTC
  • mfrom: (1.2.34)
  • Revision ID: package-import@ubuntu.com-20141219143319-kbs2wk1dixt2aoqq
Tags: 2.2.1-0ubuntu1
[ Chuck Short ]
* Open for Vivid.
* d/control: Update branch locations.

[ James Page ]
* New upstream release:
  - d/p/*: Refresh.
* d/control: Bumped Standards-Version 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
 
 
16
import mock
16
17
import os
17
18
import sys
18
19
import pickle
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
33
35
 
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
41
43
 
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
104
103
 
105
104
 
106
 
class FakeMemcacheMiddleware(object):
 
105
class FakeMemcacheMiddleware(MemcacheMiddleware):
107
106
    """
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.
109
109
    """
110
110
 
111
111
    def __init__(self, app, conf):
112
 
        self.app = app
 
112
        super(FakeMemcacheMiddleware, self).__init__(app, conf)
113
113
        self.memcache = FakeMemcache()
114
114
 
115
 
    def __call__(self, env, start_response):
116
 
        env['swift.cache'] = self.memcache
117
 
        return self.app(env, start_response)
118
 
 
119
 
 
120
 
def fake_memcache_filter_factory(conf):
121
 
    def filter_app(app):
122
 
        return FakeMemcacheMiddleware(app, conf)
123
 
    return filter_app
124
 
 
125
115
 
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
 
135
 
 
136
    else:
 
137
        print >>sys.stderr, 'Failed to find conf file %s' % proxy_conf
 
138
        return
140
139
 
141
140
    monkey_patch_mimetools()
142
141
 
163
162
    if constraints.SWIFT_CONSTRAINTS_LOADED:
164
163
        # Use the swift constraints that are loaded for the test framework
165
164
        # configuration
166
 
        config.update(constraints.EFFECTIVE_CONSTRAINTS)
 
165
        _c = dict((k, str(v))
 
166
                  for k, v in constraints.EFFECTIVE_CONSTRAINTS.items())
 
167
        config.update(_c)
167
168
    else:
168
169
        # In-process swift constraints were not loaded, somethings wrong
169
170
        raise SkipTest
184
185
        'devices': _testdir,
185
186
        'swift_dir': _testdir,
186
187
        'mount_check': 'false',
187
 
        'client_timeout': 4,
 
188
        'client_timeout': '4',
188
189
        'allow_account_management': 'true',
189
190
        'account_autocreate': 'true',
190
 
        'allowed_headers':
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
263
261
 
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'))
277
 
    global _test_servers
278
 
    _test_servers = \
279
 
        (prosrv, acc1srv, acc2srv, con1srv, con2srv, obj1srv, obj2srv)
280
 
 
281
 
    pipeline = [
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,
288
 
        bulk.filter_factory,
289
 
        tempurl.filter_factory,
290
 
        slo.filter_factory,
291
 
        dlo.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,
297
 
    ]
298
 
    app = prosrv
299
 
    import mock
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
 
274
 
 
275
    logger = debug_logger('proxy')
 
276
 
 
277
    def get_logger(name, *args, **kwargs):
 
278
        return logger
 
279
 
 
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)
306
284
 
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.