]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/util/rgw.py
91652198b8a6f57dc047b503aaf4d859858283c0
[ceph.git] / ceph / qa / tasks / util / rgw.py
1 from cStringIO import StringIO
2 import logging
3 import json
4 import time
5
6 from teuthology import misc as teuthology
7
8 log = logging.getLogger(__name__)
9
10 def rgwadmin(ctx, client, cmd, stdin=StringIO(), check_status=False,
11 format='json', decode=True, log_level=logging.DEBUG):
12 log.info('rgwadmin: {client} : {cmd}'.format(client=client,cmd=cmd))
13 testdir = teuthology.get_testdir(ctx)
14 cluster_name, daemon_type, client_id = teuthology.split_role(client)
15 client_with_id = daemon_type + '.' + client_id
16 pre = [
17 'adjust-ulimits',
18 'ceph-coverage',
19 '{tdir}/archive/coverage'.format(tdir=testdir),
20 'radosgw-admin',
21 '--log-to-stderr',
22 '--format', format,
23 '-n', client_with_id,
24 '--cluster', cluster_name,
25 ]
26 pre.extend(cmd)
27 log.log(log_level, 'rgwadmin: cmd=%s' % pre)
28 (remote,) = ctx.cluster.only(client).remotes.keys()
29 proc = remote.run(
30 args=pre,
31 check_status=check_status,
32 stdout=StringIO(),
33 stderr=StringIO(),
34 stdin=stdin,
35 )
36 r = proc.exitstatus
37 out = proc.stdout.getvalue()
38 if not decode:
39 return (r, out)
40 j = None
41 if not r and out != '':
42 try:
43 j = json.loads(out)
44 log.log(log_level, ' json result: %s' % j)
45 except ValueError:
46 j = out
47 log.log(log_level, ' raw result: %s' % j)
48 return (r, j)
49
50 def get_user_summary(out, user):
51 """Extract the summary for a given user"""
52 user_summary = None
53 for summary in out['summary']:
54 if summary.get('user') == user:
55 user_summary = summary
56
57 if not user_summary:
58 raise AssertionError('No summary info found for user: %s' % user)
59
60 return user_summary
61
62 def get_user_successful_ops(out, user):
63 summary = out['summary']
64 if len(summary) == 0:
65 return 0
66 return get_user_summary(out, user)['total']['successful_ops']
67
68 def wait_for_radosgw(url, remote):
69 """ poll the given url until it starts accepting connections
70
71 add_daemon() doesn't wait until radosgw finishes startup, so this is used
72 to avoid racing with later tasks that expect radosgw to be up and listening
73 """
74 # TODO: use '--retry-connrefused --retry 8' when teuthology is running on
75 # Centos 8 and other OS's with an updated version of curl
76 curl_cmd = ['curl',
77 url]
78 exit_status = 0
79 num_retries = 8
80 for seconds in range(num_retries):
81 proc = remote.run(
82 args=curl_cmd,
83 check_status=False,
84 stdout=StringIO(),
85 stderr=StringIO(),
86 stdin=StringIO(),
87 )
88 exit_status = proc.exitstatus
89 if exit_status == 0:
90 break
91 time.sleep(2**seconds)
92
93 assert exit_status == 0