2014-02-14 05:11:34 +00:00
|
|
|
"""
|
2017-06-25 10:42:36 +00:00
|
|
|
Test Swift API
|
2014-02-14 05:11:34 +00:00
|
|
|
"""
|
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
|
2017-06-25 10:42:36 +00:00
|
|
|
from teuthology.config import config as teuth_config
|
|
|
|
from teuthology.orchestra import run
|
|
|
|
from teuthology.orchestra.connection import split_user
|
2011-11-17 00:00:01 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def download(ctx, config):
|
2014-02-14 05:11:34 +00:00
|
|
|
"""
|
|
|
|
Download the Swift API.
|
|
|
|
"""
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2017-07-07 16:44:50 +00:00
|
|
|
assert isinstance(config, dict)
|
2011-11-17 00:00:01 +00:00
|
|
|
log.info('Downloading swift...')
|
2017-07-07 16:44:50 +00:00
|
|
|
for (client, cconf) in config.items():
|
2011-11-17 00:00:01 +00:00
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'git', 'clone',
|
2017-07-07 16:44:50 +00:00
|
|
|
'-b', cconf.get('force-branch', 'ceph-master'),
|
2013-09-24 19:19:24 +00:00
|
|
|
teuth_config.ceph_git_base_url + '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)
|
2017-07-07 16:44:50 +00:00
|
|
|
for (client, _) in config.items():
|
2013-04-30 23:47:34 +00:00
|
|
|
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):
|
2014-02-14 05:11:34 +00:00
|
|
|
"""
|
|
|
|
Configure a swift user
|
|
|
|
|
|
|
|
:param account: Swift account
|
|
|
|
:param user: User name
|
|
|
|
:param suffix: user name and email suffixes.
|
|
|
|
"""
|
|
|
|
testswift_conf['func_test'].setdefault('account{s}'.format(s=suffix), account)
|
|
|
|
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):
|
2014-02-14 05:11:34 +00:00
|
|
|
"""
|
|
|
|
Create rgw users to interact with the swift interface.
|
|
|
|
"""
|
2011-11-17 00:00:01 +00:00
|
|
|
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']:
|
2016-11-10 18:58:35 +00:00
|
|
|
cluster_name, daemon_type, client_id = teuthology.split_role(client)
|
2011-11-17 00:00:01 +00:00
|
|
|
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-09-06 20:08:01 +00:00
|
|
|
'adjust-ulimits',
|
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',
|
2013-07-31 20:32:58 +00:00
|
|
|
'-n', client,
|
2016-11-10 18:58:35 +00:00
|
|
|
'--cluster', cluster_name,
|
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',
|
2014-11-24 17:59:30 +00:00
|
|
|
'--access', 'full',
|
2011-11-17 00:00:01 +00:00
|
|
|
],
|
|
|
|
)
|
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)
|
2016-11-10 18:58:35 +00:00
|
|
|
cluster_name, daemon_type, client_id = teuthology.split_role(client)
|
2013-04-30 23:49:04 +00:00
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
2013-09-06 20:08:01 +00:00
|
|
|
'adjust-ulimits',
|
2013-04-30 23:49:04 +00:00
|
|
|
'ceph-coverage',
|
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
|
|
|
'radosgw-admin',
|
2013-07-31 20:32:58 +00:00
|
|
|
'-n', client,
|
2016-11-10 18:58:35 +00:00
|
|
|
'--cluster', cluster_name,
|
2013-04-30 23:49:04 +00:00
|
|
|
'user', 'rm',
|
|
|
|
'--uid', uid,
|
|
|
|
'--purge-data',
|
|
|
|
],
|
|
|
|
)
|
2011-11-17 00:00:01 +00:00
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def configure(ctx, config):
|
2014-02-14 05:11:34 +00:00
|
|
|
"""
|
|
|
|
Configure rgw and Swift
|
|
|
|
"""
|
2011-11-17 00:00:01 +00:00
|
|
|
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():
|
2013-08-15 13:49:35 +00:00
|
|
|
log.info('client={c}'.format(c=client))
|
|
|
|
log.info('config={c}'.format(c=config))
|
2011-11-17 00:00:01 +00:00
|
|
|
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'
|
|
|
|
|
2013-08-15 13:49:35 +00:00
|
|
|
log.info(client)
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2011-11-17 00:00:01 +00:00
|
|
|
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):
|
2014-02-14 05:11:34 +00:00
|
|
|
"""
|
|
|
|
Run an individual Swift test.
|
|
|
|
"""
|
2011-11-17 00:00:01 +00:00
|
|
|
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']
|
|
|
|
"""
|
2018-02-21 16:19:48 +00:00
|
|
|
assert hasattr(ctx, 'rgw'), 'swift must run after the rgw task'
|
2011-11-17 00:00:01 +00:00
|
|
|
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()
|
|
|
|
|
2013-08-15 13:49:35 +00:00
|
|
|
log.info('clients={c}'.format(c=clients))
|
2011-11-17 00:00:01 +00:00
|
|
|
|
|
|
|
testswift_conf = {}
|
|
|
|
for client in clients:
|
2018-02-21 16:19:48 +00:00
|
|
|
endpoint = ctx.rgw.role_endpoints.get(client)
|
|
|
|
assert endpoint, 'swift: no rgw endpoint for {}'.format(client)
|
|
|
|
|
2011-11-17 00:00:01 +00:00
|
|
|
testswift_conf[client] = ConfigObj(
|
|
|
|
indent_type='',
|
|
|
|
infile={
|
|
|
|
'func_test':
|
|
|
|
{
|
2018-02-21 16:19:48 +00:00
|
|
|
'auth_port' : endpoint.port,
|
2018-02-14 19:03:48 +00:00
|
|
|
'auth_ssl' : 'yes' if endpoint.cert else 'no',
|
2011-11-17 00:00:01 +00:00
|
|
|
'auth_prefix' : '/auth/',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
with contextutil.nested(
|
2017-07-07 16:44:50 +00:00
|
|
|
lambda: download(ctx=ctx, config=config),
|
2011-11-17 00:00:01 +00:00
|
|
|
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
|