2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Run rados gateway agent in test mode
|
|
|
|
"""
|
2013-07-31 06:14:32 +00:00
|
|
|
import contextlib
|
|
|
|
import logging
|
2013-08-03 03:28:46 +00:00
|
|
|
import argparse
|
2013-07-31 06:14:32 +00:00
|
|
|
|
2014-08-07 14:24:59 +00:00
|
|
|
from teuthology.orchestra import run
|
2013-07-31 06:14:32 +00:00
|
|
|
from teuthology import misc as teuthology
|
2014-08-07 14:24:59 +00:00
|
|
|
import util.rgw as rgw_utils
|
2013-07-31 06:14:32 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-08-09 04:14:56 +00:00
|
|
|
def run_radosgw_agent(ctx, config):
|
2013-07-31 06:14:32 +00:00
|
|
|
"""
|
2013-08-02 00:18:00 +00:00
|
|
|
Run a single radosgw-agent. See task() for config format.
|
2013-07-31 06:14:32 +00:00
|
|
|
"""
|
2013-08-09 04:14:56 +00:00
|
|
|
return_list = list()
|
|
|
|
for (client, cconf) in config.items():
|
|
|
|
# don't process entries that are not clients
|
|
|
|
if not client.startswith('client.'):
|
|
|
|
log.debug('key {data} does not start with \'client.\', moving on'.format(
|
|
|
|
data=client))
|
|
|
|
continue
|
|
|
|
|
|
|
|
src_client = cconf['src']
|
|
|
|
dest_client = cconf['dest']
|
|
|
|
|
|
|
|
src_zone = rgw_utils.zone_for_client(ctx, src_client)
|
|
|
|
dest_zone = rgw_utils.zone_for_client(ctx, dest_client)
|
|
|
|
|
|
|
|
log.info("source is %s", src_zone)
|
|
|
|
log.info("dest is %s", dest_zone)
|
|
|
|
|
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2013-08-09 04:14:56 +00:00
|
|
|
# figure out which branch to pull from
|
|
|
|
branch = cconf.get('force-branch', None)
|
|
|
|
if not branch:
|
|
|
|
branch = cconf.get('branch', 'master')
|
|
|
|
sha1 = cconf.get('sha1')
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'cd', testdir, run.Raw('&&'),
|
2013-10-29 19:23:08 +00:00
|
|
|
'git', 'clone',
|
2013-08-09 04:14:56 +00:00
|
|
|
'-b', branch,
|
2014-03-21 20:50:10 +00:00
|
|
|
# 'https://github.com/ceph/radosgw-agent.git',
|
2015-04-16 15:36:12 +00:00
|
|
|
'git://git.ceph.com/radosgw-agent.git',
|
2013-08-09 04:14:56 +00:00
|
|
|
'radosgw-agent.{client}'.format(client=client),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
if sha1 is not None:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'cd', testdir, run.Raw('&&'),
|
|
|
|
run.Raw('&&'),
|
|
|
|
'git', 'reset', '--hard', sha1,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'cd', testdir, run.Raw('&&'),
|
|
|
|
'cd', 'radosgw-agent.{client}'.format(client=client),
|
|
|
|
run.Raw('&&'),
|
|
|
|
'./bootstrap',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
src_host, src_port = rgw_utils.get_zone_host_and_port(ctx, src_client,
|
|
|
|
src_zone)
|
|
|
|
dest_host, dest_port = rgw_utils.get_zone_host_and_port(ctx, dest_client,
|
|
|
|
dest_zone)
|
|
|
|
src_access, src_secret = rgw_utils.get_zone_system_keys(ctx, src_client,
|
|
|
|
src_zone)
|
|
|
|
dest_access, dest_secret = rgw_utils.get_zone_system_keys(ctx, dest_client,
|
|
|
|
dest_zone)
|
|
|
|
sync_scope = cconf.get('sync-scope', None)
|
|
|
|
port = cconf.get('port', 8000)
|
|
|
|
daemon_name = '{host}.{port}.syncdaemon'.format(host=remote.name, port=port)
|
|
|
|
in_args=[
|
2013-10-29 19:23:08 +00:00
|
|
|
'daemon-helper',
|
|
|
|
'kill',
|
|
|
|
'{tdir}/radosgw-agent.{client}/radosgw-agent'.format(tdir=testdir,
|
|
|
|
client=client),
|
|
|
|
'-v',
|
|
|
|
'--src-access-key', src_access,
|
|
|
|
'--src-secret-key', src_secret,
|
|
|
|
'--source', "http://{addr}:{port}".format(addr=src_host, port=src_port),
|
|
|
|
'--dest-access-key', dest_access,
|
|
|
|
'--dest-secret-key', dest_secret,
|
2014-03-28 00:20:54 +00:00
|
|
|
'--max-entries', str(cconf.get('max-entries', 1000)),
|
2013-10-29 19:23:08 +00:00
|
|
|
'--log-file', '{tdir}/archive/rgw_sync_agent.{client}.log'.format(
|
|
|
|
tdir=testdir,
|
|
|
|
client=client),
|
2014-03-17 18:54:52 +00:00
|
|
|
'--object-sync-timeout', '30',
|
2013-10-29 19:23:08 +00:00
|
|
|
]
|
2013-10-29 20:10:05 +00:00
|
|
|
|
|
|
|
if cconf.get('metadata-only', False):
|
|
|
|
in_args.append('--metadata-only')
|
|
|
|
|
2013-08-09 04:14:56 +00:00
|
|
|
# the test server and full/incremental flags are mutually exclusive
|
|
|
|
if sync_scope is None:
|
|
|
|
in_args.append('--test-server-host')
|
2013-10-29 19:23:08 +00:00
|
|
|
in_args.append('0.0.0.0')
|
2013-08-09 04:14:56 +00:00
|
|
|
in_args.append('--test-server-port')
|
|
|
|
in_args.append(str(port))
|
2013-08-17 01:32:29 +00:00
|
|
|
log.debug('Starting a sync test server on {client}'.format(client=client))
|
2014-03-17 18:54:52 +00:00
|
|
|
# Stash the radosgw-agent server / port # for use by subsequent tasks
|
2013-08-24 02:21:13 +00:00
|
|
|
ctx.radosgw_agent.endpoint = (client, str(port))
|
2013-08-09 04:14:56 +00:00
|
|
|
else:
|
|
|
|
in_args.append('--sync-scope')
|
|
|
|
in_args.append(sync_scope)
|
2013-08-17 01:32:29 +00:00
|
|
|
log.debug('Starting a {scope} sync on {client}'.format(scope=sync_scope,client=client))
|
2013-08-09 04:14:56 +00:00
|
|
|
|
2013-10-29 20:03:55 +00:00
|
|
|
# positional arg for destination must come last
|
|
|
|
in_args.append("http://{addr}:{port}".format(addr=dest_host,
|
|
|
|
port=dest_port))
|
|
|
|
|
2013-08-09 04:14:56 +00:00
|
|
|
return_list.append((client, remote.run(
|
|
|
|
args=in_args,
|
2013-10-29 19:23:08 +00:00
|
|
|
wait=False,
|
|
|
|
stdin=run.PIPE,
|
|
|
|
logger=log.getChild(daemon_name),
|
|
|
|
)))
|
2013-08-09 04:14:56 +00:00
|
|
|
return return_list
|
2013-08-02 00:18:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run radosgw-agents in test mode.
|
|
|
|
|
|
|
|
Configuration is clients to run the agents on, with settings for
|
|
|
|
source client, destination client, and port to listen on. Binds
|
|
|
|
to 0.0.0.0. Port defaults to 8000. This must be run on clients
|
|
|
|
that have the correct zone root pools and rgw zone set in
|
|
|
|
ceph.conf, or the task cannot read the region information from the
|
2013-10-29 19:23:08 +00:00
|
|
|
cluster.
|
2013-08-09 04:14:56 +00:00
|
|
|
|
|
|
|
By default, this task will start an HTTP server that will trigger full
|
2013-10-29 19:23:08 +00:00
|
|
|
or incremental syncs based on requests made to it.
|
2013-08-09 04:14:56 +00:00
|
|
|
Alternatively, a single full sync can be triggered by
|
|
|
|
specifying 'sync-scope: full' or a loop of incremental syncs can be triggered
|
|
|
|
by specifying 'sync-scope: incremental' (the loop will sleep
|
2013-10-29 20:10:05 +00:00
|
|
|
'--incremental-sync-delay' seconds between each sync, default is 30 seconds).
|
|
|
|
|
|
|
|
By default, both data and metadata are synced. To only sync
|
|
|
|
metadata, for example because you want to sync between regions,
|
|
|
|
set metadata-only: true.
|
2013-10-29 19:23:08 +00:00
|
|
|
|
2013-08-09 04:14:56 +00:00
|
|
|
An example::
|
2013-08-02 00:18:00 +00:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
conf:
|
|
|
|
client.0:
|
|
|
|
rgw zone = foo
|
|
|
|
rgw zone root pool = .root.pool
|
|
|
|
client.1:
|
|
|
|
rgw zone = bar
|
|
|
|
rgw zone root pool = .root.pool2
|
|
|
|
- rgw: # region configuration omitted for brevity
|
2013-08-02 00:23:40 +00:00
|
|
|
- radosgw-agent:
|
2013-08-02 00:18:00 +00:00
|
|
|
client.0:
|
2013-08-09 04:14:56 +00:00
|
|
|
branch: wip-next-feature-branch
|
2013-08-02 00:18:00 +00:00
|
|
|
src: client.0
|
|
|
|
dest: client.1
|
2013-08-09 04:14:56 +00:00
|
|
|
sync-scope: full
|
2013-10-29 20:10:05 +00:00
|
|
|
metadata-only: true
|
2013-08-02 00:18:00 +00:00
|
|
|
# port: 8000 (default)
|
|
|
|
client.1:
|
|
|
|
src: client.1
|
|
|
|
dest: client.0
|
|
|
|
port: 8001
|
|
|
|
"""
|
|
|
|
assert isinstance(config, dict), 'rgw_sync_agent requires a dictionary config'
|
|
|
|
log.debug("config is %s", config)
|
|
|
|
|
2013-08-09 04:14:56 +00:00
|
|
|
overrides = ctx.config.get('overrides', {})
|
|
|
|
# merge each client section, but only if it exists in config since there isn't
|
|
|
|
# a sensible default action for this task
|
|
|
|
for client in config.iterkeys():
|
|
|
|
if config[client]:
|
|
|
|
log.debug('config[{client}]: {data}'.format(client=client, data=config[client]))
|
|
|
|
teuthology.deep_merge(config[client], overrides.get('radosgw-agent', {}))
|
2013-08-03 03:28:46 +00:00
|
|
|
|
|
|
|
ctx.radosgw_agent = argparse.Namespace()
|
2013-08-15 19:51:51 +00:00
|
|
|
ctx.radosgw_agent.config = config
|
2013-08-03 03:28:46 +00:00
|
|
|
|
2013-08-09 04:14:56 +00:00
|
|
|
procs = run_radosgw_agent(ctx, config)
|
2013-08-02 00:18:00 +00:00
|
|
|
|
2013-08-03 03:28:46 +00:00
|
|
|
ctx.radosgw_agent.procs = procs
|
|
|
|
|
2013-07-31 06:14:32 +00:00
|
|
|
try:
|
2013-08-02 00:18:00 +00:00
|
|
|
yield
|
2013-07-31 06:14:32 +00:00
|
|
|
finally:
|
2013-08-02 00:18:00 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
|
|
|
try:
|
|
|
|
for client, proc in procs:
|
|
|
|
log.info("shutting down sync agent on %s", client)
|
|
|
|
proc.stdin.close()
|
2014-05-30 19:32:38 +00:00
|
|
|
proc.wait()
|
2013-08-02 00:18:00 +00:00
|
|
|
finally:
|
|
|
|
for client, proc in procs:
|
|
|
|
ctx.cluster.only(client).run(
|
|
|
|
args=[
|
|
|
|
'rm', '-rf',
|
|
|
|
'{tdir}/radosgw-agent.{client}'.format(tdir=testdir,
|
|
|
|
client=client)
|
|
|
|
]
|
|
|
|
)
|