Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / tasks / filestore_idempotent.py
1 """
2 Filestore/filejournal handler
3 """
4 import logging
5 from teuthology.orchestra import run
6 import random
7
8 from teuthology import misc as teuthology
9
10 log = logging.getLogger(__name__)
11
12 def task(ctx, config):
13     """
14     Test filestore/filejournal handling of non-idempotent events.
15
16     Currently this is a kludge; we require the ceph task preceeds us just
17     so that we get the tarball installed to run the test binary.
18
19     :param ctx: Context
20     :param config: Configuration
21     """
22     assert config is None or isinstance(config, list) \
23         or isinstance(config, dict), \
24         "task only supports a list or dictionary for configuration"
25     all_clients = ['client.{id}'.format(id=id_)
26                    for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
27     if config is None:
28         config = all_clients
29     if isinstance(config, list):
30         config = dict.fromkeys(config)
31     clients = config.keys()
32
33     # just use the first client...
34     client = clients[0];
35     (remote,) = ctx.cluster.only(client).remotes.iterkeys()
36
37     testdir = teuthology.get_testdir(ctx)
38
39     dir = '%s/ceph.data/test.%s' % (testdir, client)
40
41     seed = str(int(random.uniform(1,100)))
42
43     try:
44         log.info('creating a working dir')
45         remote.run(args=['mkdir', dir])
46         remote.run(
47             args=[
48                 'cd', dir,
49                 run.Raw('&&'),
50                 'wget','-q', '-Orun_seed_to.sh',
51                 'http://git.ceph.com/?p=ceph.git;a=blob_plain;f=src/test/objectstore/run_seed_to.sh;hb=HEAD',
52                 run.Raw('&&'),
53                 'wget','-q', '-Orun_seed_to_range.sh',
54                 'http://git.ceph.com/?p=ceph.git;a=blob_plain;f=src/test/objectstore/run_seed_to_range.sh;hb=HEAD',
55                 run.Raw('&&'),
56                 'chmod', '+x', 'run_seed_to.sh', 'run_seed_to_range.sh',
57                 ]);
58
59         log.info('running a series of tests')
60         proc = remote.run(
61             args=[
62                 'cd', dir,
63                 run.Raw('&&'),
64                 './run_seed_to_range.sh', seed, '50', '300',
65                 ],
66             wait=False,
67             check_status=False)
68         result = proc.wait()
69
70         if result != 0:
71             remote.run(
72                 args=[
73                     'cp', '-a', dir, '{tdir}/archive/idempotent_failure'.format(tdir=testdir),
74                     ])
75             raise Exception("./run_seed_to_range.sh errored out")
76
77     finally:
78         remote.run(args=[
79                 'rm', '-rf', '--', dir
80                 ])
81