]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/util/rgw.py
update sources to v12.1.0
[ceph.git] / ceph / qa / tasks / util / rgw.py
CommitLineData
7c673cae
FG
1from cStringIO import StringIO
2import logging
3import json
4import requests
31f18b77
FG
5
6from requests.packages.urllib3 import PoolManager
7c673cae
FG
7from requests.packages.urllib3.util import Retry
8from urlparse import urlparse
9
10from teuthology.orchestra.connection import split_user
11from teuthology import misc as teuthology
12
13log = logging.getLogger(__name__)
14
7c673cae 15def rgwadmin(ctx, client, cmd, stdin=StringIO(), check_status=False,
31f18b77 16 format='json', decode=True, log_level=logging.DEBUG):
7c673cae
FG
17 log.info('rgwadmin: {client} : {cmd}'.format(client=client,cmd=cmd))
18 testdir = teuthology.get_testdir(ctx)
19 cluster_name, daemon_type, client_id = teuthology.split_role(client)
20 client_with_id = daemon_type + '.' + client_id
21 pre = [
22 'adjust-ulimits',
23 'ceph-coverage'.format(tdir=testdir),
24 '{tdir}/archive/coverage'.format(tdir=testdir),
25 'radosgw-admin'.format(tdir=testdir),
26 '--log-to-stderr',
27 '--format', format,
28 '-n', client_with_id,
29 '--cluster', cluster_name,
30 ]
31 pre.extend(cmd)
31f18b77 32 log.log(log_level, 'rgwadmin: cmd=%s' % pre)
7c673cae
FG
33 (remote,) = ctx.cluster.only(client).remotes.iterkeys()
34 proc = remote.run(
35 args=pre,
36 check_status=check_status,
37 stdout=StringIO(),
38 stderr=StringIO(),
39 stdin=stdin,
40 )
41 r = proc.exitstatus
42 out = proc.stdout.getvalue()
31f18b77
FG
43 if not decode:
44 return (r, out)
7c673cae
FG
45 j = None
46 if not r and out != '':
47 try:
48 j = json.loads(out)
31f18b77 49 log.log(log_level, ' json result: %s' % j)
7c673cae
FG
50 except ValueError:
51 j = out
31f18b77 52 log.log(log_level, ' raw result: %s' % j)
7c673cae
FG
53 return (r, j)
54
55def get_user_summary(out, user):
56 """Extract the summary for a given user"""
57 user_summary = None
58 for summary in out['summary']:
59 if summary.get('user') == user:
60 user_summary = summary
61
62 if not user_summary:
63 raise AssertionError('No summary info found for user: %s' % user)
64
65 return user_summary
66
67def get_user_successful_ops(out, user):
68 summary = out['summary']
69 if len(summary) == 0:
70 return 0
71 return get_user_summary(out, user)['total']['successful_ops']
72
31f18b77
FG
73def wait_for_radosgw(url):
74 """ poll the given url until it starts accepting connections
7c673cae 75
31f18b77
FG
76 add_daemon() doesn't wait until radosgw finishes startup, so this is used
77 to avoid racing with later tasks that expect radosgw to be up and listening
7c673cae 78 """
31f18b77
FG
79 # use a connection pool with retry/backoff to poll until it starts listening
80 http = PoolManager(retries=Retry(connect=8, backoff_factor=1))
81 http.request('GET', url)