Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / tasks / rbd_mirror.py
1 """
2 Task for running rbd mirroring daemons and configuring mirroring
3 """
4
5 import logging
6
7 from teuthology.orchestra import run
8 from teuthology import misc
9 from teuthology.exceptions import ConfigError
10 from teuthology.task import Task
11 from util import get_remote_for_role
12
13 log = logging.getLogger(__name__)
14
15
16 class RBDMirror(Task):
17     """
18     Run an rbd-mirror daemon to sync rbd images between clusters.
19
20     This requires two clients (one from each cluster) on the same host
21     to connect with. The pool configuration should be adjusted by later
22     test scripts to include the remote client and cluster name. This task
23     just needs to know how to connect to the local cluster.
24
25     For example:
26
27         roles:
28         - [primary.mon.a, primary.osd.0, primary.osd.1, primary.osd.2]
29         - [secondary.mon.a, secondary.osd.0, secondary.osd.1, secondary.osd.2]
30         - [primary.client.mirror, secondary.client.mirror]
31         tasks:
32         - ceph:
33             cluster: primary
34         - ceph:
35             cluster: secondary
36         - rbd-mirror:
37             client: primary.client.mirror
38
39     To mirror back to the primary cluster as well, add another
40     rbd_mirror instance:
41
42         - rbd-mirror:
43             client: secondary.client.mirror
44
45     Possible options for this task are:
46
47         client: role - ceph client to connect as
48         valgrind: [--tool=<valgrind tool>] - none by default
49         coverage: bool - whether this run may be collecting coverage data
50     """
51     def __init__(self, ctx, config):
52         super(RBDMirror, self).__init__(ctx, config)
53         self.log = log
54
55     def setup(self):
56         super(RBDMirror, self).setup()
57         try:
58             self.client = self.config['client']
59         except KeyError:
60             raise ConfigError('rbd-mirror requires a client to connect with')
61
62         self.cluster_name, type_, self.client_id = misc.split_role(self.client)
63
64         if type_ != 'client':
65             msg = 'client role ({0}) must be a client'.format(self.client)
66             raise ConfigError(msg)
67
68         self.remote = get_remote_for_role(self.ctx, self.client)
69
70     def begin(self):
71         super(RBDMirror, self).begin()
72         testdir = misc.get_testdir(self.ctx)
73         daemon_signal = 'kill'
74         if 'coverage' in self.config or 'valgrind' in self.config:
75             daemon_signal = 'term'
76
77         args = [
78             'adjust-ulimits',
79             'ceph-coverage',
80             '{tdir}/archive/coverage'.format(tdir=testdir),
81             'daemon-helper',
82             daemon_signal,
83             ]
84
85         if 'valgrind' in self.config:
86             args = misc.get_valgrind_args(
87                 testdir,
88                 'rbd-mirror-{id}'.format(id=self.client),
89                 args,
90                 self.config.get('valgrind')
91             )
92
93         args.extend([
94             'rbd-mirror', '--foreground',
95             '--cluster',
96             self.cluster_name,
97             '--id',
98             self.client_id,
99             ])
100
101         self.ctx.daemons.add_daemon(
102             self.remote, 'rbd-mirror', self.client,
103             cluster=self.cluster_name,
104             args=args,
105             logger=self.log.getChild(self.client),
106             stdin=run.PIPE,
107             wait=False,
108         )
109
110     def end(self):
111         mirror_daemon = self.ctx.daemons.get_daemon('rbd-mirror',
112                                                     self.client,
113                                                     self.cluster_name)
114         mirror_daemon.stop()
115         super(RBDMirror, self).end()
116
117 task = RBDMirror