summaryrefslogtreecommitdiffstats
path: root/qa/tasks/util/rgw.py
blob: 59c801028f937f343e8ea14546dc350a6d702a2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import logging
import json
import time

from io import StringIO

from teuthology import misc as teuthology

log = logging.getLogger(__name__)

def rgwadmin(ctx, client, cmd, stdin=StringIO(), check_status=False,
             omit_sudo=False, omit_tdir=False, format='json', decode=True,
             log_level=logging.DEBUG):
    log.info('rgwadmin: {client} : {cmd}'.format(client=client,cmd=cmd))
    testdir = teuthology.get_testdir(ctx)
    cluster_name, daemon_type, client_id = teuthology.split_role(client)
    client_with_id = daemon_type + '.' + client_id
    pre = [
        'adjust-ulimits',
        'ceph-coverage']
    if not omit_tdir:
        pre.append(
            '{tdir}/archive/coverage'.format(tdir=testdir))
    pre.extend([
        'radosgw-admin',
        '--log-to-stderr',
        '--format', format,
        '-n',  client_with_id,
        '--cluster', cluster_name,
        ])
    pre.extend(cmd)
    log.log(log_level, 'rgwadmin: cmd=%s' % pre)
    (remote,) = ctx.cluster.only(client).remotes.keys()
    proc = remote.run(
        args=pre,
        check_status=check_status,
        omit_sudo=omit_sudo,
        stdout=StringIO(),
        stderr=StringIO(),
        stdin=stdin,
        )
    r = proc.exitstatus
    out = proc.stdout.getvalue()
    if not decode:
        return (r, out)
    j = None
    if not r and out != '':
        try:
            j = json.loads(out)
            log.log(log_level, ' json result: %s' % j)
        except ValueError:
            j = out
            log.log(log_level, ' raw result: %s' % j)
    return (r, j)

def get_user_summary(out, user):
    """Extract the summary for a given user"""
    user_summary = None
    for summary in out['summary']:
        if summary.get('user') == user:
            user_summary = summary

    if not user_summary:
        raise AssertionError('No summary info found for user: %s' % user)

    return user_summary

def get_user_successful_ops(out, user):
    summary = out['summary']
    if len(summary) == 0:
        return 0
    return get_user_summary(out, user)['total']['successful_ops']

def wait_for_radosgw(url, remote):
    """ poll the given url until it starts accepting connections

    add_daemon() doesn't wait until radosgw finishes startup, so this is used
    to avoid racing with later tasks that expect radosgw to be up and listening
    """
    # TODO: use '--retry-connrefused --retry 8' when teuthology is running on
    # Centos 8 and other OS's with an updated version of curl
    curl_cmd = ['curl',
                url]
    exit_status = 0
    num_retries = 8
    for seconds in range(num_retries):
        proc = remote.run(
            args=curl_cmd,
            check_status=False,
            stdout=StringIO(),
            stderr=StringIO(),
            stdin=StringIO(),
            )
        exit_status = proc.exitstatus
        if exit_status == 0:
            break
        time.sleep(2**seconds)

    assert exit_status == 0