]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/exec_on_cleanup.py
import ceph 15.2.10
[ceph.git] / ceph / qa / tasks / exec_on_cleanup.py
1 """
2 Exececute custom commands during unwind/cleanup
3 """
4 import logging
5 import contextlib
6
7 from teuthology import misc as teuthology
8
9 log = logging.getLogger(__name__)
10
11 @contextlib.contextmanager
12 def task(ctx, config):
13 """
14 Execute commands on a given role
15
16 tasks:
17 - ceph:
18 - kclient: [client.a]
19 - exec:
20 client.a:
21 - "echo 'module libceph +p' > /sys/kernel/debug/dynamic_debug/control"
22 - "echo 'module ceph +p' > /sys/kernel/debug/dynamic_debug/control"
23 - interactive:
24
25 It stops and fails with the first command that does not return on success. It means
26 that if the first command fails, the second won't run at all.
27
28 To avoid confusion it is recommended to explicitly enclose the commands in
29 double quotes. For instance if the command is false (without double quotes) it will
30 be interpreted as a boolean by the YAML parser.
31
32 :param ctx: Context
33 :param config: Configuration
34 """
35 try:
36 yield
37 finally:
38 log.info('Executing custom commands...')
39 assert isinstance(config, dict), "task exec got invalid config"
40
41 testdir = teuthology.get_testdir(ctx)
42
43 if 'all' in config and len(config) == 1:
44 a = config['all']
45 roles = teuthology.all_roles(ctx.cluster)
46 config = dict((id_, a) for id_ in roles)
47
48 for role, ls in config.items():
49 (remote,) = ctx.cluster.only(role).remotes.keys()
50 log.info('Running commands on role %s host %s', role, remote.name)
51 for c in ls:
52 c.replace('$TESTDIR', testdir)
53 remote.run(
54 args=[
55 'sudo',
56 'TESTDIR={tdir}'.format(tdir=testdir),
57 'bash',
58 '-c',
59 c],
60 )
61