]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/blktrace.py
update sources to v12.1.4
[ceph.git] / ceph / qa / tasks / blktrace.py
CommitLineData
7c673cae
FG
1"""
2Run blktrace program through teuthology
3"""
4import contextlib
5import logging
6
7from teuthology import misc as teuthology
8from teuthology import contextutil
9from teuthology.orchestra import run
10
11log = logging.getLogger(__name__)
12blktrace = '/usr/sbin/blktrace'
13daemon_signal = 'term'
14
15@contextlib.contextmanager
16def setup(ctx, config):
17 """
18 Setup all the remotes
19 """
20 osds = ctx.cluster.only(teuthology.is_type('osd', config['cluster']))
21 log_dir = '{tdir}/archive/performance/blktrace'.format(tdir=teuthology.get_testdir(ctx))
22
23 for remote, roles_for_host in osds.remotes.iteritems():
24 log.info('Creating %s on %s' % (log_dir, remote.name))
25 remote.run(
26 args=['mkdir', '-p', '-m0755', '--', log_dir],
27 wait=False,
28 )
29 yield
30
31@contextlib.contextmanager
32def execute(ctx, config):
33 """
34 Run the blktrace program on remote machines.
35 """
36 procs = []
37 testdir = teuthology.get_testdir(ctx)
38 log_dir = '{tdir}/archive/performance/blktrace'.format(tdir=testdir)
39
40 osds = ctx.cluster.only(teuthology.is_type('osd'))
41 for remote, roles_for_host in osds.remotes.iteritems():
42 roles_to_devs = ctx.disk_config.remote_to_roles_to_dev[remote]
43 for role in teuthology.cluster_roles_of_type(roles_for_host, 'osd',
44 config['cluster']):
45 if roles_to_devs.get(role):
46 dev = roles_to_devs[role]
47 log.info("running blktrace on %s: %s" % (remote.name, dev))
48
49 proc = remote.run(
50 args=[
51 'cd',
52 log_dir,
53 run.Raw(';'),
54 'daemon-helper',
55 daemon_signal,
56 'sudo',
57 blktrace,
58 '-o',
59 dev.rsplit("/", 1)[1],
60 '-d',
61 dev,
62 ],
63 wait=False,
64 stdin=run.PIPE,
65 )
66 procs.append(proc)
67 try:
68 yield
69 finally:
70 osds = ctx.cluster.only(teuthology.is_type('osd'))
71 log.info('stopping blktrace processs')
72 for proc in procs:
73 proc.stdin.close()
74
75@contextlib.contextmanager
76def task(ctx, config):
77 """
78 Usage:
79 blktrace:
80
81 or:
82 blktrace:
83 cluster: backup
84
85 Runs blktrace on all osds in the specified cluster (the 'ceph' cluster by
86 default).
87 """
88 if config is None:
89 config = {}
90 config['cluster'] = config.get('cluster', 'ceph')
91
92 with contextutil.nested(
93 lambda: setup(ctx=ctx, config=config),
94 lambda: execute(ctx=ctx, config=config),
95 ):
96 yield