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