10 import util.rgw as rgw_utils
12 from teuthology.orchestra import run
13 from teuthology import misc as teuthology
14 from teuthology import contextutil
15 from teuthology.orchestra.run import CommandFailedError
16 from util.rgw import rgwadmin, wait_for_radosgw
17 from util.rados import (rados, create_ec_pool,
18 create_replicated_pool,
21 log = logging.getLogger(__name__)
23 @contextlib.contextmanager
24 def start_rgw(ctx, config, clients):
26 Start rgw on remote sites.
28 log.info('Starting rgw...')
29 testdir = teuthology.get_testdir(ctx)
30 for client in clients:
31 (remote,) = ctx.cluster.only(client).remotes.iterkeys()
32 cluster_name, daemon_type, client_id = teuthology.split_role(client)
33 client_with_id = daemon_type + '.' + client_id
34 client_with_cluster = cluster_name + '.' + client_with_id
36 client_config = config.get(client)
37 if client_config is None:
39 log.info("rgw %s config is %s", client, client_config)
44 '{tdir}/archive/coverage'.format(tdir=testdir),
51 log.info("Using %s as radosgw frontend", ctx.rgw.frontend)
53 host, port = ctx.rgw.role_endpoints[client]
56 '{frontend} port={port}'.format(frontend=ctx.rgw.frontend, port=port),
58 '--cluster', cluster_name,
59 '-k', '/etc/ceph/{client_with_cluster}.keyring'.format(client_with_cluster=client_with_cluster),
61 '/var/log/ceph/rgw.{client_with_cluster}.log'.format(client_with_cluster=client_with_cluster),
62 '--rgw_ops_log_socket_path',
63 '{tdir}/rgw.opslog.{client_with_cluster}.sock'.format(tdir=testdir,
64 client_with_cluster=client_with_cluster),
69 '/var/log/ceph/rgw.{client_with_cluster}.stdout'.format(tdir=testdir,
70 client_with_cluster=client_with_cluster),
74 if client_config.get('valgrind'):
75 cmd_prefix = teuthology.get_valgrind_args(
79 client_config.get('valgrind')
82 run_cmd = list(cmd_prefix)
83 run_cmd.extend(rgw_cmd)
85 ctx.daemons.add_daemon(
86 remote, 'rgw', client_with_id,
89 logger=log.getChild(client),
94 # XXX: add_daemon() doesn't let us wait until radosgw finishes startup
95 for client in config.keys():
96 host, port = ctx.rgw.role_endpoints[client]
97 endpoint = 'http://{host}:{port}/'.format(host=host, port=port)
98 log.info('Polling {client} until it starts accepting connections on {endpoint}'.format(client=client, endpoint=endpoint))
99 wait_for_radosgw(endpoint)
104 for client in config.iterkeys():
105 cluster_name, daemon_type, client_id = teuthology.split_role(client)
106 client_with_id = daemon_type + '.' + client_id
107 client_with_cluster = cluster_name + '.' + client_with_id
108 ctx.daemons.get_daemon('rgw', client_with_id, cluster_name).stop()
109 ctx.cluster.only(client).run(
113 '{tdir}/rgw.opslog.{client}.sock'.format(tdir=testdir,
114 client=client_with_cluster),
118 def assign_ports(ctx, config):
120 Assign port numberst starting with port 7280.
124 for remote, roles_for_host in ctx.cluster.remotes.iteritems():
125 for role in roles_for_host:
127 role_endpoints[role] = (remote.name.split('@')[1], port)
130 return role_endpoints
132 @contextlib.contextmanager
133 def create_pools(ctx, clients):
134 """Create replicated or erasure coded data pools for rgw."""
136 log.info('Creating data pools')
137 for client in clients:
138 log.debug("Obtaining remote for client {}".format(client))
139 (remote,) = ctx.cluster.only(client).remotes.iterkeys()
140 data_pool = '.rgw.buckets'
141 cluster_name, daemon_type, client_id = teuthology.split_role(client)
143 if ctx.rgw.ec_data_pool:
144 create_ec_pool(remote, data_pool, client, 64,
145 ctx.rgw.erasure_code_profile, cluster_name, 'rgw')
147 create_replicated_pool(remote, data_pool, 64, cluster_name, 'rgw')
148 if ctx.rgw.cache_pools:
149 create_cache_pool(remote, data_pool, data_pool + '.cache', 64,
150 64*1024*1024, cluster_name)
151 log.debug('Pools created')
154 @contextlib.contextmanager
155 def configure_compression(ctx, clients, compression):
156 """ set a compression type in the default zone placement """
157 log.info('Configuring compression type = %s', compression)
158 for client in clients:
159 # XXX: the 'default' zone and zonegroup aren't created until we run RGWRados::init_complete().
160 # issue a 'radosgw-admin user list' command to trigger this
161 rgwadmin(ctx, client, cmd=['user', 'list'], check_status=True)
163 rgwadmin(ctx, client,
164 cmd=['zone', 'placement', 'modify', '--rgw-zone', 'default',
165 '--placement-id', 'default-placement',
166 '--compression', compression],
170 @contextlib.contextmanager
171 def task(ctx, config):
173 For example, to run rgw on all clients::
179 To only run on certain clients::
183 - rgw: [client.0, client.3]
193 To run radosgw through valgrind:
199 valgrind: [--tool=memcheck]
201 valgrind: [--tool=memcheck]
204 config = dict(('client.{id}'.format(id=id_), None)
205 for id_ in teuthology.all_roles_of_type(
206 ctx.cluster, 'client'))
207 elif isinstance(config, list):
208 config = dict((name, None) for name in config)
210 clients = config.keys() # http://tracker.ceph.com/issues/20417
212 overrides = ctx.config.get('overrides', {})
213 teuthology.deep_merge(config, overrides.get('rgw', {}))
215 role_endpoints = assign_ports(ctx, config)
216 ctx.rgw = argparse.Namespace()
217 ctx.rgw.role_endpoints = role_endpoints
219 ctx.rgw.ec_data_pool = bool(config.pop('ec-data-pool', False))
220 ctx.rgw.erasure_code_profile = config.pop('erasure_code_profile', {})
221 ctx.rgw.cache_pools = bool(config.pop('cache-pools', False))
222 ctx.rgw.frontend = config.pop('frontend', 'civetweb')
223 ctx.rgw.compression_type = config.pop('compression type', None)
224 ctx.rgw.config = config
226 log.debug("config is {}".format(config))
227 log.debug("client list is {}".format(clients))
229 lambda: create_pools(ctx=ctx, clients=clients),
231 if ctx.rgw.compression_type:
233 lambda: configure_compression(ctx=ctx, clients=clients,
234 compression=ctx.rgw.compression_type),
237 lambda: start_rgw(ctx=ctx, config=config, clients=clients),
240 with contextutil.nested(*subtasks):