4 # Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
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.
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.
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
22 """Script for doing QA on Ganeti.
26 # pylint: disable=C0103
50 from ganeti import utils
51 from ganeti import rapi # pylint: disable=W0611
52 from ganeti import constants
53 from ganeti import pathutils
55 from ganeti.http.auth import ParsePasswordFile
56 import ganeti.rapi.client # pylint: disable=W0611
57 from ganeti.rapi.client import UsesRapiClient
60 def _FormatHeader(line, end=72):
61 """Fill a line up to the end column.
64 line = "---- " + line + " "
65 line += "-" * (end - len(line))
70 def _DescriptionOf(fn):
71 """Computes the description of an item.
75 desc = fn.__doc__.splitlines()[0].strip()
79 return desc.rstrip(".")
82 def RunTest(fn, *args, **kwargs):
83 """Runs a test after printing a header.
87 tstart = datetime.datetime.now()
89 desc = _DescriptionOf(fn)
92 print _FormatHeader("%s start %s" % (tstart, desc))
95 retval = fn(*args, **kwargs)
98 tstop = datetime.datetime.now()
99 tdelta = tstop - tstart
100 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
103 def RunTestIf(testnames, fn, *args, **kwargs):
104 """Runs a test conditionally.
106 @param testnames: either a single test name in the configuration
107 file, or a list of testnames (which will be AND-ed together)
110 if qa_config.TestEnabled(testnames):
111 RunTest(fn, *args, **kwargs)
113 tstart = datetime.datetime.now()
114 desc = _DescriptionOf(fn)
115 # TODO: Formatting test names when non-string names are involved
116 print _FormatHeader("%s skipping %s, test(s) %s disabled" %
117 (tstart, desc, testnames))
121 """Run several environment tests.
124 RunTestIf("env", qa_env.TestSshConnection)
125 RunTestIf("env", qa_env.TestIcmpPing)
126 RunTestIf("env", qa_env.TestGanetiCommands)
129 def _LookupRapiSecret(rapi_user):
130 """Find the RAPI secret for the given user.
132 @param rapi_user: Login user
133 @return: Login secret for the user
136 CTEXT = "{CLEARTEXT}"
137 master = qa_config.GetMasterNode()
138 cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)]
139 file_content = qa_utils.GetCommandOutput(master.primary,
140 utils.ShellQuoteArgs(cmd))
141 users = ParsePasswordFile(file_content)
142 entry = users.get(rapi_user)
144 raise qa_error.Error("User %s not found in RAPI users file" % rapi_user)
145 secret = entry.password
146 if secret.upper().startswith(CTEXT):
147 secret = secret[len(CTEXT):]
148 elif secret.startswith("{"):
149 raise qa_error.Error("Unsupported password schema for RAPI user %s:"
150 " not a clear text password" % rapi_user)
154 def SetupCluster(rapi_user):
155 """Initializes the cluster.
157 @param rapi_user: Login user for RAPI
158 @return: Login secret for RAPI
161 rapi_secret = utils.GenerateSecret()
162 RunTestIf("create-cluster", qa_cluster.TestClusterInit,
163 rapi_user, rapi_secret)
164 if not qa_config.TestEnabled("create-cluster"):
165 # If the cluster is already in place, we assume that exclusive-storage is
166 # already set according to the configuration
167 qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
168 if qa_rapi.Enabled():
169 # To support RAPI on an existing cluster we have to find out the secret
170 rapi_secret = _LookupRapiSecret(rapi_user)
172 # Test on empty cluster
173 RunTestIf("node-list", qa_node.TestNodeList)
174 RunTestIf("instance-list", qa_instance.TestInstanceList)
175 RunTestIf("job-list", qa_job.TestJobList)
177 RunTestIf("create-cluster", qa_node.TestNodeAddAll)
178 if not qa_config.TestEnabled("create-cluster"):
179 # consider the nodes are already there
180 qa_node.MarkNodeAddedAll()
182 RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
184 # enable the watcher (unconditionally)
185 RunTest(qa_daemon.TestResumeWatcher)
187 RunTestIf("node-list", qa_node.TestNodeList)
189 # Test listing fields
190 RunTestIf("node-list", qa_node.TestNodeListFields)
191 RunTestIf("instance-list", qa_instance.TestInstanceListFields)
192 RunTestIf("job-list", qa_job.TestJobListFields)
193 RunTestIf("instance-export", qa_instance.TestBackupListFields)
195 RunTestIf("node-info", qa_node.TestNodeInfo)
200 def RunClusterTests():
201 """Runs tests related to gnt-cluster.
205 ("create-cluster", qa_cluster.TestClusterInitDisk),
206 ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
207 ("cluster-verify", qa_cluster.TestClusterVerify),
208 ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
209 # TODO: add more cluster modify tests
210 ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
211 ("cluster-modify", qa_cluster.TestClusterModifyIPolicy),
212 ("cluster-modify", qa_cluster.TestClusterModifyISpecs),
213 ("cluster-modify", qa_cluster.TestClusterModifyBe),
214 ("cluster-modify", qa_cluster.TestClusterModifyDisk),
215 ("cluster-modify", qa_cluster.TestClusterModifyDiskTemplates),
216 ("cluster-modify", qa_cluster.TestClusterModifyFileStorageDir),
217 ("cluster-modify", qa_cluster.TestClusterModifySharedFileStorageDir),
218 ("cluster-rename", qa_cluster.TestClusterRename),
219 ("cluster-info", qa_cluster.TestClusterVersion),
220 ("cluster-info", qa_cluster.TestClusterInfo),
221 ("cluster-info", qa_cluster.TestClusterGetmaster),
222 ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
223 (["cluster-copyfile", qa_config.NoVirtualCluster],
224 qa_cluster.TestClusterCopyfile),
225 ("cluster-command", qa_cluster.TestClusterCommand),
226 ("cluster-burnin", qa_cluster.TestClusterBurnin),
227 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
228 ("cluster-master-failover",
229 qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
230 (["cluster-oob", qa_config.NoVirtualCluster],
231 qa_cluster.TestClusterOob),
232 (qa_rapi.Enabled, qa_rapi.TestVersion),
233 (qa_rapi.Enabled, qa_rapi.TestEmptyCluster),
234 (qa_rapi.Enabled, qa_rapi.TestRapiQuery),
239 def RunRepairDiskSizes():
240 """Run the repair disk-sizes test.
243 RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
247 """Runs all tests related to gnt-os.
250 os_enabled = ["os", qa_config.NoVirtualCluster]
252 if qa_config.TestEnabled(qa_rapi.Enabled):
253 rapi_getos = qa_rapi.GetOperatingSystems
259 qa_os.TestOsDiagnose,
261 RunTestIf(os_enabled, fn)
266 qa_os.TestOsPartiallyValid,
268 RunTestIf(os_enabled, fn, rapi_getos)
271 qa_os.TestOsModifyValid,
272 qa_os.TestOsModifyInvalid,
273 qa_os.TestOsStatesNonExisting,
275 RunTestIf(os_enabled, fn)
278 def RunCommonInstanceTests(instance, inst_nodes):
279 """Runs a few tests that are common to all disk types.
282 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
283 RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
284 qa_rapi.TestRapiStoppedInstanceConsole, instance)
285 RunTestIf(["instance-shutdown", "instance-modify"],
286 qa_instance.TestInstanceStoppedModify, instance)
287 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
289 # Test shutdown/start via RAPI
290 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
291 qa_rapi.TestRapiInstanceShutdown, instance)
292 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
293 qa_rapi.TestRapiInstanceStartup, instance)
295 RunTestIf("instance-list", qa_instance.TestInstanceList)
297 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
299 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
300 RunTestIf(["instance-modify", qa_rapi.Enabled],
301 qa_rapi.TestRapiInstanceModify, instance)
303 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
304 RunTestIf(["instance-console", qa_rapi.Enabled],
305 qa_rapi.TestRapiInstanceConsole, instance)
307 RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
309 DOWN_TESTS = qa_config.Either([
310 "instance-reinstall",
312 "instance-grow-disk",
315 # shutdown instance for any 'down' tests
316 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
318 # now run the 'down' state tests
319 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
320 RunTestIf(["instance-reinstall", qa_rapi.Enabled],
321 qa_rapi.TestRapiInstanceReinstall, instance)
323 if qa_config.TestEnabled("instance-rename"):
324 tgt_instance = qa_config.AcquireInstance()
326 rename_source = instance.name
327 rename_target = tgt_instance.name
328 # perform instance rename to the same name
329 RunTest(qa_instance.TestInstanceRenameAndBack,
330 rename_source, rename_source)
331 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
332 rename_source, rename_source)
333 if rename_target is not None:
334 # perform instance rename to a different name, if we have one configured
335 RunTest(qa_instance.TestInstanceRenameAndBack,
336 rename_source, rename_target)
337 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
338 rename_source, rename_target)
340 tgt_instance.Release()
342 RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
344 # and now start the instance again
345 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
347 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
349 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
351 if instance.disk_template == constants.DT_DRBD8:
352 RunTestIf("cluster-verify",
353 qa_cluster.TestClusterVerifyDisksBrokenDRBD, instance, inst_nodes)
354 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
356 RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)
358 # Lists instances, too
359 RunTestIf("node-list", qa_node.TestNodeList)
361 # Some jobs have been run, let's test listing them
362 RunTestIf("job-list", qa_job.TestJobList)
365 def RunCommonNodeTests():
366 """Run a few common node tests.
369 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
370 RunTestIf("node-storage", qa_node.TestNodeStorage)
371 RunTestIf(["node-oob", qa_config.NoVirtualCluster], qa_node.TestOutOfBand)
374 def RunGroupListTests():
375 """Run tests for listing node groups.
378 RunTestIf("group-list", qa_group.TestGroupList)
379 RunTestIf("group-list", qa_group.TestGroupListFields)
382 def RunNetworkTests():
383 """Run tests for network management.
386 RunTestIf("network", qa_network.TestNetworkAddRemove)
387 RunTestIf("network", qa_network.TestNetworkConnect)
390 def RunGroupRwTests():
391 """Run tests for adding/removing/renaming groups.
394 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
395 RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
396 RunTestIf("group-rwops", qa_group.TestGroupModify)
397 RunTestIf(["group-rwops", qa_rapi.Enabled], qa_rapi.TestRapiNodeGroups)
398 RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
399 qa_group.GetDefaultGroup())
402 def RunExportImportTests(instance, inodes):
403 """Tries to export and import the instance.
405 @type inodes: list of nodes
406 @param inodes: current nodes of the instance
409 # FIXME: export explicitly bails out on file based storage. other non-lvm
410 # based storage types are untested, though. Also note that import could still
411 # work, but is deeply embedded into the "export" case.
412 if (qa_config.TestEnabled("instance-export") and
413 instance.disk_template not in [constants.DT_FILE,
414 constants.DT_SHARED_FILE]):
415 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
418 expnode = qa_config.AcquireNode(exclude=pnode)
420 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
422 RunTest(qa_instance.TestBackupList, expnode)
424 if qa_config.TestEnabled("instance-import"):
425 newinst = qa_config.AcquireInstance()
427 RunTest(qa_instance.TestInstanceImport, newinst, pnode,
429 # Check if starting the instance works
430 RunTest(qa_instance.TestInstanceStartup, newinst)
431 RunTest(qa_instance.TestInstanceRemove, newinst)
437 # FIXME: inter-cluster-instance-move crashes on file based instances :/
439 if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
440 and (instance.disk_template not in
441 [constants.DT_FILE, constants.DT_SHARED_FILE])):
442 newinst = qa_config.AcquireInstance()
444 tnode = qa_config.AcquireNode(exclude=inodes)
446 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
454 def RunDaemonTests(instance):
455 """Test the ganeti-watcher script.
458 RunTest(qa_daemon.TestPauseWatcher)
460 RunTestIf("instance-automatic-restart",
461 qa_daemon.TestInstanceAutomaticRestart, instance)
462 RunTestIf("instance-consecutive-failures",
463 qa_daemon.TestInstanceConsecutiveFailures, instance)
465 RunTest(qa_daemon.TestResumeWatcher)
468 def RunHardwareFailureTests(instance, inodes):
469 """Test cluster internal hardware failure recovery.
472 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
473 RunTestIf(["instance-failover", qa_rapi.Enabled],
474 qa_rapi.TestRapiInstanceFailover, instance)
476 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
477 RunTestIf(["instance-migrate", qa_rapi.Enabled],
478 qa_rapi.TestRapiInstanceMigrate, instance)
480 if qa_config.TestEnabled("instance-replace-disks"):
481 # We just need alternative secondary nodes, hence "- 1"
482 othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
484 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
485 RunTest(qa_instance.TestReplaceDisks,
486 instance, inodes, othernodes)
488 qa_config.ReleaseManyNodes(othernodes)
491 if qa_config.TestEnabled("instance-recreate-disks"):
493 acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
494 othernodes = acquirednodes
495 except qa_error.OutOfNodesError:
497 # If the cluster is not big enough, let's reuse some of the nodes, but
498 # with different roles. In this way, we can test a DRBD instance even on
500 acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
501 othernodes = acquirednodes + inodes[:-1]
505 RunTest(qa_instance.TestRecreateDisks,
506 instance, inodes, othernodes)
508 qa_config.ReleaseManyNodes(acquirednodes)
511 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
512 RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
513 RunTestIf("node-migrate", qa_node.TestNodeMigrate, inodes[0], inodes[1])
516 def RunExclusiveStorageTests():
517 """Test exclusive storage."""
518 if not qa_config.TestEnabled("cluster-exclusive-storage"):
521 node = qa_config.AcquireNode()
523 old_es = qa_cluster.TestSetExclStorCluster(False)
524 qa_node.TestExclStorSingleNode(node)
526 qa_cluster.TestSetExclStorCluster(True)
527 qa_cluster.TestExclStorSharedPv(node)
529 if qa_config.TestEnabled("instance-add-plain-disk"):
530 # Make sure that the cluster doesn't have any pre-existing problem
531 qa_cluster.AssertClusterVerify()
533 # Create and allocate instances
534 instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
536 instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
538 # cluster-verify checks that disks are allocated correctly
539 qa_cluster.AssertClusterVerify()
542 qa_instance.TestInstanceRemove(instance2)
543 qa_instance.TestInstanceRemove(instance1)
549 if qa_config.TestEnabled("instance-add-drbd-disk"):
550 snode = qa_config.AcquireNode()
552 qa_cluster.TestSetExclStorCluster(False)
553 instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
555 qa_cluster.TestSetExclStorCluster(True)
556 exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
557 qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
558 qa_instance.TestInstanceRemove(instance)
563 qa_cluster.TestSetExclStorCluster(old_es)
568 def _BuildSpecDict(par, mn, st, mx):
570 constants.ISPECS_MINMAX: [{
571 constants.ISPECS_MIN: {par: mn},
572 constants.ISPECS_MAX: {par: mx},
574 constants.ISPECS_STD: {par: st},
578 def _BuildDoubleSpecDict(index, par, mn, st, mx):
580 constants.ISPECS_MINMAX: [{}, {}],
583 new_spec[constants.ISPECS_STD] = {par: st}
584 new_spec[constants.ISPECS_MINMAX][index] = {
585 constants.ISPECS_MIN: {par: mn},
586 constants.ISPECS_MAX: {par: mx},
591 def TestIPolicyPlainInstance():
592 """Test instance policy interaction with instances"""
593 params = ["memory-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
594 if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
595 print "Template %s not supported" % constants.DT_PLAIN
598 # This test assumes that the group policy is empty
599 (_, old_specs) = qa_cluster.TestClusterSetISpecs()
600 # We also assume to have only one min/max bound
601 assert len(old_specs[constants.ISPECS_MINMAX]) == 1
602 node = qa_config.AcquireNode()
604 # Log of policy changes, list of tuples:
605 # (full_change, incremental_change, policy_violated)
607 instance = qa_instance.TestInstanceAddWithPlainDisk([node])
609 policyerror = [constants.CV_EINSTANCEPOLICY]
611 (iminval, imaxval) = qa_instance.GetInstanceSpec(instance.name, par)
612 # Some specs must be multiple of 4
613 new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
614 history.append((None, new_spec, True))
616 # Some specs must be multiple of 4
621 new_spec = _BuildSpecDict(par, 0, upper, upper)
622 history.append((None, new_spec, True))
623 history.append((old_specs, None, False))
625 # Test with two instance specs
626 double_specs = copy.deepcopy(old_specs)
627 double_specs[constants.ISPECS_MINMAX] = \
628 double_specs[constants.ISPECS_MINMAX] * 2
629 (par1, par2) = params[0:2]
630 (_, imaxval1) = qa_instance.GetInstanceSpec(instance.name, par1)
631 (_, imaxval2) = qa_instance.GetInstanceSpec(instance.name, par2)
632 old_minmax = old_specs[constants.ISPECS_MINMAX][0]
634 (double_specs, None, False),
635 # The first min/max limit is being violated
637 _BuildDoubleSpecDict(0, par1, imaxval1 + 4, imaxval1 + 4,
640 # Both min/max limits are being violated
642 _BuildDoubleSpecDict(1, par2, imaxval2 + 4, None, imaxval2 + 4),
644 # The second min/max limit is being violated
646 _BuildDoubleSpecDict(0, par1,
647 old_minmax[constants.ISPECS_MIN][par1],
648 old_specs[constants.ISPECS_STD][par1],
649 old_minmax[constants.ISPECS_MAX][par1]),
651 (old_specs, None, False),
654 # Apply the changes, and check policy violations after each change
655 qa_cluster.AssertClusterVerify()
656 for (new_specs, diff_specs, failed) in history:
657 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
658 diff_specs=diff_specs)
660 qa_cluster.AssertClusterVerify(warnings=policyerror)
662 qa_cluster.AssertClusterVerify()
664 qa_instance.TestInstanceRemove(instance)
668 # Now we replay the same policy changes, and we expect that the instance
669 # cannot be created for the cases where we had a policy violation above
670 for (new_specs, diff_specs, failed) in history:
671 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
672 diff_specs=diff_specs)
674 qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
675 # Instance creation with no policy violation has been tested already
680 def IsExclusiveStorageInstanceTestEnabled():
681 test_name = "exclusive-storage-instance-tests"
682 if qa_config.TestEnabled(test_name):
683 vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
684 vgscmd = utils.ShellQuoteArgs([
685 "vgs", "--noheadings", "-o", "pv_count", vgname,
687 nodes = qa_config.GetConfig()["nodes"]
690 pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
692 msg = ("Cannot get the number of PVs on %s, needed by '%s': %s" %
693 (node.primary, test_name, e))
694 raise qa_error.Error(msg)
696 raise qa_error.Error("Node %s has not enough PVs (%s) to run '%s'" %
697 (node.primary, pvnum, test_name))
704 def RunInstanceTests():
705 """Create and exercise instances."""
707 ("instance-add-plain-disk", constants.DT_PLAIN,
708 qa_instance.TestInstanceAddWithPlainDisk, 1),
709 ("instance-add-drbd-disk", constants.DT_DRBD8,
710 qa_instance.TestInstanceAddWithDrbdDisk, 2),
711 ("instance-add-diskless", constants.DT_DISKLESS,
712 qa_instance.TestInstanceAddDiskless, 1),
713 ("instance-add-file", constants.DT_FILE,
714 qa_instance.TestInstanceAddFile, 1),
715 ("instance-add-shared-file", constants.DT_SHARED_FILE,
716 qa_instance.TestInstanceAddSharedFile, 1),
719 for (test_name, templ, create_fun, num_nodes) in instance_tests:
720 if (qa_config.TestEnabled(test_name) and
721 qa_config.IsTemplateSupported(templ)):
722 inodes = qa_config.AcquireManyNodes(num_nodes)
724 instance = RunTest(create_fun, inodes)
726 RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
727 RunDaemonTests(instance)
729 RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
731 RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
732 constants.INITIAL_NODE_GROUP_NAME,
733 inodes[0].primary, inodes[1].primary)
734 if qa_config.TestEnabled("instance-convert-disk"):
735 RunTest(qa_instance.TestInstanceShutdown, instance)
736 RunTest(qa_instance.TestInstanceConvertDiskToPlain,
738 RunTest(qa_instance.TestInstanceStartup, instance)
739 RunTestIf("instance-modify-disks",
740 qa_instance.TestInstanceModifyDisks, instance)
741 RunCommonInstanceTests(instance, inodes)
742 if qa_config.TestEnabled("instance-modify-primary"):
743 othernode = qa_config.AcquireNode()
744 RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
745 instance, inodes[0], othernode)
748 RunExportImportTests(instance, inodes)
749 RunHardwareFailureTests(instance, inodes)
751 RunTest(qa_instance.TestInstanceRemove, instance)
756 qa_config.ReleaseManyNodes(inodes)
757 qa_cluster.AssertClusterVerify()
760 def RunMonitoringTests():
761 if qa_config.TestEnabled("mon-collector"):
762 RunTest(qa_monitoring.TestInstStatusCollector)
769 rapi_user = "ganeti-qa"
772 rapi_secret = SetupCluster(rapi_user)
774 if qa_rapi.Enabled():
775 # Load RAPI certificate
776 qa_rapi.Setup(rapi_user, rapi_secret)
781 RunTestIf("tags", qa_tags.TestClusterTags)
788 # The master shouldn't be readded or put offline; "delay" needs a non-master
790 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
792 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
793 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
794 RunTestIf("delay", qa_cluster.TestDelay, pnode)
798 # Make sure the cluster is clean before running instance tests
799 qa_cluster.AssertClusterVerify()
801 pnode = qa_config.AcquireNode()
803 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
805 if qa_rapi.Enabled():
806 RunTest(qa_rapi.TestNode, pnode)
808 if (qa_config.TestEnabled("instance-add-plain-disk")
809 and qa_config.IsTemplateSupported(constants.DT_PLAIN)):
810 for use_client in [True, False]:
811 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
814 if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
815 RunCommonInstanceTests(rapi_instance, [pnode])
816 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
818 rapi_instance.Release()
825 ("default-instance-tests", lambda: None, lambda _: None),
826 (IsExclusiveStorageInstanceTestEnabled,
827 lambda: qa_cluster.TestSetExclStorCluster(True),
828 qa_cluster.TestSetExclStorCluster),
830 for (conf_name, setup_conf_f, restore_conf_f) in config_list:
831 if qa_config.TestEnabled(conf_name):
832 oldconf = setup_conf_f()
834 restore_conf_f(oldconf)
836 pnode = qa_config.AcquireNode()
838 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
839 for shutdown in [False, True]:
840 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
842 expnode = qa_config.AcquireNode(exclude=pnode)
845 # Stop instance before exporting and removing it
846 RunTest(qa_instance.TestInstanceShutdown, instance)
847 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
848 RunTest(qa_instance.TestBackupList, expnode)
855 qa_cluster.AssertClusterVerify()
860 RunExclusiveStorageTests()
861 RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
862 TestIPolicyPlainInstance)
865 "instance-add-restricted-by-disktemplates",
866 qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
868 # Test removing instance with offline drbd secondary
869 if qa_config.TestEnabled(["instance-remove-drbd-offline",
870 "instance-add-drbd-disk"]):
871 # Make sure the master is not put offline
872 snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
874 pnode = qa_config.AcquireNode(exclude=snode)
876 instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
877 set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
878 set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
879 RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
880 set_offline, set_online)
885 qa_cluster.AssertClusterVerify()
889 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
891 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
899 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
900 parser.add_option("--yes-do-it", dest="yes_do_it",
902 help="Really execute the tests")
903 (opts, args) = parser.parse_args()
906 (config_file, ) = args
908 parser.error("Wrong number of arguments.")
910 if not opts.yes_do_it:
911 print ("Executing this script irreversibly destroys any Ganeti\n"
912 "configuration on all nodes involved. If you really want\n"
913 "to start testing, supply the --yes-do-it option.")
916 qa_config.Load(config_file)
918 primary = qa_config.GetMasterNode().primary
919 qa_utils.StartMultiplexer(primary)
920 print ("SSH command for primary node: %s" %
921 utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
922 print ("SSH command for other nodes: %s" %
923 utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
927 qa_utils.CloseMultiplexers()
929 if __name__ == "__main__":