]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/restart.py
716148a7566c1c3180ea30d2b312fff82c065959
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(remote
.read_file(f
'{testdir}/restarts.list').decode().split('\0'))
69 return (srcdir
, restarts
)
71 def task(ctx
, config
):
73 Execute commands and allow daemon restart with config options.
74 Each process executed can output to stdout restart commands of the form:
75 restart <role> <id> <conf_key1> <conf_value1> <conf_key2> <conf_value2>
76 This will restart the daemon <role>.<id> with the specified config values once
77 by modifying the conf file with those values, and then replacing the old conf file
78 once the daemon is restarted.
79 This task does not kill a running daemon, it assumes the daemon will abort on an
80 assert specified in the config.
91 assert isinstance(config
, dict), "task kill got invalid config"
93 testdir
= teuthology
.get_testdir(ctx
)
96 assert 'exec' in config
, "config requires exec key with <role>: <command> entries"
97 for role
, task
in config
['exec'].items():
98 log
.info('restart for role {r}'.format(r
=role
))
99 (remote
,) = ctx
.cluster
.only(role
).remotes
.keys()
100 srcdir
, restarts
= get_tests(ctx
, config
, role
, remote
, testdir
)
101 log
.info('Running command on role %s host %s', role
, remote
.name
)
102 spec
= '{spec}'.format(spec
=task
[0])
103 log
.info('Restarts list: %s', restarts
)
104 log
.info('Spec is %s', spec
)
105 to_run
= [w
for w
in restarts
if w
== task
or w
.find(spec
) != -1]
106 log
.info('To run: %s', to_run
)
108 log
.info('Running restart script %s...', c
)
110 run
.Raw('TESTDIR="{tdir}"'.format(tdir
=testdir
)),
112 env
= config
.get('env')
114 for var
, val
in env
.items():
115 quoted_val
= pipes
.quote(val
)
116 env_arg
= '{var}={val}'.format(var
=var
, val
=quoted_val
)
117 args
.append(run
.Raw(env_arg
))
121 '{tdir}/archive/coverage'.format(tdir
=testdir
),
122 '{srcdir}/{c}'.format(
134 log
.info('waiting for a command from script')
136 l
= proc
.stdout
.readline()
139 log
.debug('script command: {c}'.format(c
=l
))
144 assert cmd
[0] == 'restart', "script sent invalid command request to kill task"
145 # cmd should be: restart <role> <id> <conf_key1> <conf_value1> <conf_key2> <conf_value2>
146 # or to clear, just: restart <role> <id>
147 restart_daemon(ctx
, config
, cmd
[1], cmd
[2], *cmd
[3:])
148 proc
.stdin
.writelines(['restarted\n'])
152 except tor
.CommandFailedError
:
153 raise Exception('restart task got non-zero exit status from script: {s}'.format(s
=c
))
155 log
.info('Finishing %s on %s...', task
, role
)
157 logger
=log
.getChild(role
),
159 'rm', '-rf', '--', '{tdir}/restarts.list'.format(tdir
=testdir
), srcdir
,