root / qa / ganeti-qa.py @ 4fab7cab
History | View | Annotate | Download (15.2 kB)
1 |
#!/usr/bin/python -u
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007, 2008, 2009, 2010, 2011 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 |
# pylint: disable-msg=C0103
|
27 |
# due to invalid name
|
28 |
|
29 |
import sys |
30 |
import datetime |
31 |
import optparse |
32 |
|
33 |
import qa_cluster |
34 |
import qa_config |
35 |
import qa_daemon |
36 |
import qa_env |
37 |
import qa_group |
38 |
import qa_instance |
39 |
import qa_node |
40 |
import qa_os |
41 |
import qa_rapi |
42 |
import qa_tags |
43 |
import qa_utils |
44 |
|
45 |
from ganeti import utils |
46 |
from ganeti import rapi |
47 |
from ganeti import constants |
48 |
|
49 |
import ganeti.rapi.client # pylint: disable-msg=W0611 |
50 |
|
51 |
|
52 |
def _FormatHeader(line, end=72): |
53 |
"""Fill a line up to the end column.
|
54 |
|
55 |
"""
|
56 |
line = "---- " + line + " " |
57 |
line += "-" * (end-len(line)) |
58 |
line = line.rstrip() |
59 |
return line
|
60 |
|
61 |
|
62 |
def _DescriptionOf(fn): |
63 |
"""Computes the description of an item.
|
64 |
|
65 |
"""
|
66 |
if fn.__doc__:
|
67 |
desc = fn.__doc__.splitlines()[0].strip()
|
68 |
else:
|
69 |
desc = "%r" % fn
|
70 |
|
71 |
return desc.rstrip(".") |
72 |
|
73 |
|
74 |
def RunTest(fn, *args): |
75 |
"""Runs a test after printing a header.
|
76 |
|
77 |
"""
|
78 |
|
79 |
tstart = datetime.datetime.now() |
80 |
|
81 |
desc = _DescriptionOf(fn) |
82 |
|
83 |
print
|
84 |
print _FormatHeader("%s start %s" % (tstart, desc)) |
85 |
|
86 |
try:
|
87 |
retval = fn(*args) |
88 |
return retval
|
89 |
finally:
|
90 |
tstop = datetime.datetime.now() |
91 |
tdelta = tstop - tstart |
92 |
print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc)) |
93 |
|
94 |
|
95 |
def RunTestIf(testnames, fn, *args): |
96 |
"""Runs a test conditionally.
|
97 |
|
98 |
@param testnames: either a single test name in the configuration
|
99 |
file, or a list of testnames (which will be AND-ed together)
|
100 |
|
101 |
"""
|
102 |
if qa_config.TestEnabled(testnames):
|
103 |
RunTest(fn, *args) |
104 |
else:
|
105 |
tstart = datetime.datetime.now() |
106 |
desc = _DescriptionOf(fn) |
107 |
print _FormatHeader("%s skipping %s, test(s) %s disabled" % |
108 |
(tstart, desc, testnames)) |
109 |
|
110 |
|
111 |
def RunEnvTests(): |
112 |
"""Run several environment tests.
|
113 |
|
114 |
"""
|
115 |
RunTestIf("env", qa_env.TestSshConnection)
|
116 |
RunTestIf("env", qa_env.TestIcmpPing)
|
117 |
RunTestIf("env", qa_env.TestGanetiCommands)
|
118 |
|
119 |
|
120 |
def SetupCluster(rapi_user, rapi_secret): |
121 |
"""Initializes the cluster.
|
122 |
|
123 |
@param rapi_user: Login user for RAPI
|
124 |
@param rapi_secret: Login secret for RAPI
|
125 |
|
126 |
"""
|
127 |
RunTestIf("create-cluster", qa_cluster.TestClusterInit,
|
128 |
rapi_user, rapi_secret) |
129 |
|
130 |
# Test on empty cluster
|
131 |
RunTestIf("node-list", qa_node.TestNodeList)
|
132 |
RunTestIf("instance-list", qa_instance.TestInstanceList)
|
133 |
|
134 |
RunTestIf("create-cluster", qa_node.TestNodeAddAll)
|
135 |
if not qa_config.TestEnabled("create-cluster"): |
136 |
# consider the nodes are already there
|
137 |
qa_node.MarkNodeAddedAll() |
138 |
|
139 |
RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
|
140 |
|
141 |
# enable the watcher (unconditionally)
|
142 |
RunTest(qa_daemon.TestResumeWatcher) |
143 |
|
144 |
RunTestIf("node-list", qa_node.TestNodeList)
|
145 |
|
146 |
# Test listing fields
|
147 |
RunTestIf("node-list", qa_node.TestNodeListFields)
|
148 |
RunTestIf("instance-list", qa_instance.TestInstanceListFields)
|
149 |
|
150 |
RunTestIf("node-info", qa_node.TestNodeInfo)
|
151 |
|
152 |
|
153 |
def RunClusterTests(): |
154 |
"""Runs tests related to gnt-cluster.
|
155 |
|
156 |
"""
|
157 |
for test, fn in [ |
158 |
("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
|
159 |
("cluster-verify", qa_cluster.TestClusterVerify),
|
160 |
("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
|
161 |
# TODO: add more cluster modify tests
|
162 |
("cluster-modify", qa_cluster.TestClusterModifyBe),
|
163 |
("cluster-rename", qa_cluster.TestClusterRename),
|
164 |
("cluster-info", qa_cluster.TestClusterVersion),
|
165 |
("cluster-info", qa_cluster.TestClusterInfo),
|
166 |
("cluster-info", qa_cluster.TestClusterGetmaster),
|
167 |
("cluster-copyfile", qa_cluster.TestClusterCopyfile),
|
168 |
("cluster-command", qa_cluster.TestClusterCommand),
|
169 |
("cluster-burnin", qa_cluster.TestClusterBurnin),
|
170 |
("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
|
171 |
("cluster-master-failover",
|
172 |
qa_cluster.TestClusterMasterFailoverWithDrainedQueue), |
173 |
("cluster-oob", qa_cluster.TestClusterOob),
|
174 |
("rapi", qa_rapi.TestVersion),
|
175 |
("rapi", qa_rapi.TestEmptyCluster),
|
176 |
("rapi", qa_rapi.TestRapiQuery),
|
177 |
]: |
178 |
RunTestIf(test, fn) |
179 |
|
180 |
|
181 |
def RunOsTests(): |
182 |
"""Runs all tests related to gnt-os.
|
183 |
|
184 |
"""
|
185 |
if qa_config.TestEnabled("rapi"): |
186 |
rapi_getos = qa_rapi.GetOperatingSystems |
187 |
else:
|
188 |
rapi_getos = None
|
189 |
|
190 |
for fn in [ |
191 |
qa_os.TestOsList, |
192 |
qa_os.TestOsDiagnose, |
193 |
]: |
194 |
RunTestIf("os", fn)
|
195 |
|
196 |
for fn in [ |
197 |
qa_os.TestOsValid, |
198 |
qa_os.TestOsInvalid, |
199 |
qa_os.TestOsPartiallyValid, |
200 |
]: |
201 |
RunTestIf("os", fn, rapi_getos)
|
202 |
|
203 |
for fn in [ |
204 |
qa_os.TestOsModifyValid, |
205 |
qa_os.TestOsModifyInvalid, |
206 |
qa_os.TestOsStatesNonExisting, |
207 |
]: |
208 |
RunTestIf("os", fn)
|
209 |
|
210 |
|
211 |
def RunCommonInstanceTests(instance): |
212 |
"""Runs a few tests that are common to all disk types.
|
213 |
|
214 |
"""
|
215 |
RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
|
216 |
RunTestIf(["instance-shutdown", "instance-console", "rapi"], |
217 |
qa_rapi.TestRapiStoppedInstanceConsole, instance) |
218 |
RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
|
219 |
|
220 |
RunTestIf("instance-list", qa_instance.TestInstanceList)
|
221 |
|
222 |
RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
|
223 |
|
224 |
RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
|
225 |
RunTestIf(["instance-modify", "rapi"], |
226 |
qa_rapi.TestRapiInstanceModify, instance) |
227 |
|
228 |
RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
|
229 |
RunTestIf(["instance-console", "rapi"], |
230 |
qa_rapi.TestRapiInstanceConsole, instance) |
231 |
|
232 |
RunTestIf("instance-reinstall", qa_instance.TestInstanceShutdown, instance)
|
233 |
RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
|
234 |
RunTestIf(["instance-reinstall", "rapi"], |
235 |
qa_rapi.TestRapiInstanceReinstall, instance) |
236 |
RunTestIf("instance-reinstall", qa_instance.TestInstanceStartup, instance)
|
237 |
|
238 |
RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
|
239 |
|
240 |
if qa_config.TestEnabled('instance-rename'): |
241 |
rename_source = instance["name"]
|
242 |
rename_target = qa_config.get("rename", None) |
243 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
244 |
# perform instance rename to the same name
|
245 |
RunTest(qa_instance.TestInstanceRename, rename_source, rename_source) |
246 |
RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
|
247 |
rename_source, rename_source) |
248 |
if rename_target is not None: |
249 |
# perform instance rename to a different name, if we have one configured
|
250 |
RunTest(qa_instance.TestInstanceRename, rename_source, rename_target) |
251 |
RunTest(qa_instance.TestInstanceRename, rename_target, rename_source) |
252 |
RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
|
253 |
rename_source, rename_target) |
254 |
RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
|
255 |
rename_target, rename_source) |
256 |
RunTest(qa_instance.TestInstanceStartup, instance) |
257 |
|
258 |
RunTestIf("tags", qa_tags.TestInstanceTags, instance)
|
259 |
|
260 |
RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
|
261 |
|
262 |
RunTestIf("rapi", qa_rapi.TestInstance, instance)
|
263 |
|
264 |
# Lists instances, too
|
265 |
RunTestIf("node-list", qa_node.TestNodeList)
|
266 |
|
267 |
|
268 |
def RunCommonNodeTests(): |
269 |
"""Run a few common node tests.
|
270 |
|
271 |
"""
|
272 |
RunTestIf("node-volumes", qa_node.TestNodeVolumes)
|
273 |
RunTestIf("node-storage", qa_node.TestNodeStorage)
|
274 |
RunTestIf("node-oob", qa_node.TestOutOfBand)
|
275 |
|
276 |
|
277 |
def RunGroupListTests(): |
278 |
"""Run tests for listing node groups.
|
279 |
|
280 |
"""
|
281 |
RunTestIf("group-list", qa_group.TestGroupList)
|
282 |
RunTestIf("group-list", qa_group.TestGroupListFields)
|
283 |
|
284 |
|
285 |
def RunGroupRwTests(): |
286 |
"""Run tests for adding/removing/renaming groups.
|
287 |
|
288 |
"""
|
289 |
RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
|
290 |
RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
|
291 |
RunTestIf("group-rwops", qa_group.TestGroupModify)
|
292 |
RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups) |
293 |
|
294 |
|
295 |
def RunExportImportTests(instance, pnode, snode): |
296 |
"""Tries to export and import the instance.
|
297 |
|
298 |
@param pnode: current primary node of the instance
|
299 |
@param snode: current secondary node of the instance, if any,
|
300 |
otherwise None
|
301 |
|
302 |
"""
|
303 |
if qa_config.TestEnabled('instance-export'): |
304 |
RunTest(qa_instance.TestInstanceExportNoTarget, instance) |
305 |
|
306 |
expnode = qa_config.AcquireNode(exclude=pnode) |
307 |
try:
|
308 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
309 |
|
310 |
RunTest(qa_instance.TestBackupList, expnode) |
311 |
|
312 |
if qa_config.TestEnabled('instance-import'): |
313 |
newinst = qa_config.AcquireInstance() |
314 |
try:
|
315 |
RunTest(qa_instance.TestInstanceImport, pnode, newinst, |
316 |
expnode, name) |
317 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
318 |
finally:
|
319 |
qa_config.ReleaseInstance(newinst) |
320 |
finally:
|
321 |
qa_config.ReleaseNode(expnode) |
322 |
|
323 |
if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]): |
324 |
newinst = qa_config.AcquireInstance() |
325 |
try:
|
326 |
if snode is None: |
327 |
excl = [pnode] |
328 |
else:
|
329 |
excl = [pnode, snode] |
330 |
tnode = qa_config.AcquireNode(exclude=excl) |
331 |
try:
|
332 |
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst, |
333 |
pnode, snode, tnode) |
334 |
finally:
|
335 |
qa_config.ReleaseNode(tnode) |
336 |
finally:
|
337 |
qa_config.ReleaseInstance(newinst) |
338 |
|
339 |
|
340 |
def RunDaemonTests(instance, pnode): |
341 |
"""Test the ganeti-watcher script.
|
342 |
|
343 |
"""
|
344 |
RunTest(qa_daemon.TestPauseWatcher) |
345 |
|
346 |
RunTestIf("instance-automatic-restart",
|
347 |
qa_daemon.TestInstanceAutomaticRestart, pnode, instance) |
348 |
RunTestIf("instance-consecutive-failures",
|
349 |
qa_daemon.TestInstanceConsecutiveFailures, pnode, instance) |
350 |
|
351 |
RunTest(qa_daemon.TestResumeWatcher) |
352 |
|
353 |
|
354 |
def RunHardwareFailureTests(instance, pnode, snode): |
355 |
"""Test cluster internal hardware failure recovery.
|
356 |
|
357 |
"""
|
358 |
RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
|
359 |
|
360 |
RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
|
361 |
RunTestIf(["instance-migrate", "rapi"], |
362 |
qa_rapi.TestRapiInstanceMigrate, instance) |
363 |
|
364 |
if qa_config.TestEnabled('instance-replace-disks'): |
365 |
othernode = qa_config.AcquireNode(exclude=[pnode, snode]) |
366 |
try:
|
367 |
RunTest(qa_instance.TestReplaceDisks, |
368 |
instance, pnode, snode, othernode) |
369 |
finally:
|
370 |
qa_config.ReleaseNode(othernode) |
371 |
|
372 |
RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
|
373 |
|
374 |
RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
|
375 |
|
376 |
RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
|
377 |
instance, pnode, snode) |
378 |
RunTestIf("instance-disk-failure",
|
379 |
qa_instance.TestInstanceSecondaryDiskFailure, instance, |
380 |
pnode, snode) |
381 |
|
382 |
|
383 |
def RunQa(): |
384 |
"""Main QA body.
|
385 |
|
386 |
"""
|
387 |
rapi_user = "ganeti-qa"
|
388 |
rapi_secret = utils.GenerateSecret() |
389 |
|
390 |
RunEnvTests() |
391 |
SetupCluster(rapi_user, rapi_secret) |
392 |
|
393 |
# Load RAPI certificate
|
394 |
qa_rapi.Setup(rapi_user, rapi_secret) |
395 |
|
396 |
RunClusterTests() |
397 |
RunOsTests() |
398 |
|
399 |
RunTestIf("tags", qa_tags.TestClusterTags)
|
400 |
|
401 |
RunCommonNodeTests() |
402 |
RunGroupListTests() |
403 |
RunGroupRwTests() |
404 |
|
405 |
pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode()) |
406 |
try:
|
407 |
RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
|
408 |
RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
|
409 |
finally:
|
410 |
qa_config.ReleaseNode(pnode) |
411 |
|
412 |
pnode = qa_config.AcquireNode() |
413 |
try:
|
414 |
RunTestIf("tags", qa_tags.TestNodeTags, pnode)
|
415 |
|
416 |
if qa_rapi.Enabled():
|
417 |
RunTest(qa_rapi.TestNode, pnode) |
418 |
|
419 |
if qa_config.TestEnabled("instance-add-plain-disk"): |
420 |
for use_client in [True, False]: |
421 |
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode, |
422 |
use_client) |
423 |
RunCommonInstanceTests(rapi_instance) |
424 |
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client) |
425 |
del rapi_instance
|
426 |
|
427 |
if qa_config.TestEnabled('instance-add-plain-disk'): |
428 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
429 |
RunCommonInstanceTests(instance) |
430 |
RunGroupListTests() |
431 |
RunTest(qa_cluster.TestClusterEpo) |
432 |
RunExportImportTests(instance, pnode, None)
|
433 |
RunDaemonTests(instance, pnode) |
434 |
RunTest(qa_instance.TestInstanceRemove, instance) |
435 |
del instance
|
436 |
|
437 |
multinode_tests = [ |
438 |
('instance-add-drbd-disk',
|
439 |
qa_instance.TestInstanceAddWithDrbdDisk), |
440 |
] |
441 |
|
442 |
for name, func in multinode_tests: |
443 |
if qa_config.TestEnabled(name):
|
444 |
snode = qa_config.AcquireNode(exclude=pnode) |
445 |
try:
|
446 |
instance = RunTest(func, pnode, snode) |
447 |
RunCommonInstanceTests(instance) |
448 |
RunGroupListTests() |
449 |
RunTest(qa_group.TestAssignNodesIncludingSplit, |
450 |
constants.INITIAL_NODE_GROUP_NAME, |
451 |
pnode["primary"], snode["primary"]) |
452 |
if qa_config.TestEnabled('instance-convert-disk'): |
453 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
454 |
RunTest(qa_instance.TestInstanceConvertDisk, instance, snode) |
455 |
RunTest(qa_instance.TestInstanceStartup, instance) |
456 |
RunExportImportTests(instance, pnode, snode) |
457 |
RunHardwareFailureTests(instance, pnode, snode) |
458 |
RunTest(qa_instance.TestInstanceRemove, instance) |
459 |
del instance
|
460 |
finally:
|
461 |
qa_config.ReleaseNode(snode) |
462 |
|
463 |
if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]): |
464 |
for shutdown in [False, True]: |
465 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
466 |
expnode = qa_config.AcquireNode(exclude=pnode) |
467 |
try:
|
468 |
if shutdown:
|
469 |
# Stop instance before exporting and removing it
|
470 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
471 |
RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode) |
472 |
RunTest(qa_instance.TestBackupList, expnode) |
473 |
finally:
|
474 |
qa_config.ReleaseNode(expnode) |
475 |
del expnode
|
476 |
del instance
|
477 |
|
478 |
finally:
|
479 |
qa_config.ReleaseNode(pnode) |
480 |
|
481 |
RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
|
482 |
|
483 |
RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
|
484 |
|
485 |
|
486 |
@rapi.client.UsesRapiClient
|
487 |
def main(): |
488 |
"""Main program.
|
489 |
|
490 |
"""
|
491 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>")
|
492 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
493 |
action="store_true",
|
494 |
help="Really execute the tests")
|
495 |
(qa_config.options, args) = parser.parse_args() |
496 |
|
497 |
if len(args) == 1: |
498 |
(config_file, ) = args |
499 |
else:
|
500 |
parser.error("Wrong number of arguments.")
|
501 |
|
502 |
if not qa_config.options.yes_do_it: |
503 |
print ("Executing this script irreversibly destroys any Ganeti\n" |
504 |
"configuration on all nodes involved. If you really want\n"
|
505 |
"to start testing, supply the --yes-do-it option.")
|
506 |
sys.exit(1)
|
507 |
|
508 |
qa_config.Load(config_file) |
509 |
|
510 |
qa_utils.StartMultiplexer(qa_config.GetMasterNode()["primary"])
|
511 |
try:
|
512 |
RunQa() |
513 |
finally:
|
514 |
qa_utils.CloseMultiplexers() |
515 |
|
516 |
if __name__ == '__main__': |
517 |
main() |