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