root / qa / ganeti-qa.py @ 8cd4f8cf
History | View | Annotate | Download (23.4 kB)
1 |
#!/usr/bin/python -u
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 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=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_error |
38 |
import qa_group |
39 |
import qa_instance |
40 |
import qa_node |
41 |
import qa_os |
42 |
import qa_job |
43 |
import qa_rapi |
44 |
import qa_tags |
45 |
import qa_utils |
46 |
|
47 |
from ganeti import utils |
48 |
from ganeti import rapi # pylint: disable=W0611 |
49 |
from ganeti import constants |
50 |
|
51 |
import ganeti.rapi.client # pylint: disable=W0611 |
52 |
from ganeti.rapi.client import UsesRapiClient |
53 |
|
54 |
|
55 |
def _FormatHeader(line, end=72): |
56 |
"""Fill a line up to the end column.
|
57 |
|
58 |
"""
|
59 |
line = "---- " + line + " " |
60 |
line += "-" * (end - len(line)) |
61 |
line = line.rstrip() |
62 |
return line
|
63 |
|
64 |
|
65 |
def _DescriptionOf(fn): |
66 |
"""Computes the description of an item.
|
67 |
|
68 |
"""
|
69 |
if fn.__doc__:
|
70 |
desc = fn.__doc__.splitlines()[0].strip()
|
71 |
else:
|
72 |
desc = "%r" % fn
|
73 |
|
74 |
return desc.rstrip(".") |
75 |
|
76 |
|
77 |
def RunTest(fn, *args, **kwargs): |
78 |
"""Runs a test after printing a header.
|
79 |
|
80 |
"""
|
81 |
|
82 |
tstart = datetime.datetime.now() |
83 |
|
84 |
desc = _DescriptionOf(fn) |
85 |
|
86 |
print
|
87 |
print _FormatHeader("%s start %s" % (tstart, desc)) |
88 |
|
89 |
try:
|
90 |
retval = fn(*args, **kwargs) |
91 |
return retval
|
92 |
finally:
|
93 |
tstop = datetime.datetime.now() |
94 |
tdelta = tstop - tstart |
95 |
print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc)) |
96 |
|
97 |
|
98 |
def RunTestIf(testnames, fn, *args, **kwargs): |
99 |
"""Runs a test conditionally.
|
100 |
|
101 |
@param testnames: either a single test name in the configuration
|
102 |
file, or a list of testnames (which will be AND-ed together)
|
103 |
|
104 |
"""
|
105 |
if qa_config.TestEnabled(testnames):
|
106 |
RunTest(fn, *args, **kwargs) |
107 |
else:
|
108 |
tstart = datetime.datetime.now() |
109 |
desc = _DescriptionOf(fn) |
110 |
print _FormatHeader("%s skipping %s, test(s) %s disabled" % |
111 |
(tstart, desc, testnames)) |
112 |
|
113 |
|
114 |
def RunEnvTests(): |
115 |
"""Run several environment tests.
|
116 |
|
117 |
"""
|
118 |
RunTestIf("env", qa_env.TestSshConnection)
|
119 |
RunTestIf("env", qa_env.TestIcmpPing)
|
120 |
RunTestIf("env", qa_env.TestGanetiCommands)
|
121 |
|
122 |
|
123 |
def SetupCluster(rapi_user, rapi_secret): |
124 |
"""Initializes the cluster.
|
125 |
|
126 |
@param rapi_user: Login user for RAPI
|
127 |
@param rapi_secret: Login secret for RAPI
|
128 |
|
129 |
"""
|
130 |
RunTestIf("create-cluster", qa_cluster.TestClusterInit,
|
131 |
rapi_user, rapi_secret) |
132 |
if not qa_config.TestEnabled("create-cluster"): |
133 |
# If the cluster is already in place, we assume that exclusive-storage is
|
134 |
# already set according to the configuration
|
135 |
qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False)) |
136 |
|
137 |
# Test on empty cluster
|
138 |
RunTestIf("node-list", qa_node.TestNodeList)
|
139 |
RunTestIf("instance-list", qa_instance.TestInstanceList)
|
140 |
RunTestIf("job-list", qa_job.TestJobList)
|
141 |
|
142 |
RunTestIf("create-cluster", qa_node.TestNodeAddAll)
|
143 |
if not qa_config.TestEnabled("create-cluster"): |
144 |
# consider the nodes are already there
|
145 |
qa_node.MarkNodeAddedAll() |
146 |
|
147 |
RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
|
148 |
|
149 |
# enable the watcher (unconditionally)
|
150 |
RunTest(qa_daemon.TestResumeWatcher) |
151 |
|
152 |
RunTestIf("node-list", qa_node.TestNodeList)
|
153 |
|
154 |
# Test listing fields
|
155 |
RunTestIf("node-list", qa_node.TestNodeListFields)
|
156 |
RunTestIf("instance-list", qa_instance.TestInstanceListFields)
|
157 |
RunTestIf("job-list", qa_job.TestJobListFields)
|
158 |
RunTestIf("instance-export", qa_instance.TestBackupListFields)
|
159 |
|
160 |
RunTestIf("node-info", qa_node.TestNodeInfo)
|
161 |
|
162 |
|
163 |
def RunClusterTests(): |
164 |
"""Runs tests related to gnt-cluster.
|
165 |
|
166 |
"""
|
167 |
for test, fn in [ |
168 |
("create-cluster", qa_cluster.TestClusterInitDisk),
|
169 |
("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
|
170 |
("cluster-verify", qa_cluster.TestClusterVerify),
|
171 |
("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
|
172 |
# TODO: add more cluster modify tests
|
173 |
("cluster-modify", qa_cluster.TestClusterModifyEmpty),
|
174 |
("cluster-modify", qa_cluster.TestClusterModifyIPolicy),
|
175 |
("cluster-modify", qa_cluster.TestClusterModifyISpecs),
|
176 |
("cluster-modify", qa_cluster.TestClusterModifyBe),
|
177 |
("cluster-modify", qa_cluster.TestClusterModifyDisk),
|
178 |
("cluster-rename", qa_cluster.TestClusterRename),
|
179 |
("cluster-info", qa_cluster.TestClusterVersion),
|
180 |
("cluster-info", qa_cluster.TestClusterInfo),
|
181 |
("cluster-info", qa_cluster.TestClusterGetmaster),
|
182 |
("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
|
183 |
("cluster-copyfile", qa_cluster.TestClusterCopyfile),
|
184 |
("cluster-command", qa_cluster.TestClusterCommand),
|
185 |
("cluster-burnin", qa_cluster.TestClusterBurnin),
|
186 |
("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
|
187 |
("cluster-master-failover",
|
188 |
qa_cluster.TestClusterMasterFailoverWithDrainedQueue), |
189 |
("cluster-oob", qa_cluster.TestClusterOob),
|
190 |
("rapi", qa_rapi.TestVersion),
|
191 |
("rapi", qa_rapi.TestEmptyCluster),
|
192 |
("rapi", qa_rapi.TestRapiQuery),
|
193 |
]: |
194 |
RunTestIf(test, fn) |
195 |
|
196 |
|
197 |
def RunRepairDiskSizes(): |
198 |
"""Run the repair disk-sizes test.
|
199 |
|
200 |
"""
|
201 |
RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
|
202 |
|
203 |
|
204 |
def RunOsTests(): |
205 |
"""Runs all tests related to gnt-os.
|
206 |
|
207 |
"""
|
208 |
if qa_config.TestEnabled("rapi"): |
209 |
rapi_getos = qa_rapi.GetOperatingSystems |
210 |
else:
|
211 |
rapi_getos = None
|
212 |
|
213 |
for fn in [ |
214 |
qa_os.TestOsList, |
215 |
qa_os.TestOsDiagnose, |
216 |
]: |
217 |
RunTestIf("os", fn)
|
218 |
|
219 |
for fn in [ |
220 |
qa_os.TestOsValid, |
221 |
qa_os.TestOsInvalid, |
222 |
qa_os.TestOsPartiallyValid, |
223 |
]: |
224 |
RunTestIf("os", fn, rapi_getos)
|
225 |
|
226 |
for fn in [ |
227 |
qa_os.TestOsModifyValid, |
228 |
qa_os.TestOsModifyInvalid, |
229 |
qa_os.TestOsStatesNonExisting, |
230 |
]: |
231 |
RunTestIf("os", fn)
|
232 |
|
233 |
|
234 |
def RunCommonInstanceTests(instance): |
235 |
"""Runs a few tests that are common to all disk types.
|
236 |
|
237 |
"""
|
238 |
RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
|
239 |
RunTestIf(["instance-shutdown", "instance-console", "rapi"], |
240 |
qa_rapi.TestRapiStoppedInstanceConsole, instance) |
241 |
RunTestIf(["instance-shutdown", "instance-modify"], |
242 |
qa_instance.TestInstanceStoppedModify, instance) |
243 |
RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
|
244 |
|
245 |
# Test shutdown/start via RAPI
|
246 |
RunTestIf(["instance-shutdown", "rapi"], |
247 |
qa_rapi.TestRapiInstanceShutdown, instance) |
248 |
RunTestIf(["instance-shutdown", "rapi"], |
249 |
qa_rapi.TestRapiInstanceStartup, instance) |
250 |
|
251 |
RunTestIf("instance-list", qa_instance.TestInstanceList)
|
252 |
|
253 |
RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
|
254 |
|
255 |
RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
|
256 |
RunTestIf(["instance-modify", "rapi"], |
257 |
qa_rapi.TestRapiInstanceModify, instance) |
258 |
|
259 |
RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
|
260 |
RunTestIf(["instance-console", "rapi"], |
261 |
qa_rapi.TestRapiInstanceConsole, instance) |
262 |
|
263 |
DOWN_TESTS = qa_config.Either([ |
264 |
"instance-reinstall",
|
265 |
"instance-rename",
|
266 |
"instance-grow-disk",
|
267 |
]) |
268 |
|
269 |
# shutdown instance for any 'down' tests
|
270 |
RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance) |
271 |
|
272 |
# now run the 'down' state tests
|
273 |
RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
|
274 |
RunTestIf(["instance-reinstall", "rapi"], |
275 |
qa_rapi.TestRapiInstanceReinstall, instance) |
276 |
|
277 |
if qa_config.TestEnabled("instance-rename"): |
278 |
tgt_instance = qa_config.AcquireInstance() |
279 |
try:
|
280 |
rename_source = instance["name"]
|
281 |
rename_target = tgt_instance["name"]
|
282 |
# perform instance rename to the same name
|
283 |
RunTest(qa_instance.TestInstanceRenameAndBack, |
284 |
rename_source, rename_source) |
285 |
RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
|
286 |
rename_source, rename_source) |
287 |
if rename_target is not None: |
288 |
# perform instance rename to a different name, if we have one configured
|
289 |
RunTest(qa_instance.TestInstanceRenameAndBack, |
290 |
rename_source, rename_target) |
291 |
RunTestIf("rapi", qa_rapi.TestRapiInstanceRenameAndBack,
|
292 |
rename_source, rename_target) |
293 |
finally:
|
294 |
qa_config.ReleaseInstance(tgt_instance) |
295 |
|
296 |
RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
|
297 |
|
298 |
# and now start the instance again
|
299 |
RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance) |
300 |
|
301 |
RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
|
302 |
|
303 |
RunTestIf("tags", qa_tags.TestInstanceTags, instance)
|
304 |
|
305 |
RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
|
306 |
|
307 |
RunTestIf("rapi", qa_rapi.TestInstance, instance)
|
308 |
|
309 |
# Lists instances, too
|
310 |
RunTestIf("node-list", qa_node.TestNodeList)
|
311 |
|
312 |
# Some jobs have been run, let's test listing them
|
313 |
RunTestIf("job-list", qa_job.TestJobList)
|
314 |
|
315 |
|
316 |
def RunCommonNodeTests(): |
317 |
"""Run a few common node tests.
|
318 |
|
319 |
"""
|
320 |
RunTestIf("node-volumes", qa_node.TestNodeVolumes)
|
321 |
RunTestIf("node-storage", qa_node.TestNodeStorage)
|
322 |
RunTestIf("node-oob", qa_node.TestOutOfBand)
|
323 |
|
324 |
|
325 |
def RunGroupListTests(): |
326 |
"""Run tests for listing node groups.
|
327 |
|
328 |
"""
|
329 |
RunTestIf("group-list", qa_group.TestGroupList)
|
330 |
RunTestIf("group-list", qa_group.TestGroupListFields)
|
331 |
|
332 |
|
333 |
def RunGroupRwTests(): |
334 |
"""Run tests for adding/removing/renaming groups.
|
335 |
|
336 |
"""
|
337 |
RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
|
338 |
RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
|
339 |
RunTestIf("group-rwops", qa_group.TestGroupModify)
|
340 |
RunTestIf(["group-rwops", "rapi"], qa_rapi.TestRapiNodeGroups) |
341 |
RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags, |
342 |
qa_group.GetDefaultGroup()) |
343 |
|
344 |
|
345 |
def RunExportImportTests(instance, inodes): |
346 |
"""Tries to export and import the instance.
|
347 |
|
348 |
@type inodes: list of nodes
|
349 |
@param inodes: current nodes of the instance
|
350 |
|
351 |
"""
|
352 |
if qa_config.TestEnabled("instance-export"): |
353 |
RunTest(qa_instance.TestInstanceExportNoTarget, instance) |
354 |
|
355 |
pnode = inodes[0]
|
356 |
expnode = qa_config.AcquireNode(exclude=pnode) |
357 |
try:
|
358 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
359 |
|
360 |
RunTest(qa_instance.TestBackupList, expnode) |
361 |
|
362 |
if qa_config.TestEnabled("instance-import"): |
363 |
newinst = qa_config.AcquireInstance() |
364 |
try:
|
365 |
RunTest(qa_instance.TestInstanceImport, newinst, pnode, |
366 |
expnode, name) |
367 |
# Check if starting the instance works
|
368 |
RunTest(qa_instance.TestInstanceStartup, newinst) |
369 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
370 |
finally:
|
371 |
qa_config.ReleaseInstance(newinst) |
372 |
finally:
|
373 |
qa_config.ReleaseNode(expnode) |
374 |
|
375 |
if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]): |
376 |
newinst = qa_config.AcquireInstance() |
377 |
try:
|
378 |
tnode = qa_config.AcquireNode(exclude=inodes) |
379 |
try:
|
380 |
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst, |
381 |
inodes, tnode) |
382 |
finally:
|
383 |
qa_config.ReleaseNode(tnode) |
384 |
finally:
|
385 |
qa_config.ReleaseInstance(newinst) |
386 |
|
387 |
|
388 |
def RunDaemonTests(instance): |
389 |
"""Test the ganeti-watcher script.
|
390 |
|
391 |
"""
|
392 |
RunTest(qa_daemon.TestPauseWatcher) |
393 |
|
394 |
RunTestIf("instance-automatic-restart",
|
395 |
qa_daemon.TestInstanceAutomaticRestart, instance) |
396 |
RunTestIf("instance-consecutive-failures",
|
397 |
qa_daemon.TestInstanceConsecutiveFailures, instance) |
398 |
|
399 |
RunTest(qa_daemon.TestResumeWatcher) |
400 |
|
401 |
|
402 |
def RunHardwareFailureTests(instance, inodes): |
403 |
"""Test cluster internal hardware failure recovery.
|
404 |
|
405 |
"""
|
406 |
RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
|
407 |
RunTestIf(["instance-failover", "rapi"], |
408 |
qa_rapi.TestRapiInstanceFailover, instance) |
409 |
|
410 |
RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
|
411 |
RunTestIf(["instance-migrate", "rapi"], |
412 |
qa_rapi.TestRapiInstanceMigrate, instance) |
413 |
|
414 |
if qa_config.TestEnabled("instance-replace-disks"): |
415 |
# We just need alternative secondary nodes, hence "- 1"
|
416 |
othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes) |
417 |
try:
|
418 |
RunTestIf("rapi", qa_rapi.TestRapiInstanceReplaceDisks, instance)
|
419 |
RunTest(qa_instance.TestReplaceDisks, |
420 |
instance, inodes, othernodes) |
421 |
finally:
|
422 |
qa_config.ReleaseManyNodes(othernodes) |
423 |
del othernodes
|
424 |
|
425 |
if qa_config.TestEnabled("instance-recreate-disks"): |
426 |
try:
|
427 |
acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
|
428 |
othernodes = acquirednodes |
429 |
except qa_error.OutOfNodesError:
|
430 |
if len(inodes) > 1: |
431 |
# If the cluster is not big enough, let's reuse some of the nodes, but
|
432 |
# with different roles. In this way, we can test a DRBD instance even on
|
433 |
# a 3-node cluster.
|
434 |
acquirednodes = [qa_config.AcquireNode(exclude=inodes)] |
435 |
othernodes = acquirednodes + inodes[:-1]
|
436 |
else:
|
437 |
raise
|
438 |
try:
|
439 |
RunTest(qa_instance.TestRecreateDisks, |
440 |
instance, inodes, othernodes) |
441 |
finally:
|
442 |
qa_config.ReleaseManyNodes(acquirednodes) |
443 |
|
444 |
if len(inodes) >= 2: |
445 |
RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1]) |
446 |
RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1]) |
447 |
|
448 |
|
449 |
def RunExclusiveStorageTests(): |
450 |
"""Test exclusive storage."""
|
451 |
if not qa_config.TestEnabled("cluster-exclusive-storage"): |
452 |
return
|
453 |
|
454 |
node = qa_config.AcquireNode() |
455 |
try:
|
456 |
old_es = qa_cluster.TestSetExclStorCluster(False)
|
457 |
qa_node.TestExclStorSingleNode(node) |
458 |
|
459 |
qa_cluster.TestSetExclStorCluster(True)
|
460 |
qa_cluster.TestExclStorSharedPv(node) |
461 |
|
462 |
if qa_config.TestEnabled("instance-add-plain-disk"): |
463 |
# Make sure that the cluster doesn't have any pre-existing problem
|
464 |
qa_cluster.AssertClusterVerify() |
465 |
instance1 = qa_instance.TestInstanceAddWithPlainDisk([node]) |
466 |
instance2 = qa_instance.TestInstanceAddWithPlainDisk([node]) |
467 |
# cluster-verify checks that disks are allocated correctly
|
468 |
qa_cluster.AssertClusterVerify() |
469 |
qa_instance.TestInstanceRemove(instance1) |
470 |
qa_instance.TestInstanceRemove(instance2) |
471 |
if qa_config.TestEnabled("instance-add-drbd-disk"): |
472 |
snode = qa_config.AcquireNode() |
473 |
try:
|
474 |
qa_cluster.TestSetExclStorCluster(False)
|
475 |
instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode]) |
476 |
qa_cluster.TestSetExclStorCluster(True)
|
477 |
exp_err = [constants.CV_EINSTANCEUNSUITABLENODE] |
478 |
qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
|
479 |
qa_instance.TestInstanceRemove(instance) |
480 |
finally:
|
481 |
qa_config.ReleaseNode(snode) |
482 |
qa_cluster.TestSetExclStorCluster(old_es) |
483 |
finally:
|
484 |
qa_config.ReleaseNode(node) |
485 |
|
486 |
|
487 |
def _BuildSpecDict(par, mn, st, mx): |
488 |
return {par: {"min": mn, "std": st, "max": mx}} |
489 |
|
490 |
|
491 |
def TestIPolicyPlainInstance(): |
492 |
"""Test instance policy interaction with instances"""
|
493 |
params = ["mem-size", "cpu-count", "disk-count", "disk-size", "nic-count"] |
494 |
if not qa_config.IsTemplateSupported(constants.DT_PLAIN): |
495 |
print "Template %s not supported" % constants.DT_PLAIN |
496 |
return
|
497 |
|
498 |
# This test assumes that the group policy is empty
|
499 |
(_, old_specs) = qa_cluster.TestClusterSetISpecs({}) |
500 |
node = qa_config.AcquireNode() |
501 |
try:
|
502 |
# Log of policy changes, list of tuples: (change, policy_violated)
|
503 |
history = [] |
504 |
instance = qa_instance.TestInstanceAddWithPlainDisk([node]) |
505 |
try:
|
506 |
policyerror = [constants.CV_EINSTANCEPOLICY] |
507 |
for par in params: |
508 |
qa_cluster.AssertClusterVerify() |
509 |
(iminval, imaxval) = qa_instance.GetInstanceSpec(instance["name"], par)
|
510 |
# Some specs must be multiple of 4
|
511 |
new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4) |
512 |
history.append((new_spec, True))
|
513 |
qa_cluster.TestClusterSetISpecs(new_spec) |
514 |
qa_cluster.AssertClusterVerify(warnings=policyerror) |
515 |
if iminval > 0: |
516 |
# Some specs must be multiple of 4
|
517 |
if iminval >= 4: |
518 |
upper = iminval - 4
|
519 |
else:
|
520 |
upper = iminval - 1
|
521 |
new_spec = _BuildSpecDict(par, 0, upper, upper)
|
522 |
history.append((new_spec, True))
|
523 |
qa_cluster.TestClusterSetISpecs(new_spec) |
524 |
qa_cluster.AssertClusterVerify(warnings=policyerror) |
525 |
qa_cluster.TestClusterSetISpecs(old_specs) |
526 |
history.append((old_specs, False))
|
527 |
qa_instance.TestInstanceRemove(instance) |
528 |
finally:
|
529 |
qa_config.ReleaseInstance(instance) |
530 |
|
531 |
# Now we replay the same policy changes, and we expect that the instance
|
532 |
# cannot be created for the cases where we had a policy violation above
|
533 |
for (change, failed) in history: |
534 |
qa_cluster.TestClusterSetISpecs(change) |
535 |
if failed:
|
536 |
qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
|
537 |
# Instance creation with no policy violation has been tested already
|
538 |
finally:
|
539 |
qa_config.ReleaseNode(node) |
540 |
|
541 |
|
542 |
def RunInstanceTests(): |
543 |
"""Create and exercise instances."""
|
544 |
instance_tests = [ |
545 |
("instance-add-plain-disk", constants.DT_PLAIN,
|
546 |
qa_instance.TestInstanceAddWithPlainDisk, 1),
|
547 |
("instance-add-drbd-disk", constants.DT_DRBD8,
|
548 |
qa_instance.TestInstanceAddWithDrbdDisk, 2),
|
549 |
] |
550 |
|
551 |
for (test_name, templ, create_fun, num_nodes) in instance_tests: |
552 |
if (qa_config.TestEnabled(test_name) and |
553 |
qa_config.IsTemplateSupported(templ)): |
554 |
inodes = qa_config.AcquireManyNodes(num_nodes) |
555 |
try:
|
556 |
instance = RunTest(create_fun, inodes) |
557 |
|
558 |
RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
|
559 |
RunDaemonTests(instance) |
560 |
for node in inodes: |
561 |
RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
|
562 |
if len(inodes) > 1: |
563 |
RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
|
564 |
constants.INITIAL_NODE_GROUP_NAME, |
565 |
inodes[0]["primary"], inodes[1]["primary"]) |
566 |
if qa_config.TestEnabled("instance-convert-disk"): |
567 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
568 |
RunTest(qa_instance.TestInstanceConvertDiskToPlain, instance, inodes) |
569 |
RunTest(qa_instance.TestInstanceStartup, instance) |
570 |
RunTestIf("instance-modify-disks", qa_instance.TestInstanceModifyDisks,
|
571 |
instance) |
572 |
RunCommonInstanceTests(instance) |
573 |
RunGroupListTests() |
574 |
RunExportImportTests(instance, inodes) |
575 |
RunHardwareFailureTests(instance, inodes) |
576 |
RunRepairDiskSizes() |
577 |
RunTest(qa_instance.TestInstanceRemove, instance) |
578 |
del instance
|
579 |
finally:
|
580 |
qa_config.ReleaseManyNodes(inodes) |
581 |
qa_cluster.AssertClusterVerify() |
582 |
|
583 |
|
584 |
def RunQa(): |
585 |
"""Main QA body.
|
586 |
|
587 |
"""
|
588 |
rapi_user = "ganeti-qa"
|
589 |
rapi_secret = utils.GenerateSecret() |
590 |
|
591 |
RunEnvTests() |
592 |
SetupCluster(rapi_user, rapi_secret) |
593 |
|
594 |
# Load RAPI certificate
|
595 |
qa_rapi.Setup(rapi_user, rapi_secret) |
596 |
|
597 |
RunClusterTests() |
598 |
RunOsTests() |
599 |
|
600 |
RunTestIf("tags", qa_tags.TestClusterTags)
|
601 |
|
602 |
RunCommonNodeTests() |
603 |
RunGroupListTests() |
604 |
RunGroupRwTests() |
605 |
|
606 |
# The master shouldn't be readded or put offline; "delay" needs a non-master
|
607 |
# node to test
|
608 |
pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode()) |
609 |
try:
|
610 |
RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
|
611 |
RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
|
612 |
RunTestIf("delay", qa_cluster.TestDelay, pnode)
|
613 |
finally:
|
614 |
qa_config.ReleaseNode(pnode) |
615 |
|
616 |
# Make sure the cluster is clean before running instance tests
|
617 |
qa_cluster.AssertClusterVerify() |
618 |
|
619 |
pnode = qa_config.AcquireNode() |
620 |
try:
|
621 |
RunTestIf("tags", qa_tags.TestNodeTags, pnode)
|
622 |
|
623 |
if qa_rapi.Enabled():
|
624 |
RunTest(qa_rapi.TestNode, pnode) |
625 |
|
626 |
if qa_config.TestEnabled("instance-add-plain-disk"): |
627 |
for use_client in [True, False]: |
628 |
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode, |
629 |
use_client) |
630 |
if qa_config.TestEnabled("instance-plain-rapi-common-tests"): |
631 |
RunCommonInstanceTests(rapi_instance) |
632 |
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client) |
633 |
del rapi_instance
|
634 |
|
635 |
finally:
|
636 |
qa_config.ReleaseNode(pnode) |
637 |
|
638 |
config_list = [ |
639 |
("default-instance-tests", lambda: None, lambda _: None), |
640 |
("exclusive-storage-instance-tests",
|
641 |
lambda: qa_cluster.TestSetExclStorCluster(True), |
642 |
qa_cluster.TestSetExclStorCluster), |
643 |
] |
644 |
for (conf_name, setup_conf_f, restore_conf_f) in config_list: |
645 |
if qa_config.TestEnabled(conf_name):
|
646 |
oldconf = setup_conf_f() |
647 |
RunInstanceTests() |
648 |
restore_conf_f(oldconf) |
649 |
|
650 |
pnode = qa_config.AcquireNode() |
651 |
try:
|
652 |
if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]): |
653 |
for shutdown in [False, True]: |
654 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode]) |
655 |
expnode = qa_config.AcquireNode(exclude=pnode) |
656 |
try:
|
657 |
if shutdown:
|
658 |
# Stop instance before exporting and removing it
|
659 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
660 |
RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode) |
661 |
RunTest(qa_instance.TestBackupList, expnode) |
662 |
finally:
|
663 |
qa_config.ReleaseNode(expnode) |
664 |
del expnode
|
665 |
del instance
|
666 |
qa_cluster.AssertClusterVerify() |
667 |
|
668 |
finally:
|
669 |
qa_config.ReleaseNode(pnode) |
670 |
|
671 |
RunExclusiveStorageTests() |
672 |
RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"], |
673 |
TestIPolicyPlainInstance) |
674 |
|
675 |
# Test removing instance with offline drbd secondary
|
676 |
if qa_config.TestEnabled("instance-remove-drbd-offline"): |
677 |
# Make sure the master is not put offline
|
678 |
snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode()) |
679 |
try:
|
680 |
pnode = qa_config.AcquireNode(exclude=snode) |
681 |
try:
|
682 |
instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode]) |
683 |
set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes") |
684 |
set_online = lambda node: qa_node.MakeNodeOffline(node, "no") |
685 |
RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode, |
686 |
set_offline, set_online) |
687 |
finally:
|
688 |
qa_config.ReleaseNode(pnode) |
689 |
finally:
|
690 |
qa_config.ReleaseNode(snode) |
691 |
qa_cluster.AssertClusterVerify() |
692 |
|
693 |
RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
|
694 |
|
695 |
RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
|
696 |
|
697 |
|
698 |
@UsesRapiClient
|
699 |
def main(): |
700 |
"""Main program.
|
701 |
|
702 |
"""
|
703 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>")
|
704 |
parser.add_option("--yes-do-it", dest="yes_do_it", |
705 |
action="store_true",
|
706 |
help="Really execute the tests")
|
707 |
(qa_config.options, args) = parser.parse_args() |
708 |
|
709 |
if len(args) == 1: |
710 |
(config_file, ) = args |
711 |
else:
|
712 |
parser.error("Wrong number of arguments.")
|
713 |
|
714 |
if not qa_config.options.yes_do_it: |
715 |
print ("Executing this script irreversibly destroys any Ganeti\n" |
716 |
"configuration on all nodes involved. If you really want\n"
|
717 |
"to start testing, supply the --yes-do-it option.")
|
718 |
sys.exit(1)
|
719 |
|
720 |
qa_config.Load(config_file) |
721 |
|
722 |
primary = qa_config.GetMasterNode()["primary"]
|
723 |
qa_utils.StartMultiplexer(primary) |
724 |
print ("SSH command for primary node: %s" % |
725 |
utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
|
726 |
print ("SSH command for other nodes: %s" % |
727 |
utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", ""))) |
728 |
try:
|
729 |
RunQa() |
730 |
finally:
|
731 |
qa_utils.CloseMultiplexers() |
732 |
|
733 |
if __name__ == "__main__": |
734 |
main() |