Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / tasks / rbd_fsx.py
1 """
2 Run fsx on an rbd image
3 """
4 import contextlib
5 import logging
6
7 from teuthology.parallel import parallel
8 from teuthology import misc as teuthology
9
10 log = logging.getLogger(__name__)
11
12 @contextlib.contextmanager
13 def task(ctx, config):
14     """
15     Run fsx on an rbd image.
16
17     Currently this requires running as client.admin
18     to create a pool.
19
20     Specify which clients to run on as a list::
21
22       tasks:
23         ceph:
24         rbd_fsx:
25           clients: [client.0, client.1]
26
27     You can optionally change some properties of fsx:
28
29       tasks:
30         ceph:
31         rbd_fsx:
32           clients: <list of clients>
33           seed: <random seed number, or 0 to use the time>
34           ops: <number of operations to do>
35           size: <maximum image size in bytes>
36           valgrind: [--tool=<valgrind tool>]
37     """
38     log.info('starting rbd_fsx...')
39     with parallel() as p:
40         for role in config['clients']:
41             p.spawn(_run_one_client, ctx, config, role)
42     yield
43
44 def _run_one_client(ctx, config, role):
45     """Spawned task that runs the client"""
46     krbd = config.get('krbd', False)
47     nbd = config.get('nbd', False)
48     testdir = teuthology.get_testdir(ctx)
49     (remote,) = ctx.cluster.only(role).remotes.iterkeys()
50
51     args = []
52     if krbd or nbd:
53         args.append('sudo') # rbd(-nbd) map/unmap need privileges
54     args.extend([
55         'adjust-ulimits',
56         'ceph-coverage',
57         '{tdir}/archive/coverage'.format(tdir=testdir)
58     ])
59
60     overrides = ctx.config.get('overrides', {})
61     teuthology.deep_merge(config, overrides.get('rbd_fsx', {}))
62
63     if config.get('valgrind'):
64         args = teuthology.get_valgrind_args(
65             testdir,
66             'fsx_{id}'.format(id=role),
67             args,
68             config.get('valgrind')
69         )
70
71     args.extend([
72         'ceph_test_librbd_fsx',
73         '-d', # debug output for all operations
74         '-W', '-R', # mmap doesn't work with rbd
75         '-p', str(config.get('progress_interval', 100)), # show progress
76         '-P', '{tdir}/archive'.format(tdir=testdir),
77         '-r', str(config.get('readbdy',1)),
78         '-w', str(config.get('writebdy',1)),
79         '-t', str(config.get('truncbdy',1)),
80         '-h', str(config.get('holebdy',1)),
81         '-l', str(config.get('size', 250000000)),
82         '-S', str(config.get('seed', 0)),
83         '-N', str(config.get('ops', 1000)),
84     ])
85     if krbd:
86         args.append('-K') # -K enables krbd mode
87     if nbd:
88         args.append('-M') # -M enables nbd mode
89     if config.get('direct_io', False):
90         args.append('-Z') # -Z use direct IO
91     if not config.get('randomized_striping', True):
92         args.append('-U') # -U disables randomized striping
93     if not config.get('punch_holes', True):
94         args.append('-H') # -H disables discard ops
95     if config.get('journal_replay', False):
96         args.append('-j') # -j replay all IO events from journal
97     args.extend([
98         'pool_{pool}'.format(pool=role),
99         'image_{image}'.format(image=role),
100     ])
101
102     remote.run(args=args)