2017-01-25 22:44:05 +00:00
|
|
|
"""
|
|
|
|
Run a set of s3 tests on rgw.
|
|
|
|
"""
|
2020-02-15 10:20:11 +00:00
|
|
|
from io import BytesIO
|
2017-01-25 22:44:05 +00:00
|
|
|
from configobj import ConfigObj
|
|
|
|
import base64
|
|
|
|
import contextlib
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
|
|
|
from teuthology import misc as teuthology
|
|
|
|
from teuthology import contextutil
|
|
|
|
from teuthology.config import config as teuth_config
|
|
|
|
from teuthology.orchestra import run
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2020-07-30 08:45:40 +00:00
|
|
|
|
|
|
|
def get_ragweed_branches(config, client_conf):
|
|
|
|
"""
|
|
|
|
figure out the ragweed branch according to the per-client settings
|
|
|
|
|
|
|
|
use force-branch is specified, and fall back to the ones deduced using ceph
|
|
|
|
branch under testing
|
|
|
|
"""
|
|
|
|
force_branch = client_conf.get('force-branch', None)
|
|
|
|
if force_branch:
|
|
|
|
return [force_branch]
|
|
|
|
else:
|
|
|
|
S3_BRANCHES = ['master', 'nautilus', 'mimic',
|
|
|
|
'luminous', 'kraken', 'jewel']
|
|
|
|
ceph_branch = config.get('branch')
|
|
|
|
suite_branch = config.get('suite_branch', ceph_branch)
|
|
|
|
if suite_branch in S3_BRANCHES:
|
|
|
|
branch = client_conf.get('branch', 'ceph-' + suite_branch)
|
|
|
|
else:
|
|
|
|
branch = client_conf.get('branch', suite_branch)
|
|
|
|
default_branch = client_conf.get('default-branch', None)
|
|
|
|
if default_branch:
|
|
|
|
return [branch, default_branch]
|
|
|
|
else:
|
|
|
|
return [branch]
|
|
|
|
|
2023-03-03 15:40:03 +00:00
|
|
|
def get_ragweed_dir(testdir, client):
|
|
|
|
return '{}/ragweed.{}'.format(testdir, client)
|
2020-07-30 08:45:40 +00:00
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def download(ctx, config):
|
|
|
|
"""
|
|
|
|
Download the s3 tests from the git builder.
|
|
|
|
Remove downloaded s3 file upon exit.
|
|
|
|
|
|
|
|
The context passed in should be identical to the context
|
|
|
|
passed in to the main task.
|
|
|
|
"""
|
|
|
|
assert isinstance(config, dict)
|
|
|
|
log.info('Downloading ragweed...')
|
|
|
|
testdir = teuthology.get_testdir(ctx)
|
|
|
|
for (client, cconf) in config.items():
|
2023-03-03 15:40:03 +00:00
|
|
|
ragweed_dir = get_ragweed_dir(testdir, client)
|
2020-07-30 08:45:40 +00:00
|
|
|
ragweed_repo = ctx.config.get('ragweed_repo',
|
|
|
|
teuth_config.ceph_git_base_url + 'ragweed.git')
|
|
|
|
for branch in get_ragweed_branches(ctx.config, cconf):
|
2017-01-25 22:44:05 +00:00
|
|
|
log.info("Using branch '%s' for ragweed", branch)
|
2020-07-30 08:45:40 +00:00
|
|
|
try:
|
|
|
|
ctx.cluster.only(client).sh(
|
2023-03-03 15:40:03 +00:00
|
|
|
script=f'git clone -b {branch} {ragweed_repo} {ragweed_dir}')
|
2020-07-30 08:45:40 +00:00
|
|
|
break
|
|
|
|
except Exception as e:
|
|
|
|
exc = e
|
|
|
|
else:
|
|
|
|
raise exc
|
2019-01-08 03:04:25 +00:00
|
|
|
|
2020-07-30 08:45:40 +00:00
|
|
|
sha1 = cconf.get('sha1')
|
2017-01-25 22:44:05 +00:00
|
|
|
if sha1 is not None:
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
2023-03-03 15:40:03 +00:00
|
|
|
'cd', ragweed_dir,
|
2017-01-25 22:44:05 +00:00
|
|
|
run.Raw('&&'),
|
|
|
|
'git', 'reset', '--hard', sha1,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
log.info('Removing ragweed...')
|
|
|
|
for client in config:
|
2023-03-03 15:40:03 +00:00
|
|
|
ragweed_dir = get_ragweed_dir(testdir, client)
|
2017-01-25 22:44:05 +00:00
|
|
|
ctx.cluster.only(client).run(
|
2023-03-03 15:40:03 +00:00
|
|
|
args=['rm', '-rf', ragweed_dir]
|
2017-01-25 22:44:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _config_user(ragweed_conf, section, user):
|
|
|
|
"""
|
|
|
|
Configure users for this section by stashing away keys, ids, and
|
|
|
|
email addresses.
|
|
|
|
"""
|
|
|
|
ragweed_conf[section].setdefault('user_id', user)
|
|
|
|
ragweed_conf[section].setdefault('email', '{user}+test@test.test'.format(user=user))
|
|
|
|
ragweed_conf[section].setdefault('display_name', 'Mr. {user}'.format(user=user))
|
2020-04-06 07:12:46 +00:00
|
|
|
ragweed_conf[section].setdefault('access_key', ''.join(random.choice(string.ascii_uppercase) for i in range(20)))
|
2020-04-06 10:55:53 +00:00
|
|
|
ragweed_conf[section].setdefault('secret_key', base64.b64encode(os.urandom(40)).decode('ascii'))
|
2017-01-25 22:44:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
2017-02-22 00:34:01 +00:00
|
|
|
def create_users(ctx, config, run_stages):
|
2017-01-25 22:44:05 +00:00
|
|
|
"""
|
|
|
|
Create a main and an alternate s3 user.
|
|
|
|
"""
|
|
|
|
assert isinstance(config, dict)
|
2017-02-22 00:34:01 +00:00
|
|
|
|
2019-10-09 12:36:58 +00:00
|
|
|
for client, properties in config['config'].items():
|
2020-04-06 07:12:46 +00:00
|
|
|
run_stages[client] = properties.get('stages', 'prepare,check').split(',')
|
2017-02-22 00:34:01 +00:00
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
log.info('Creating rgw users...')
|
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2019-07-08 19:51:51 +00:00
|
|
|
users = {'user regular': 'ragweed', 'user system': 'sysuser'}
|
2017-01-25 22:44:05 +00:00
|
|
|
for client in config['clients']:
|
2017-02-22 00:34:01 +00:00
|
|
|
if not 'prepare' in run_stages[client]:
|
|
|
|
# should have been prepared in a previous run
|
|
|
|
continue
|
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
ragweed_conf = config['ragweed_conf'][client]
|
|
|
|
ragweed_conf.setdefault('fixtures', {})
|
|
|
|
ragweed_conf['rgw'].setdefault('bucket_prefix', 'test-' + client)
|
2019-10-09 12:36:58 +00:00
|
|
|
for section, user in users.items():
|
2017-01-25 22:44:05 +00:00
|
|
|
_config_user(ragweed_conf, section, '{user}.{client}'.format(user=user, client=client))
|
|
|
|
log.debug('Creating user {user} on {host}'.format(user=ragweed_conf[section]['user_id'], host=client))
|
2017-02-21 22:15:42 +00:00
|
|
|
if user == 'sysuser':
|
|
|
|
sys_str = 'true'
|
|
|
|
else:
|
|
|
|
sys_str = 'false'
|
2017-01-25 22:44:05 +00:00
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'adjust-ulimits',
|
|
|
|
'ceph-coverage',
|
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
|
|
|
'radosgw-admin',
|
|
|
|
'-n', client,
|
|
|
|
'user', 'create',
|
|
|
|
'--uid', ragweed_conf[section]['user_id'],
|
|
|
|
'--display-name', ragweed_conf[section]['display_name'],
|
|
|
|
'--access-key', ragweed_conf[section]['access_key'],
|
|
|
|
'--secret', ragweed_conf[section]['secret_key'],
|
|
|
|
'--email', ragweed_conf[section]['email'],
|
2017-02-21 22:15:42 +00:00
|
|
|
'--system', sys_str,
|
2017-01-25 22:44:05 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
for client in config['clients']:
|
2017-02-22 00:34:01 +00:00
|
|
|
if not 'check' in run_stages[client]:
|
|
|
|
# only remove user if went through the check stage
|
|
|
|
continue
|
2020-02-15 10:15:28 +00:00
|
|
|
for user in users.values():
|
2017-01-25 22:44:05 +00:00
|
|
|
uid = '{user}.{client}'.format(user=user, client=client)
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'adjust-ulimits',
|
|
|
|
'ceph-coverage',
|
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
|
|
|
'radosgw-admin',
|
|
|
|
'-n', client,
|
|
|
|
'user', 'rm',
|
|
|
|
'--uid', uid,
|
|
|
|
'--purge-data',
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
2017-02-22 00:34:01 +00:00
|
|
|
def configure(ctx, config, run_stages):
|
2017-01-25 22:44:05 +00:00
|
|
|
"""
|
2023-01-31 18:07:34 +00:00
|
|
|
Configure the local config files.
|
2017-01-25 22:44:05 +00:00
|
|
|
"""
|
|
|
|
assert isinstance(config, dict)
|
|
|
|
log.info('Configuring ragweed...')
|
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2019-10-09 12:36:58 +00:00
|
|
|
for client, properties in config['clients'].items():
|
2017-02-22 00:34:01 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
|
|
|
preparing = 'prepare' in run_stages[client]
|
|
|
|
if not preparing:
|
|
|
|
# should have been prepared in a previous run
|
|
|
|
continue
|
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
ragweed_conf = config['ragweed_conf'][client]
|
|
|
|
if properties is not None and 'slow_backend' in properties:
|
2019-12-09 16:27:46 +00:00
|
|
|
ragweed_conf['fixtures']['slow backend'] = properties['slow_backend']
|
2017-01-25 22:44:05 +00:00
|
|
|
|
2020-02-15 10:20:11 +00:00
|
|
|
conf_fp = BytesIO()
|
2017-01-25 22:44:05 +00:00
|
|
|
ragweed_conf.write(conf_fp)
|
2020-07-20 10:41:24 +00:00
|
|
|
remote.write_file(
|
2017-01-25 22:44:05 +00:00
|
|
|
path='{tdir}/archive/ragweed.{client}.conf'.format(tdir=testdir, client=client),
|
|
|
|
data=conf_fp.getvalue(),
|
|
|
|
)
|
|
|
|
|
|
|
|
log.info('Configuring boto...')
|
|
|
|
boto_src = os.path.join(os.path.dirname(__file__), 'boto.cfg.template')
|
2019-10-09 12:36:58 +00:00
|
|
|
for client, properties in config['clients'].items():
|
2020-04-06 13:14:36 +00:00
|
|
|
with open(boto_src, 'r') as f:
|
2017-01-25 22:44:05 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
|
|
|
conf = f.read().format(
|
|
|
|
idle_timeout=config.get('idle_timeout', 30)
|
|
|
|
)
|
2020-07-20 10:41:24 +00:00
|
|
|
remote.write_file('{tdir}/boto.cfg'.format(tdir=testdir), conf)
|
2017-01-25 22:44:05 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
|
|
|
|
finally:
|
|
|
|
log.info('Cleaning up boto...')
|
2019-10-09 12:36:58 +00:00
|
|
|
for client, properties in config['clients'].items():
|
2017-01-25 22:44:05 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
|
|
|
remote.run(
|
|
|
|
args=[
|
2023-03-03 15:40:03 +00:00
|
|
|
'rm', '-f',
|
2017-01-25 22:44:05 +00:00
|
|
|
'{tdir}/boto.cfg'.format(tdir=testdir),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2023-01-31 18:07:34 +00:00
|
|
|
def get_toxvenv_dir(ctx):
|
|
|
|
return ctx.tox.venv_path
|
|
|
|
|
|
|
|
def toxvenv_sh(ctx, remote, args, **kwargs):
|
|
|
|
activate = get_toxvenv_dir(ctx) + '/bin/activate'
|
|
|
|
return remote.sh(['source', activate, run.Raw('&&')] + args, **kwargs)
|
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
@contextlib.contextmanager
|
2017-02-22 00:34:01 +00:00
|
|
|
def run_tests(ctx, config, run_stages):
|
2017-01-25 22:44:05 +00:00
|
|
|
"""
|
|
|
|
Run the ragweed after everything is set up.
|
|
|
|
|
|
|
|
:param ctx: Context passed to task
|
|
|
|
:param config: specific configuration information
|
|
|
|
"""
|
|
|
|
assert isinstance(config, dict)
|
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2023-01-31 18:07:34 +00:00
|
|
|
attrs = ["not fails_on_rgw"]
|
2019-10-09 12:36:58 +00:00
|
|
|
for client, client_config in config.items():
|
2023-03-03 15:40:03 +00:00
|
|
|
ragweed_dir = get_ragweed_dir(testdir, client)
|
2020-04-06 07:12:46 +00:00
|
|
|
stages = ','.join(run_stages[client])
|
2017-01-25 22:44:05 +00:00
|
|
|
args = [
|
2023-03-03 15:40:03 +00:00
|
|
|
'cd', ragweed_dir, run.Raw('&&'),
|
2017-01-25 22:44:05 +00:00
|
|
|
'RAGWEED_CONF={tdir}/archive/ragweed.{client}.conf'.format(tdir=testdir, client=client),
|
2017-02-21 22:56:06 +00:00
|
|
|
'RAGWEED_STAGES={stages}'.format(stages=stages),
|
2017-01-25 22:44:05 +00:00
|
|
|
'BOTO_CONFIG={tdir}/boto.cfg'.format(tdir=testdir),
|
2023-01-31 18:07:34 +00:00
|
|
|
'tox',
|
|
|
|
'--sitepackages',
|
|
|
|
'--',
|
2017-01-25 22:44:05 +00:00
|
|
|
'-v',
|
2023-01-31 18:07:34 +00:00
|
|
|
'-m', ' and '.join(attrs),
|
2017-01-25 22:44:05 +00:00
|
|
|
]
|
|
|
|
if client_config is not None and 'extra_args' in client_config:
|
|
|
|
args.extend(client_config['extra_args'])
|
|
|
|
|
2023-01-31 18:07:34 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
|
|
|
toxvenv_sh(ctx, remote, args, label="ragweed tests against rgw")
|
2017-01-25 22:44:05 +00:00
|
|
|
yield
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run the ragweed suite against rgw.
|
|
|
|
|
|
|
|
To run all tests on all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw:
|
|
|
|
- ragweed:
|
|
|
|
|
|
|
|
To restrict testing to particular clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw: [client.0]
|
|
|
|
- ragweed: [client.0]
|
|
|
|
|
|
|
|
To run against a server on client.1 and increase the boto timeout to 10m::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw: [client.1]
|
|
|
|
- ragweed:
|
|
|
|
client.0:
|
|
|
|
rgw_server: client.1
|
|
|
|
idle_timeout: 600
|
2017-02-21 22:56:06 +00:00
|
|
|
stages: prepare,check
|
2017-01-25 22:44:05 +00:00
|
|
|
|
|
|
|
To pass extra arguments to nose (e.g. to run a certain test)::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rgw: [client.0]
|
|
|
|
- ragweed:
|
|
|
|
client.0:
|
|
|
|
extra_args: ['test_s3:test_object_acl_grand_public_read']
|
|
|
|
client.1:
|
|
|
|
extra_args: ['--exclude', 'test_100_continue']
|
|
|
|
"""
|
2018-02-21 16:19:48 +00:00
|
|
|
assert hasattr(ctx, 'rgw'), 'ragweed must run after the rgw task'
|
2023-01-31 18:07:34 +00:00
|
|
|
assert hasattr(ctx, 'tox'), 'ragweed must run after the tox task'
|
2017-01-25 22:44:05 +00:00
|
|
|
assert config is None or isinstance(config, list) \
|
|
|
|
or isinstance(config, dict), \
|
|
|
|
"task ragweed 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()
|
|
|
|
|
|
|
|
overrides = ctx.config.get('overrides', {})
|
|
|
|
# merge each client section, not the top level.
|
2019-10-11 15:57:47 +00:00
|
|
|
for client in config.keys():
|
2017-01-25 22:44:05 +00:00
|
|
|
if not config[client]:
|
|
|
|
config[client] = {}
|
|
|
|
teuthology.deep_merge(config[client], overrides.get('ragweed', {}))
|
|
|
|
|
|
|
|
log.debug('ragweed config is %s', config)
|
|
|
|
|
|
|
|
ragweed_conf = {}
|
|
|
|
for client in clients:
|
2019-09-05 19:50:26 +00:00
|
|
|
# use rgw_server endpoint if given, or default to same client
|
|
|
|
target = config[client].get('rgw_server', client)
|
|
|
|
|
|
|
|
endpoint = ctx.rgw.role_endpoints.get(target)
|
|
|
|
assert endpoint, 'ragweed: no rgw endpoint for {}'.format(target)
|
2018-02-21 16:19:48 +00:00
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
ragweed_conf[client] = ConfigObj(
|
|
|
|
indent_type='',
|
|
|
|
infile={
|
|
|
|
'rgw':
|
|
|
|
{
|
2019-09-05 19:50:26 +00:00
|
|
|
'host' : endpoint.dns_name,
|
2018-02-21 16:19:48 +00:00
|
|
|
'port' : endpoint.port,
|
2019-06-18 13:07:33 +00:00
|
|
|
'is_secure' : endpoint.cert is not None,
|
2017-01-25 22:44:05 +00:00
|
|
|
},
|
|
|
|
'fixtures' : {},
|
|
|
|
'user system' : {},
|
|
|
|
'user regular' : {},
|
2017-02-21 22:16:41 +00:00
|
|
|
'rados':
|
|
|
|
{
|
|
|
|
'ceph_conf' : '/etc/ceph/ceph.conf',
|
|
|
|
},
|
2017-01-25 22:44:05 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-02-22 00:34:01 +00:00
|
|
|
run_stages = {}
|
|
|
|
|
2017-01-25 22:44:05 +00:00
|
|
|
with contextutil.nested(
|
|
|
|
lambda: download(ctx=ctx, config=config),
|
|
|
|
lambda: create_users(ctx=ctx, config=dict(
|
|
|
|
clients=clients,
|
|
|
|
ragweed_conf=ragweed_conf,
|
2017-02-22 00:34:01 +00:00
|
|
|
config=config,
|
|
|
|
),
|
|
|
|
run_stages=run_stages),
|
2017-01-25 22:44:05 +00:00
|
|
|
lambda: configure(ctx=ctx, config=dict(
|
|
|
|
clients=config,
|
|
|
|
ragweed_conf=ragweed_conf,
|
2017-02-22 00:34:01 +00:00
|
|
|
),
|
|
|
|
run_stages=run_stages),
|
|
|
|
lambda: run_tests(ctx=ctx, config=config, run_stages=run_stages),
|
2017-01-25 22:44:05 +00:00
|
|
|
):
|
|
|
|
pass
|
|
|
|
yield
|