root / qa / ganeti-qa.py @ 3d914585
History | View | Annotate | Download (12.4 kB)
1 |
#!/usr/bin/python -u
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007, 2008, 2009, 2010 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""Script for doing QA on Ganeti.
|
23 |
|
24 |
"""
|
25 |
|
26 |
import sys |
27 |
import datetime |
28 |
import optparse |
29 |
|
30 |
import qa_cluster |
31 |
import qa_config |
32 |
import qa_daemon |
33 |
import qa_env |
34 |
import qa_instance |
35 |
import qa_node |
36 |
import qa_os |
37 |
import qa_rapi |
38 |
import qa_tags |
39 |
import qa_utils |
40 |
|
41 |
from ganeti import utils |
42 |
from ganeti import rapi |
43 |
|
44 |
import ganeti.rapi.client |
45 |
|
46 |
|
47 |
def _FormatHeader(line, end=72, char="-"): |
48 |
"""Fill a line up to the end column.
|
49 |
|
50 |
"""
|
51 |
line = "---- " + line + " " |
52 |
line += "-" * (end-len(line)) |
53 |
line = line.rstrip() |
54 |
return line
|
55 |
|
56 |
|
57 |
def RunTest(fn, *args): |
58 |
"""Runs a test after printing a header.
|
59 |
|
60 |
"""
|
61 |
if fn.__doc__:
|
62 |
desc = fn.__doc__.splitlines()[0].strip()
|
63 |
else:
|
64 |
desc = "%r" % fn
|
65 |
|
66 |
desc = desc.rstrip(".")
|
67 |
|
68 |
tstart = datetime.datetime.now() |
69 |
|
70 |
print
|
71 |
print _FormatHeader("%s start %s" % (tstart, desc)) |
72 |
|
73 |
try:
|
74 |
retval = fn(*args) |
75 |
return retval
|
76 |
finally:
|
77 |
tstop = datetime.datetime.now() |
78 |
tdelta = tstop - tstart |
79 |
print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc)) |
80 |
|
81 |
|
82 |
def RunEnvTests(): |
83 |
"""Run several environment tests.
|
84 |
|
85 |
"""
|
86 |
if not qa_config.TestEnabled('env'): |
87 |
return
|
88 |
|
89 |
RunTest(qa_env.TestSshConnection) |
90 |
RunTest(qa_env.TestIcmpPing) |
91 |
RunTest(qa_env.TestGanetiCommands) |
92 |
|
93 |
|
94 |
def SetupCluster(rapi_user, rapi_secret): |
95 |
"""Initializes the cluster.
|
96 |
|
97 |
@param rapi_user: Login user for RAPI
|
98 |
@param rapi_secret: Login secret for RAPI
|
99 |
|
100 |
"""
|
101 |
if qa_config.TestEnabled('create-cluster'): |
102 |
RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret) |
103 |
RunTest(qa_node.TestNodeAddAll) |
104 |
RunTest(qa_cluster.TestJobqueue) |
105 |
else:
|
106 |
# consider the nodes are already there
|
107 |
qa_node.MarkNodeAddedAll() |
108 |
if qa_config.TestEnabled('node-info'): |
109 |
RunTest(qa_node.TestNodeInfo) |
110 |
|
111 |
|
112 |
def RunClusterTests(): |
113 |
"""Runs tests related to gnt-cluster.
|
114 |
|
115 |
"""
|
116 |
if qa_config.TestEnabled("cluster-renew-crypto"): |
117 |
RunTest(qa_cluster.TestClusterRenewCrypto) |
118 |
|
119 |
if qa_config.TestEnabled('cluster-verify'): |
120 |
RunTest(qa_cluster.TestClusterVerify) |
121 |
|
122 |
if qa_config.TestEnabled('cluster-reserved-lvs'): |
123 |
RunTest(qa_cluster.TestClusterReservedLvs) |
124 |
|
125 |
if qa_config.TestEnabled('cluster-rename'): |
126 |
RunTest(qa_cluster.TestClusterRename) |
127 |
|
128 |
if qa_config.TestEnabled('cluster-info'): |
129 |
RunTest(qa_cluster.TestClusterVersion) |
130 |
RunTest(qa_cluster.TestClusterInfo) |
131 |
RunTest(qa_cluster.TestClusterGetmaster) |
132 |
|
133 |
if qa_config.TestEnabled('cluster-copyfile'): |
134 |
RunTest(qa_cluster.TestClusterCopyfile) |
135 |
|
136 |
if qa_config.TestEnabled('cluster-command'): |
137 |
RunTest(qa_cluster.TestClusterCommand) |
138 |
|
139 |
if qa_config.TestEnabled('cluster-burnin'): |
140 |
RunTest(qa_cluster.TestClusterBurnin) |
141 |
|
142 |
if qa_config.TestEnabled('cluster-master-failover'): |
143 |
RunTest(qa_cluster.TestClusterMasterFailover) |
144 |
|
145 |
if qa_rapi.Enabled():
|
146 |
RunTest(qa_rapi.TestVersion) |
147 |
RunTest(qa_rapi.TestEmptyCluster) |
148 |
|
149 |
|
150 |
def RunOsTests(): |
151 |
"""Runs all tests related to gnt-os.
|
152 |
|
153 |
"""
|
154 |
if not qa_config.TestEnabled('os'): |
155 |
return
|
156 |
|
157 |
RunTest(qa_os.TestOsList) |
158 |
RunTest(qa_os.TestOsDiagnose) |
159 |
RunTest(qa_os.TestOsValid) |
160 |
RunTest(qa_os.TestOsInvalid) |
161 |
RunTest(qa_os.TestOsPartiallyValid) |
162 |
RunTest(qa_os.TestOsModifyValid) |
163 |
RunTest(qa_os.TestOsModifyInvalid) |
164 |
RunTest(qa_os.TestOsStates) |
165 |
|
166 |
|
167 |
def RunCommonInstanceTests(instance): |
168 |
"""Runs a few tests that are common to all disk types.
|
169 |
|
170 |
"""
|
171 |
if qa_config.TestEnabled('instance-shutdown'): |
172 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
173 |
RunTest(qa_instance.TestInstanceStartup, instance) |
174 |
|
175 |
if qa_config.TestEnabled('instance-list'): |
176 |
RunTest(qa_instance.TestInstanceList) |
177 |
|
178 |
if qa_config.TestEnabled('instance-info'): |
179 |
RunTest(qa_instance.TestInstanceInfo, instance) |
180 |
|
181 |
if qa_config.TestEnabled('instance-modify'): |
182 |
RunTest(qa_instance.TestInstanceModify, instance) |
183 |
if qa_rapi.Enabled():
|
184 |
RunTest(qa_rapi.TestRapiInstanceModify, instance) |
185 |
|
186 |
if qa_config.TestEnabled('instance-console'): |
187 |
RunTest(qa_instance.TestInstanceConsole, instance) |
188 |
|
189 |
if qa_config.TestEnabled('instance-reinstall'): |
190 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
191 |
RunTest(qa_instance.TestInstanceReinstall, instance) |
192 |
RunTest(qa_instance.TestInstanceStartup, instance) |
193 |
|
194 |
if qa_config.TestEnabled('instance-reboot'): |
195 |
RunTest(qa_instance.TestInstanceReboot, instance) |
196 |
|
197 |
if qa_config.TestEnabled('instance-rename'): |
198 |
rename_target = qa_config.get("rename", None) |
199 |
if rename_target is None: |
200 |
print qa_utils.FormatError("Can rename instance, 'rename' entry is" |
201 |
" missing from configuration")
|
202 |
else:
|
203 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
204 |
RunTest(qa_instance.TestInstanceRename, instance, rename_target) |
205 |
if qa_rapi.Enabled():
|
206 |
RunTest(qa_rapi.TestRapiInstanceRename, instance, rename_target) |
207 |
RunTest(qa_instance.TestInstanceStartup, instance) |
208 |
|
209 |
if qa_config.TestEnabled('tags'): |
210 |
RunTest(qa_tags.TestInstanceTags, instance) |
211 |
|
212 |
if qa_config.TestEnabled('node-volumes'): |
213 |
RunTest(qa_node.TestNodeVolumes) |
214 |
|
215 |
if qa_config.TestEnabled("node-storage"): |
216 |
RunTest(qa_node.TestNodeStorage) |
217 |
|
218 |
if qa_rapi.Enabled():
|
219 |
RunTest(qa_rapi.TestInstance, instance) |
220 |
|
221 |
|
222 |
def RunExportImportTests(instance, pnode, snode): |
223 |
"""Tries to export and import the instance.
|
224 |
|
225 |
@param pnode: current primary node of the instance
|
226 |
@param snode: current secondary node of the instance, if any,
|
227 |
otherwise None
|
228 |
|
229 |
"""
|
230 |
if qa_config.TestEnabled('instance-export'): |
231 |
RunTest(qa_instance.TestInstanceExportNoTarget, instance) |
232 |
|
233 |
expnode = qa_config.AcquireNode(exclude=pnode) |
234 |
try:
|
235 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
236 |
|
237 |
RunTest(qa_instance.TestBackupList, expnode) |
238 |
|
239 |
if qa_config.TestEnabled('instance-import'): |
240 |
newinst = qa_config.AcquireInstance() |
241 |
try:
|
242 |
RunTest(qa_instance.TestInstanceImport, pnode, newinst, |
243 |
expnode, name) |
244 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
245 |
finally:
|
246 |
qa_config.ReleaseInstance(newinst) |
247 |
finally:
|
248 |
qa_config.ReleaseNode(expnode) |
249 |
|
250 |
if (qa_rapi.Enabled() and |
251 |
qa_config.TestEnabled("inter-cluster-instance-move")):
|
252 |
newinst = qa_config.AcquireInstance() |
253 |
try:
|
254 |
if snode is None: |
255 |
excl = [pnode] |
256 |
else:
|
257 |
excl = [pnode, snode] |
258 |
tnode = qa_config.AcquireNode(exclude=excl) |
259 |
try:
|
260 |
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst, |
261 |
pnode, snode, tnode) |
262 |
finally:
|
263 |
qa_config.ReleaseNode(tnode) |
264 |
finally:
|
265 |
qa_config.ReleaseInstance(newinst) |
266 |
|
267 |
|
268 |
def RunDaemonTests(instance, pnode): |
269 |
"""Test the ganeti-watcher script.
|
270 |
|
271 |
"""
|
272 |
automatic_restart = \ |
273 |
qa_config.TestEnabled('instance-automatic-restart')
|
274 |
consecutive_failures = \ |
275 |
qa_config.TestEnabled('instance-consecutive-failures')
|
276 |
|
277 |
if automatic_restart or consecutive_failures: |
278 |
qa_daemon.PrintCronWarning() |
279 |
|
280 |
if automatic_restart:
|
281 |
RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance) |
282 |
|
283 |
if consecutive_failures:
|
284 |
RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance) |
285 |
|
286 |
|
287 |
def RunHardwareFailureTests(instance, pnode, snode): |
288 |
"""Test cluster internal hardware failure recovery.
|
289 |
|
290 |
"""
|
291 |
if qa_config.TestEnabled('instance-failover'): |
292 |
RunTest(qa_instance.TestInstanceFailover, instance) |
293 |
|
294 |
if qa_config.TestEnabled("instance-migrate"): |
295 |
RunTest(qa_instance.TestInstanceMigrate, instance) |
296 |
|
297 |
if qa_rapi.Enabled():
|
298 |
RunTest(qa_rapi.TestRapiInstanceMigrate, instance) |
299 |
|
300 |
if qa_config.TestEnabled('instance-replace-disks'): |
301 |
othernode = qa_config.AcquireNode(exclude=[pnode, snode]) |
302 |
try:
|
303 |
RunTest(qa_instance.TestReplaceDisks, |
304 |
instance, pnode, snode, othernode) |
305 |
finally:
|
306 |
qa_config.ReleaseNode(othernode) |
307 |
|
308 |
if qa_config.TestEnabled('node-evacuate'): |
309 |
RunTest(qa_node.TestNodeEvacuate, pnode, snode) |
310 |
|
311 |
if qa_config.TestEnabled('node-failover'): |
312 |
RunTest(qa_node.TestNodeFailover, pnode, snode) |
313 |
|
314 |
if qa_config.TestEnabled('instance-disk-failure'): |
315 |
RunTest(qa_instance.TestInstanceMasterDiskFailure, |
316 |
instance, pnode, snode) |
317 |
RunTest(qa_instance.TestInstanceSecondaryDiskFailure, |
318 |
instance, pnode, snode) |
319 |
|
320 |
|
321 |
@rapi.client.UsesRapiClient
|
322 |
def main(): |
323 |
"""Main program.
|
324 |
|
325 |
"""
|
326 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>")
|
327 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
328 |
action="store_true",
|
329 |
help="Really execute the tests")
|
330 |
(qa_config.options, args) = parser.parse_args() |
331 |
|
332 |
if len(args) == 1: |
333 |
(config_file, ) = args |
334 |
else:
|
335 |
parser.error("Wrong number of arguments.")
|
336 |
|
337 |
if not qa_config.options.yes_do_it: |
338 |
print ("Executing this script irreversibly destroys any Ganeti\n" |
339 |
"configuration on all nodes involved. If you really want\n"
|
340 |
"to start testing, supply the --yes-do-it option.")
|
341 |
sys.exit(1)
|
342 |
|
343 |
qa_config.Load(config_file) |
344 |
|
345 |
rapi_user = "ganeti-qa"
|
346 |
rapi_secret = utils.GenerateSecret() |
347 |
|
348 |
RunEnvTests() |
349 |
SetupCluster(rapi_user, rapi_secret) |
350 |
|
351 |
# Load RAPI certificate
|
352 |
qa_rapi.Setup(rapi_user, rapi_secret) |
353 |
|
354 |
RunClusterTests() |
355 |
RunOsTests() |
356 |
|
357 |
if qa_config.TestEnabled('tags'): |
358 |
RunTest(qa_tags.TestClusterTags) |
359 |
|
360 |
if qa_config.TestEnabled('node-readd'): |
361 |
master = qa_config.GetMasterNode() |
362 |
pnode = qa_config.AcquireNode(exclude=master) |
363 |
try:
|
364 |
RunTest(qa_node.TestNodeReadd, pnode) |
365 |
finally:
|
366 |
qa_config.ReleaseNode(pnode) |
367 |
|
368 |
pnode = qa_config.AcquireNode() |
369 |
try:
|
370 |
if qa_config.TestEnabled('tags'): |
371 |
RunTest(qa_tags.TestNodeTags, pnode) |
372 |
|
373 |
if qa_rapi.Enabled():
|
374 |
RunTest(qa_rapi.TestNode, pnode) |
375 |
|
376 |
if qa_config.TestEnabled("instance-add-plain-disk"): |
377 |
for use_client in [True, False]: |
378 |
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode, |
379 |
use_client) |
380 |
RunCommonInstanceTests(rapi_instance) |
381 |
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client) |
382 |
del rapi_instance
|
383 |
|
384 |
if qa_config.TestEnabled('instance-add-plain-disk'): |
385 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
386 |
RunCommonInstanceTests(instance) |
387 |
RunExportImportTests(instance, pnode, None)
|
388 |
RunDaemonTests(instance, pnode) |
389 |
RunTest(qa_instance.TestInstanceRemove, instance) |
390 |
del instance
|
391 |
|
392 |
multinode_tests = [ |
393 |
('instance-add-drbd-disk',
|
394 |
qa_instance.TestInstanceAddWithDrbdDisk), |
395 |
] |
396 |
|
397 |
for name, func in multinode_tests: |
398 |
if qa_config.TestEnabled(name):
|
399 |
snode = qa_config.AcquireNode(exclude=pnode) |
400 |
try:
|
401 |
instance = RunTest(func, pnode, snode) |
402 |
RunCommonInstanceTests(instance) |
403 |
if qa_config.TestEnabled('instance-convert-disk'): |
404 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
405 |
RunTest(qa_instance.TestInstanceConvertDisk, instance, snode) |
406 |
RunTest(qa_instance.TestInstanceStartup, instance) |
407 |
RunExportImportTests(instance, pnode, snode) |
408 |
RunHardwareFailureTests(instance, pnode, snode) |
409 |
RunTest(qa_instance.TestInstanceRemove, instance) |
410 |
del instance
|
411 |
finally:
|
412 |
qa_config.ReleaseNode(snode) |
413 |
|
414 |
if (qa_config.TestEnabled('instance-add-plain-disk') and |
415 |
qa_config.TestEnabled("instance-export")):
|
416 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
417 |
expnode = qa_config.AcquireNode(exclude=pnode) |
418 |
try:
|
419 |
RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode) |
420 |
RunTest(qa_instance.TestBackupList, expnode) |
421 |
finally:
|
422 |
qa_config.ReleaseNode(expnode) |
423 |
del expnode
|
424 |
del instance
|
425 |
|
426 |
finally:
|
427 |
qa_config.ReleaseNode(pnode) |
428 |
|
429 |
if qa_config.TestEnabled('create-cluster'): |
430 |
RunTest(qa_node.TestNodeRemoveAll) |
431 |
|
432 |
if qa_config.TestEnabled('cluster-destroy'): |
433 |
RunTest(qa_cluster.TestClusterDestroy) |
434 |
|
435 |
|
436 |
if __name__ == '__main__': |
437 |
main() |