]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/restart.py
7 from teuthology
import misc
as teuthology
8 from teuthology
.orchestra
import run
as tor
10 from teuthology
.orchestra
import run
11 log
= logging
.getLogger(__name__
)
13 def restart_daemon(ctx
, config
, role
, id_
, *args
):
15 Handle restart (including the execution of the command parameters passed)
17 log
.info('Restarting {r}.{i} daemon...'.format(r
=role
, i
=id_
))
18 daemon
= ctx
.daemons
.get_daemon(role
, id_
)
19 log
.debug('Waiting for exit of {r}.{i} daemon...'.format(r
=role
, i
=id_
))
21 daemon
.wait_for_exit()
22 except tor
.CommandFailedError
as e
:
23 log
.debug('Command Failed: {e}'.format(e
=e
))
25 confargs
= ['--{k}={v}'.format(k
=k
, v
=v
) for k
,v
in zip(args
[0::2], args
[1::2])]
26 log
.debug('Doing restart of {r}.{i} daemon with args: {a}...'.format(r
=role
, i
=id_
, a
=confargs
))
27 daemon
.restart_with_args(confargs
)
29 log
.debug('Doing restart of {r}.{i} daemon...'.format(r
=role
, i
=id_
))
32 def get_tests(ctx
, config
, role
, remote
, testdir
):
33 """Download restart tests"""
34 srcdir
= '{tdir}/restart.{role}'.format(tdir
=testdir
, role
=role
)
36 refspec
= config
.get('branch')
38 refspec
= config
.get('sha1')
40 refspec
= config
.get('tag')
43 log
.info('Pulling restart qa/workunits from ref %s', refspec
)
46 logger
=log
.getChild(role
),
48 'mkdir', '--', srcdir
,
52 '--remote=git://git.ceph.com/ceph.git',
53 '%s:qa/workunits' % refspec
,
62 'if', 'test', '-e', 'Makefile', run
.Raw(';'), 'then', 'make', run
.Raw(';'), 'fi',
64 'find', '-executable', '-type', 'f', '-printf', r
'%P\0',
65 run
.Raw('>{tdir}/restarts.list'.format(tdir
=testdir
)),
68 restarts
= sorted(teuthology
.get_file(
70 '{tdir}/restarts.list'.format(tdir
=testdir
)).split('\0'))
71 return (srcdir
, restarts
)
73 def task(ctx
, config
):
75 Execute commands and allow daemon restart with config options.
76 Each process executed can output to stdout restart commands of the form:
77 restart <role> <id> <conf_key1> <conf_value1> <conf_key2> <conf_value2>
78 This will restart the daemon <role>.<id> with the specified config values once
79 by modifying the conf file with those values, and then replacing the old conf file
80 once the daemon is restarted.
81 This task does not kill a running daemon, it assumes the daemon will abort on an
82 assert specified in the config.
93 assert isinstance(config
, dict), "task kill got invalid config"
95 testdir
= teuthology
.get_testdir(ctx
)
98 assert 'exec' in config
, "config requires exec key with <role>: <command> entries"
99 for role
, task
in config
['exec'].items():
100 log
.info('restart for role {r}'.format(r
=role
))
101 (remote
,) = ctx
.cluster
.only(role
).remotes
.keys()
102 srcdir
, restarts
= get_tests(ctx
, config
, role
, remote
, testdir
)
103 log
.info('Running command on role %s host %s', role
, remote
.name
)
104 spec
= '{spec}'.format(spec
=task
[0])
105 log
.info('Restarts list: %s', restarts
)
106 log
.info('Spec is %s', spec
)
107 to_run
= [w
for w
in restarts
if w
== task
or w
.find(spec
) != -1]
108 log
.info('To run: %s', to_run
)
110 log
.info('Running restart script %s...', c
)
112 run
.Raw('TESTDIR="{tdir}"'.format(tdir
=testdir
)),
114 env
= config
.get('env')
116 for var
, val
in env
.items():
117 quoted_val
= pipes
.quote(val
)
118 env_arg
= '{var}={val}'.format(var
=var
, val
=quoted_val
)
119 args
.append(run
.Raw(env_arg
))
123 '{tdir}/archive/coverage'.format(tdir
=testdir
),
124 '{srcdir}/{c}'.format(
136 log
.info('waiting for a command from script')
138 l
= proc
.stdout
.readline()
141 log
.debug('script command: {c}'.format(c
=l
))
146 assert cmd
[0] == 'restart', "script sent invalid command request to kill task"
147 # cmd should be: restart <role> <id> <conf_key1> <conf_value1> <conf_key2> <conf_value2>
148 # or to clear, just: restart <role> <id>
149 restart_daemon(ctx
, config
, cmd
[1], cmd
[2], *cmd
[3:])
150 proc
.stdin
.writelines(['restarted\n'])
154 except tor
.CommandFailedError
:
155 raise Exception('restart task got non-zero exit status from script: {s}'.format(s
=c
))
157 log
.info('Finishing %s on %s...', task
, role
)
159 logger
=log
.getChild(role
),
161 'rm', '-rf', '--', '{tdir}/restarts.list'.format(tdir
=testdir
), srcdir
,