2011-11-17 00:00:01 +00:00
|
|
|
from cStringIO import StringIO
|
|
|
|
from configobj import ConfigObj
|
|
|
|
import base64
|
|
|
|
import contextlib
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from teuthology import misc as teuthology
|
|
|
|
from teuthology import contextutil
|
|
|
|
from ..orchestra import run
|
|
|
|
from ..orchestra.connection import split_user
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def download(ctx, config):
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2011-11-17 00:00:01 +00:00
|
|
|
assert isinstance(config, list)
|
|
|
|
log.info('Downloading swift...')
|
|
|
|
for client in config:
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'git', 'clone',
|
2012-12-21 18:20:02 +00:00
|
|
|
'git://ceph.com/git/swift.git',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/swift'.format(tdir=testdir),
|
2011-11-17 00:00:01 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
2013-04-30 23:47:34 +00:00
|
|
|
log.info('Removing swift...')
|
|
|
|
testdir = teuthology.get_testdir(ctx)
|
|
|
|
for client in config:
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'rm',
|
|
|
|
'-rf',
|
|
|
|
'{tdir}/swift'.format(tdir=testdir),
|
|
|
|
],
|
|
|
|
)
|
2011-11-17 00:00:01 +00:00
|
|
|
|
|
|
|
def _config_user(testswift_conf, account, user, suffix):
|
|
|
|
testswift_conf['func_test'].setdefault('account{s}'.format(s=suffix), account);
|
2011-11-18 00:53:21 +00:00
|
|
|
testswift_conf['func_test'].setdefault('username{s}'.format(s=suffix), user);
|
2011-11-17 00:00:01 +00:00
|
|
|
testswift_conf['func_test'].setdefault('email{s}'.format(s=suffix), '{account}+test@test.test'.format(account=account))
|
|
|
|
testswift_conf['func_test'].setdefault('display_name{s}'.format(s=suffix), 'Mr. {account} {user}'.format(account=account, user=user))
|
2011-11-18 00:53:21 +00:00
|
|
|
testswift_conf['func_test'].setdefault('password{s}'.format(s=suffix), base64.b64encode(os.urandom(40)))
|
2011-11-17 00:00:01 +00:00
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def create_users(ctx, config):
|
|
|
|
assert isinstance(config, dict)
|
|
|
|
log.info('Creating rgw users...')
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2013-04-30 23:49:04 +00:00
|
|
|
users = {'': 'foo', '2': 'bar'}
|
2011-11-17 00:00:01 +00:00
|
|
|
for client in config['clients']:
|
|
|
|
testswift_conf = config['testswift_conf'][client]
|
2013-04-30 23:49:04 +00:00
|
|
|
for suffix, user in users.iteritems():
|
2011-11-17 00:00:01 +00:00
|
|
|
_config_user(testswift_conf, '{user}.{client}'.format(user=user, client=client), user, suffix)
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/enable-coredump'.format(tdir=testdir),
|
2013-02-06 19:16:52 +00:00
|
|
|
'ceph-coverage',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
2013-02-06 19:16:52 +00:00
|
|
|
'radosgw-admin',
|
2011-11-17 00:00:01 +00:00
|
|
|
'user', 'create',
|
|
|
|
'--subuser', '{account}:{user}'.format(account=testswift_conf['func_test']['account{s}'.format(s=suffix)],user=user),
|
|
|
|
'--display-name', testswift_conf['func_test']['display_name{s}'.format(s=suffix)],
|
2011-11-18 00:53:21 +00:00
|
|
|
'--secret', testswift_conf['func_test']['password{s}'.format(s=suffix)],
|
2011-11-17 00:00:01 +00:00
|
|
|
'--email', testswift_conf['func_test']['email{s}'.format(s=suffix)],
|
|
|
|
'--key-type', 'swift',
|
|
|
|
],
|
|
|
|
)
|
2013-04-30 23:49:04 +00:00
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
for client in config['clients']:
|
|
|
|
for user in users.itervalues():
|
|
|
|
uid = '{user}.{client}'.format(user=user, client=client)
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'{tdir}/enable-coredump'.format(tdir=testdir),
|
|
|
|
'ceph-coverage',
|
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
|
|
|
'radosgw-admin',
|
|
|
|
'user', 'rm',
|
|
|
|
'--uid', uid,
|
|
|
|
'--purge-data',
|
|
|
|
],
|
|
|
|
)
|
2011-11-17 00:00:01 +00:00
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def configure(ctx, config):
|
|
|
|
assert isinstance(config, dict)
|
|
|
|
log.info('Configuring testswift...')
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2011-11-17 00:00:01 +00:00
|
|
|
for client, properties in config['clients'].iteritems():
|
|
|
|
print 'client={c}'.format(c=client)
|
|
|
|
print 'config={c}'.format(c=config)
|
|
|
|
testswift_conf = config['testswift_conf'][client]
|
|
|
|
if properties is not None and 'rgw_server' in properties:
|
|
|
|
host = None
|
|
|
|
for target, roles in zip(ctx.config['targets'].iterkeys(), ctx.config['roles']):
|
|
|
|
log.info('roles: ' + str(roles))
|
|
|
|
log.info('target: ' + str(target))
|
|
|
|
if properties['rgw_server'] in roles:
|
|
|
|
_, host = split_user(target)
|
|
|
|
assert host is not None, "Invalid client specified as the rgw_server"
|
|
|
|
testswift_conf['func_test']['auth_host'] = host
|
|
|
|
else:
|
|
|
|
testswift_conf['func_test']['auth_host'] = 'localhost'
|
|
|
|
|
|
|
|
print client
|
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'cd',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/swift'.format(tdir=testdir),
|
2011-11-17 00:00:01 +00:00
|
|
|
run.Raw('&&'),
|
|
|
|
'./bootstrap',
|
|
|
|
],
|
|
|
|
)
|
|
|
|
conf_fp = StringIO()
|
|
|
|
testswift_conf.write(conf_fp)
|
|
|
|
teuthology.write_file(
|
|
|
|
remote=remote,
|
2013-01-23 20:37:39 +00:00
|
|
|
path='{tdir}/archive/testswift.{client}.conf'.format(tdir=testdir, client=client),
|
2011-11-17 00:00:01 +00:00
|
|
|
data=conf_fp.getvalue(),
|
|
|
|
)
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def run_tests(ctx, config):
|
|
|
|
assert isinstance(config, dict)
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2011-11-17 00:00:01 +00:00
|
|
|
for client, client_config in config.iteritems():
|
|
|
|
args = [
|
2013-01-23 20:37:39 +00:00
|
|
|
'SWIFT_TEST_CONFIG_FILE={tdir}/archive/testswift.{client}.conf'.format(tdir=testdir, client=client),
|
|
|
|
'{tdir}/swift/virtualenv/bin/nosetests'.format(tdir=testdir),
|
2011-11-17 00:00:01 +00:00
|
|
|
'-w',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/swift/test/functional'.format(tdir=testdir),
|
2011-11-17 00:00:01 +00:00
|
|
|
'-v',
|
|
|
|
'-a', '!fails_on_rgw',
|
|
|
|
]
|
|
|
|
if client_config is not None and 'extra_args' in client_config:
|
|
|
|
args.extend(client_config['extra_args'])
|
|
|
|
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=args,
|
|
|
|
)
|
|
|
|
yield
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run the testswift suite against rgw.
|
|
|
|
|
|
|
|
To run all tests on all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw:
|
|
|
|
- testswift:
|
|
|
|
|
|
|
|
To restrict testing to particular clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw: [client.0]
|
|
|
|
- testswift: [client.0]
|
|
|
|
|
|
|
|
To run against a server on client.1::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw: [client.1]
|
|
|
|
- testswift:
|
|
|
|
client.0:
|
|
|
|
rgw_server: client.1
|
|
|
|
|
|
|
|
To pass extra arguments to nose (e.g. to run a certain test)::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw: [client.0]
|
|
|
|
- testswift:
|
|
|
|
client.0:
|
|
|
|
extra_args: ['test.functional.tests:TestFileUTF8', '-m', 'testCopy']
|
|
|
|
client.1:
|
|
|
|
extra_args: ['--exclude', 'TestFile']
|
|
|
|
"""
|
|
|
|
assert config is None or isinstance(config, list) \
|
|
|
|
or isinstance(config, dict), \
|
|
|
|
"task testswift only supports a list or dictionary for configuration"
|
|
|
|
all_clients = ['client.{id}'.format(id=id_)
|
|
|
|
for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
|
|
|
|
if config is None:
|
|
|
|
config = all_clients
|
|
|
|
if isinstance(config, list):
|
|
|
|
config = dict.fromkeys(config)
|
|
|
|
clients = config.keys()
|
|
|
|
|
|
|
|
print 'clients={c}'.format(c=clients)
|
|
|
|
|
|
|
|
testswift_conf = {}
|
|
|
|
for client in clients:
|
|
|
|
testswift_conf[client] = ConfigObj(
|
|
|
|
indent_type='',
|
|
|
|
infile={
|
|
|
|
'func_test':
|
|
|
|
{
|
|
|
|
'auth_port' : 7280,
|
|
|
|
'auth_ssl' : 'no',
|
|
|
|
'auth_prefix' : '/auth/',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
with contextutil.nested(
|
|
|
|
lambda: download(ctx=ctx, config=clients),
|
|
|
|
lambda: create_users(ctx=ctx, config=dict(
|
|
|
|
clients=clients,
|
|
|
|
testswift_conf=testswift_conf,
|
|
|
|
)),
|
|
|
|
lambda: configure(ctx=ctx, config=dict(
|
|
|
|
clients=config,
|
|
|
|
testswift_conf=testswift_conf,
|
|
|
|
)),
|
|
|
|
lambda: run_tests(ctx=ctx, config=config),
|
|
|
|
):
|
2013-04-30 23:47:34 +00:00
|
|
|
pass
|
|
|
|
yield
|