summaryrefslogtreecommitdiffstats
path: root/qa/tasks/autotest.py
blob: 80c3fc9d219741519e846be047a52f6542983afb (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
Run an autotest test on the ceph cluster.
"""
import json
import logging
import os

from teuthology import misc as teuthology
from teuthology.parallel import parallel
from teuthology.orchestra import run

log = logging.getLogger(__name__)

def task(ctx, config):
    """
    Run an autotest test on the ceph cluster.

    Only autotest client tests are supported.

    The config is a mapping from role name to list of tests to run on
    that client.

    For example::

        tasks:
        - ceph:
        - ceph-fuse: [client.0, client.1]
        - autotest:
            client.0: [dbench]
            client.1: [bonnie]

    You can also specify a list of tests to run on all clients::

        tasks:
        - ceph:
        - ceph-fuse:
        - autotest:
            all: [dbench]
    """
    assert isinstance(config, dict)
    config = teuthology.replace_all_with_clients(ctx.cluster, config)
    log.info('Setting up autotest...')
    testdir = teuthology.get_testdir(ctx)
    with parallel() as p:
        for role in config.keys():
            (remote,) = ctx.cluster.only(role).remotes.keys()
            p.spawn(_download, testdir, remote)

    log.info('Making a separate scratch dir for every client...')
    for role in config.keys():
        assert isinstance(role, str)
        PREFIX = 'client.'
        assert role.startswith(PREFIX)
        id_ = role[len(PREFIX):]
        (remote,) = ctx.cluster.only(role).remotes.keys()
        mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
        scratch = os.path.join(mnt, 'client.{id}'.format(id=id_))
        remote.run(
            args=[
                'sudo',
                'install',
                '-d',
                '-m', '0755',
                '--owner={user}'.format(user='ubuntu'), #TODO
                '--',
                scratch,
                ],
            )

    with parallel() as p:
        for role, tests in config.items():
            (remote,) = ctx.cluster.only(role).remotes.keys()
            p.spawn(_run_tests, testdir, remote, role, tests)

def _download(testdir, remote):
    """
    Download.  Does not explicitly support muliple tasks in a single run.
    """
    remote.run(
        args=[
            # explicitly does not support multiple autotest tasks
            # in a single run; the result archival would conflict
            'mkdir', '{tdir}/archive/autotest'.format(tdir=testdir),
            run.Raw('&&'),
            'mkdir', '{tdir}/autotest'.format(tdir=testdir),
            run.Raw('&&'),
            'wget',
            '-nv',
            '--no-check-certificate',
            'https://github.com/ceph/autotest/tarball/ceph',
            '-O-',
            run.Raw('|'),
            'tar',
            '-C', '{tdir}/autotest'.format(tdir=testdir),
            '-x',
            '-z',
            '-f-',
            '--strip-components=1',
            ],
        )

def _run_tests(testdir, remote, role, tests):
    """
    Spawned to run test on remote site
    """
    assert isinstance(role, str)
    PREFIX = 'client.'
    assert role.startswith(PREFIX)
    id_ = role[len(PREFIX):]
    mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
    scratch = os.path.join(mnt, 'client.{id}'.format(id=id_))

    assert isinstance(tests, list)
    for idx, testname in enumerate(tests):
        log.info('Running autotest client test #%d: %s...', idx, testname)

        tag = 'client.{id}.num{idx}.{testname}'.format(
            idx=idx,
            testname=testname,
            id=id_,
            )
        control = '{tdir}/control.{tag}'.format(tdir=testdir, tag=tag)
        remote.write_file(
            path=control,
            data='import json; data=json.loads({data!r}); job.run_test(**data)'.format(
                data=json.dumps(dict(
                        url=testname,
                        dir=scratch,
                        # TODO perhaps tag
                        # results will be in {testdir}/autotest/client/results/dbench
                        # or {testdir}/autotest/client/results/dbench.{tag}
                        )),
                ),
            )
        remote.run(
            args=[
                '{tdir}/autotest/client/bin/autotest'.format(tdir=testdir),
                '--verbose',
                '--harness=simple',
                '--tag={tag}'.format(tag=tag),
                control,
                run.Raw('3>&1'),
                ],
            )

        remote.run(
            args=[
                'rm', '-rf', '--', control,
                ],
            )

        remote.run(
            args=[
                'mv',
                '--',
                '{tdir}/autotest/client/results/{tag}'.format(tdir=testdir, tag=tag),
                '{tdir}/archive/autotest/{tag}'.format(tdir=testdir, tag=tag),
                ],
            )

    remote.run(
        args=[
            'rm', '-rf', '--', '{tdir}/autotest'.format(tdir=testdir),
            ],
        )