]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | import logging |
2 | import json | |
81eedcae | 3 | import time |
31f18b77 | 4 | |
f67539c2 | 5 | from io import StringIO |
e306af50 | 6 | |
7c673cae FG |
7 | from teuthology import misc as teuthology |
8 | ||
9 | log = logging.getLogger(__name__) | |
10 | ||
7c673cae | 11 | def rgwadmin(ctx, client, cmd, stdin=StringIO(), check_status=False, |
31f18b77 | 12 | format='json', decode=True, log_level=logging.DEBUG): |
7c673cae FG |
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', | |
9f95a23c | 19 | 'ceph-coverage', |
7c673cae | 20 | '{tdir}/archive/coverage'.format(tdir=testdir), |
9f95a23c | 21 | 'radosgw-admin', |
7c673cae FG |
22 | '--log-to-stderr', |
23 | '--format', format, | |
24 | '-n', client_with_id, | |
25 | '--cluster', cluster_name, | |
26 | ] | |
27 | pre.extend(cmd) | |
31f18b77 | 28 | log.log(log_level, 'rgwadmin: cmd=%s' % pre) |
9f95a23c | 29 | (remote,) = ctx.cluster.only(client).remotes.keys() |
7c673cae FG |
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() | |
31f18b77 FG |
39 | if not decode: |
40 | return (r, out) | |
7c673cae FG |
41 | j = None |
42 | if not r and out != '': | |
43 | try: | |
44 | j = json.loads(out) | |
31f18b77 | 45 | log.log(log_level, ' json result: %s' % j) |
7c673cae FG |
46 | except ValueError: |
47 | j = out | |
31f18b77 | 48 | log.log(log_level, ' raw result: %s' % j) |
7c673cae FG |
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 | ||
81eedcae | 69 | def wait_for_radosgw(url, remote): |
31f18b77 | 70 | """ poll the given url until it starts accepting connections |
7c673cae | 71 | |
31f18b77 FG |
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 | |
7c673cae | 74 | """ |
81eedcae TL |
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 |