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
49 from ganeti import utils
50 from ganeti import rapi # pylint: disable=W0611
51 from ganeti import constants
53 import ganeti.rapi.client # pylint: disable=W0611
54 from ganeti.rapi.client import UsesRapiClient
57 def _FormatHeader(line, end=72):
58 """Fill a line up to the end column.
61 line = "---- " + line + " "
62 line += "-" * (end - len(line))
67 def _DescriptionOf(fn):
68 """Computes the description of an item.
72 desc = fn.__doc__.splitlines()[0].strip()
76 return desc.rstrip(".")
79 def RunTest(fn, *args, **kwargs):
80 """Runs a test after printing a header.
84 tstart = datetime.datetime.now()
86 desc = _DescriptionOf(fn)
89 print _FormatHeader("%s start %s" % (tstart, desc))
92 retval = fn(*args, **kwargs)
95 tstop = datetime.datetime.now()
96 tdelta = tstop - tstart
97 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
100 def RunTestIf(testnames, fn, *args, **kwargs):
101 """Runs a test conditionally.
103 @param testnames: either a single test name in the configuration
104 file, or a list of testnames (which will be AND-ed together)
107 if qa_config.TestEnabled(testnames):
108 RunTest(fn, *args, **kwargs)
110 tstart = datetime.datetime.now()
111 desc = _DescriptionOf(fn)
112 # TODO: Formatting test names when non-string names are involved
113 print _FormatHeader("%s skipping %s, test(s) %s disabled" %
114 (tstart, desc, testnames))
118 """Run several environment tests.
121 RunTestIf("env", qa_env.TestSshConnection)
122 RunTestIf("env", qa_env.TestIcmpPing)
123 RunTestIf("env", qa_env.TestGanetiCommands)
126 def SetupCluster(rapi_user, rapi_secret):
127 """Initializes the cluster.
129 @param rapi_user: Login user for RAPI
130 @param rapi_secret: Login secret for RAPI
133 RunTestIf("create-cluster", qa_cluster.TestClusterInit,
134 rapi_user, rapi_secret)
135 if not qa_config.TestEnabled("create-cluster"):
136 # If the cluster is already in place, we assume that exclusive-storage is
137 # already set according to the configuration
138 qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
140 # Test on empty cluster
141 RunTestIf("node-list", qa_node.TestNodeList)
142 RunTestIf("instance-list", qa_instance.TestInstanceList)
143 RunTestIf("job-list", qa_job.TestJobList)
145 RunTestIf("create-cluster", qa_node.TestNodeAddAll)
146 if not qa_config.TestEnabled("create-cluster"):
147 # consider the nodes are already there
148 qa_node.MarkNodeAddedAll()
150 RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
152 # enable the watcher (unconditionally)
153 RunTest(qa_daemon.TestResumeWatcher)
155 RunTestIf("node-list", qa_node.TestNodeList)
157 # Test listing fields
158 RunTestIf("node-list", qa_node.TestNodeListFields)
159 RunTestIf("instance-list", qa_instance.TestInstanceListFields)
160 RunTestIf("job-list", qa_job.TestJobListFields)
161 RunTestIf("instance-export", qa_instance.TestBackupListFields)
163 RunTestIf("node-info", qa_node.TestNodeInfo)
166 def RunClusterTests():
167 """Runs tests related to gnt-cluster.
171 ("create-cluster", qa_cluster.TestClusterInitDisk),
172 ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
173 ("cluster-verify", qa_cluster.TestClusterVerify),
174 ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
175 # TODO: add more cluster modify tests
176 ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
177 ("cluster-modify", qa_cluster.TestClusterModifyIPolicy),
178 ("cluster-modify", qa_cluster.TestClusterModifyISpecs),
179 ("cluster-modify", qa_cluster.TestClusterModifyBe),
180 ("cluster-modify", qa_cluster.TestClusterModifyDisk),
181 ("cluster-modify", qa_cluster.TestClusterModifyDiskTemplates),
182 ("cluster-rename", qa_cluster.TestClusterRename),
183 ("cluster-info", qa_cluster.TestClusterVersion),
184 ("cluster-info", qa_cluster.TestClusterInfo),
185 ("cluster-info", qa_cluster.TestClusterGetmaster),
186 ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
187 (["cluster-copyfile", qa_config.NoVirtualCluster],
188 qa_cluster.TestClusterCopyfile),
189 ("cluster-command", qa_cluster.TestClusterCommand),
190 ("cluster-burnin", qa_cluster.TestClusterBurnin),
191 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
192 ("cluster-master-failover",
193 qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
194 (["cluster-oob", qa_config.NoVirtualCluster],
195 qa_cluster.TestClusterOob),
196 (qa_rapi.Enabled, qa_rapi.TestVersion),
197 (qa_rapi.Enabled, qa_rapi.TestEmptyCluster),
198 (qa_rapi.Enabled, qa_rapi.TestRapiQuery),
203 def RunRepairDiskSizes():
204 """Run the repair disk-sizes test.
207 RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
211 """Runs all tests related to gnt-os.
214 os_enabled = ["os", qa_config.NoVirtualCluster]
216 if qa_config.TestEnabled(qa_rapi.Enabled):
217 rapi_getos = qa_rapi.GetOperatingSystems
223 qa_os.TestOsDiagnose,
225 RunTestIf(os_enabled, fn)
230 qa_os.TestOsPartiallyValid,
232 RunTestIf(os_enabled, fn, rapi_getos)
235 qa_os.TestOsModifyValid,
236 qa_os.TestOsModifyInvalid,
237 qa_os.TestOsStatesNonExisting,
239 RunTestIf(os_enabled, fn)
242 def RunCommonInstanceTests(instance):
243 """Runs a few tests that are common to all disk types.
246 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
247 RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
248 qa_rapi.TestRapiStoppedInstanceConsole, instance)
249 RunTestIf(["instance-shutdown", "instance-modify"],
250 qa_instance.TestInstanceStoppedModify, instance)
251 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
253 # Test shutdown/start via RAPI
254 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
255 qa_rapi.TestRapiInstanceShutdown, instance)
256 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
257 qa_rapi.TestRapiInstanceStartup, instance)
259 RunTestIf("instance-list", qa_instance.TestInstanceList)
261 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
263 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
264 RunTestIf(["instance-modify", qa_rapi.Enabled],
265 qa_rapi.TestRapiInstanceModify, instance)
267 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
268 RunTestIf(["instance-console", qa_rapi.Enabled],
269 qa_rapi.TestRapiInstanceConsole, instance)
271 RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
273 DOWN_TESTS = qa_config.Either([
274 "instance-reinstall",
276 "instance-grow-disk",
279 # shutdown instance for any 'down' tests
280 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
282 # now run the 'down' state tests
283 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
284 RunTestIf(["instance-reinstall", qa_rapi.Enabled],
285 qa_rapi.TestRapiInstanceReinstall, instance)
287 if qa_config.TestEnabled("instance-rename"):
288 tgt_instance = qa_config.AcquireInstance()
290 rename_source = instance.name
291 rename_target = tgt_instance.name
292 # perform instance rename to the same name
293 RunTest(qa_instance.TestInstanceRenameAndBack,
294 rename_source, rename_source)
295 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
296 rename_source, rename_source)
297 if rename_target is not None:
298 # perform instance rename to a different name, if we have one configured
299 RunTest(qa_instance.TestInstanceRenameAndBack,
300 rename_source, rename_target)
301 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
302 rename_source, rename_target)
304 tgt_instance.Release()
306 RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
308 # and now start the instance again
309 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
311 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
313 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
315 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
317 RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)
319 # Lists instances, too
320 RunTestIf("node-list", qa_node.TestNodeList)
322 # Some jobs have been run, let's test listing them
323 RunTestIf("job-list", qa_job.TestJobList)
326 def RunCommonNodeTests():
327 """Run a few common node tests.
330 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
331 RunTestIf("node-storage", qa_node.TestNodeStorage)
332 RunTestIf(["node-oob", qa_config.NoVirtualCluster], qa_node.TestOutOfBand)
335 def RunGroupListTests():
336 """Run tests for listing node groups.
339 RunTestIf("group-list", qa_group.TestGroupList)
340 RunTestIf("group-list", qa_group.TestGroupListFields)
343 def RunNetworkTests():
344 """Run tests for network management.
347 RunTestIf("network", qa_network.TestNetworkAddRemove)
348 RunTestIf("network", qa_network.TestNetworkConnect)
351 def RunGroupRwTests():
352 """Run tests for adding/removing/renaming groups.
355 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
356 RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
357 RunTestIf("group-rwops", qa_group.TestGroupModify)
358 RunTestIf(["group-rwops", qa_rapi.Enabled], qa_rapi.TestRapiNodeGroups)
359 RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
360 qa_group.GetDefaultGroup())
363 def RunExportImportTests(instance, inodes):
364 """Tries to export and import the instance.
366 @type inodes: list of nodes
367 @param inodes: current nodes of the instance
370 # FIXME: export explicitly bails out on file based storage. other non-lvm
371 # based storage types are untested, though. Also note that import could still
372 # work, but is deeply embedded into the "export" case.
373 if (qa_config.TestEnabled("instance-export") and
374 instance.disk_template != constants.DT_FILE):
375 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
378 expnode = qa_config.AcquireNode(exclude=pnode)
380 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
382 RunTest(qa_instance.TestBackupList, expnode)
384 if qa_config.TestEnabled("instance-import"):
385 newinst = qa_config.AcquireInstance()
387 RunTest(qa_instance.TestInstanceImport, newinst, pnode,
389 # Check if starting the instance works
390 RunTest(qa_instance.TestInstanceStartup, newinst)
391 RunTest(qa_instance.TestInstanceRemove, newinst)
397 # FIXME: inter-cluster-instance-move crashes on file based instances :/
399 if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
400 and instance.disk_template != constants.DT_FILE):
401 newinst = qa_config.AcquireInstance()
403 tnode = qa_config.AcquireNode(exclude=inodes)
405 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
413 def RunDaemonTests(instance):
414 """Test the ganeti-watcher script.
417 RunTest(qa_daemon.TestPauseWatcher)
419 RunTestIf("instance-automatic-restart",
420 qa_daemon.TestInstanceAutomaticRestart, instance)
421 RunTestIf("instance-consecutive-failures",
422 qa_daemon.TestInstanceConsecutiveFailures, instance)
424 RunTest(qa_daemon.TestResumeWatcher)
427 def RunHardwareFailureTests(instance, inodes):
428 """Test cluster internal hardware failure recovery.
431 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
432 RunTestIf(["instance-failover", qa_rapi.Enabled],
433 qa_rapi.TestRapiInstanceFailover, instance)
435 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
436 RunTestIf(["instance-migrate", qa_rapi.Enabled],
437 qa_rapi.TestRapiInstanceMigrate, instance)
439 if qa_config.TestEnabled("instance-replace-disks"):
440 # We just need alternative secondary nodes, hence "- 1"
441 othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
443 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
444 RunTest(qa_instance.TestReplaceDisks,
445 instance, inodes, othernodes)
447 qa_config.ReleaseManyNodes(othernodes)
450 if qa_config.TestEnabled("instance-recreate-disks"):
452 acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
453 othernodes = acquirednodes
454 except qa_error.OutOfNodesError:
456 # If the cluster is not big enough, let's reuse some of the nodes, but
457 # with different roles. In this way, we can test a DRBD instance even on
459 acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
460 othernodes = acquirednodes + inodes[:-1]
464 RunTest(qa_instance.TestRecreateDisks,
465 instance, inodes, othernodes)
467 qa_config.ReleaseManyNodes(acquirednodes)
470 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
471 RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
474 def RunExclusiveStorageTests():
475 """Test exclusive storage."""
476 if not qa_config.TestEnabled("cluster-exclusive-storage"):
479 node = qa_config.AcquireNode()
481 old_es = qa_cluster.TestSetExclStorCluster(False)
482 qa_node.TestExclStorSingleNode(node)
484 qa_cluster.TestSetExclStorCluster(True)
485 qa_cluster.TestExclStorSharedPv(node)
487 if qa_config.TestEnabled("instance-add-plain-disk"):
488 # Make sure that the cluster doesn't have any pre-existing problem
489 qa_cluster.AssertClusterVerify()
491 # Create and allocate instances
492 instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
494 instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
496 # cluster-verify checks that disks are allocated correctly
497 qa_cluster.AssertClusterVerify()
500 qa_instance.TestInstanceRemove(instance2)
501 qa_instance.TestInstanceRemove(instance1)
507 if qa_config.TestEnabled("instance-add-drbd-disk"):
508 snode = qa_config.AcquireNode()
510 qa_cluster.TestSetExclStorCluster(False)
511 instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
513 qa_cluster.TestSetExclStorCluster(True)
514 exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
515 qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
516 qa_instance.TestInstanceRemove(instance)
521 qa_cluster.TestSetExclStorCluster(old_es)
526 def _BuildSpecDict(par, mn, st, mx):
528 constants.ISPECS_MINMAX: [{
529 constants.ISPECS_MIN: {par: mn},
530 constants.ISPECS_MAX: {par: mx},
532 constants.ISPECS_STD: {par: st},
536 def _BuildDoubleSpecDict(index, par, mn, st, mx):
538 constants.ISPECS_MINMAX: [{}, {}],
541 new_spec[constants.ISPECS_STD] = {par: st}
542 new_spec[constants.ISPECS_MINMAX][index] = {
543 constants.ISPECS_MIN: {par: mn},
544 constants.ISPECS_MAX: {par: mx},
549 def TestIPolicyPlainInstance():
550 """Test instance policy interaction with instances"""
551 params = ["memory-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
552 if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
553 print "Template %s not supported" % constants.DT_PLAIN
556 # This test assumes that the group policy is empty
557 (_, old_specs) = qa_cluster.TestClusterSetISpecs()
558 # We also assume to have only one min/max bound
559 assert len(old_specs[constants.ISPECS_MINMAX]) == 1
560 node = qa_config.AcquireNode()
562 # Log of policy changes, list of tuples:
563 # (full_change, incremental_change, policy_violated)
565 instance = qa_instance.TestInstanceAddWithPlainDisk([node])
567 policyerror = [constants.CV_EINSTANCEPOLICY]
569 (iminval, imaxval) = qa_instance.GetInstanceSpec(instance.name, par)
570 # Some specs must be multiple of 4
571 new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
572 history.append((None, new_spec, True))
574 # Some specs must be multiple of 4
579 new_spec = _BuildSpecDict(par, 0, upper, upper)
580 history.append((None, new_spec, True))
581 history.append((old_specs, None, False))
583 # Test with two instance specs
584 double_specs = copy.deepcopy(old_specs)
585 double_specs[constants.ISPECS_MINMAX] = \
586 double_specs[constants.ISPECS_MINMAX] * 2
587 (par1, par2) = params[0:2]
588 (_, imaxval1) = qa_instance.GetInstanceSpec(instance.name, par1)
589 (_, imaxval2) = qa_instance.GetInstanceSpec(instance.name, par2)
590 old_minmax = old_specs[constants.ISPECS_MINMAX][0]
592 (double_specs, None, False),
593 # The first min/max limit is being violated
595 _BuildDoubleSpecDict(0, par1, imaxval1 + 4, imaxval1 + 4,
598 # Both min/max limits are being violated
600 _BuildDoubleSpecDict(1, par2, imaxval2 + 4, None, imaxval2 + 4),
602 # The second min/max limit is being violated
604 _BuildDoubleSpecDict(0, par1,
605 old_minmax[constants.ISPECS_MIN][par1],
606 old_specs[constants.ISPECS_STD][par1],
607 old_minmax[constants.ISPECS_MAX][par1]),
609 (old_specs, None, False),
612 # Apply the changes, and check policy violations after each change
613 qa_cluster.AssertClusterVerify()
614 for (new_specs, diff_specs, failed) in history:
615 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
616 diff_specs=diff_specs)
618 qa_cluster.AssertClusterVerify(warnings=policyerror)
620 qa_cluster.AssertClusterVerify()
622 qa_instance.TestInstanceRemove(instance)
626 # Now we replay the same policy changes, and we expect that the instance
627 # cannot be created for the cases where we had a policy violation above
628 for (new_specs, diff_specs, failed) in history:
629 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
630 diff_specs=diff_specs)
632 qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
633 # Instance creation with no policy violation has been tested already
638 def IsExclusiveStorageInstanceTestEnabled():
639 test_name = "exclusive-storage-instance-tests"
640 if qa_config.TestEnabled(test_name):
641 vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
642 vgscmd = utils.ShellQuoteArgs([
643 "vgs", "--noheadings", "-o", "pv_count", vgname,
645 nodes = qa_config.GetConfig()["nodes"]
648 pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
650 msg = ("Cannot get the number of PVs on %s, needed by '%s': %s" %
651 (node.primary, test_name, e))
652 raise qa_error.Error(msg)
654 raise qa_error.Error("Node %s has not enough PVs (%s) to run '%s'" %
655 (node.primary, pvnum, test_name))
662 def RunInstanceTests():
663 """Create and exercise instances."""
665 ("instance-add-plain-disk", constants.DT_PLAIN,
666 qa_instance.TestInstanceAddWithPlainDisk, 1),
667 ("instance-add-drbd-disk", constants.DT_DRBD8,
668 qa_instance.TestInstanceAddWithDrbdDisk, 2),
669 ("instance-add-diskless", constants.DT_DISKLESS,
670 qa_instance.TestInstanceAddDiskless, 1),
671 ("instance-add-file", constants.DT_FILE,
672 qa_instance.TestInstanceAddFile, 1)
675 for (test_name, templ, create_fun, num_nodes) in instance_tests:
676 if (qa_config.TestEnabled(test_name) and
677 qa_config.IsTemplateSupported(templ)):
678 inodes = qa_config.AcquireManyNodes(num_nodes)
680 instance = RunTest(create_fun, inodes)
682 RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
683 RunDaemonTests(instance)
685 RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
687 RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
688 constants.INITIAL_NODE_GROUP_NAME,
689 inodes[0].primary, inodes[1].primary)
690 if qa_config.TestEnabled("instance-convert-disk"):
691 RunTest(qa_instance.TestInstanceShutdown, instance)
692 RunTest(qa_instance.TestInstanceConvertDiskToPlain,
694 RunTest(qa_instance.TestInstanceStartup, instance)
695 RunCommonInstanceTests(instance)
696 if qa_config.TestEnabled("instance-modify-primary"):
697 othernode = qa_config.AcquireNode()
698 RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
699 instance, inodes[0], othernode)
702 RunExportImportTests(instance, inodes)
703 RunHardwareFailureTests(instance, inodes)
705 RunTest(qa_instance.TestInstanceRemove, instance)
710 qa_config.ReleaseManyNodes(inodes)
711 qa_cluster.AssertClusterVerify()
718 rapi_user = "ganeti-qa"
719 rapi_secret = utils.GenerateSecret()
722 SetupCluster(rapi_user, rapi_secret)
724 if qa_rapi.Enabled():
725 # Load RAPI certificate
726 qa_rapi.Setup(rapi_user, rapi_secret)
731 RunTestIf("tags", qa_tags.TestClusterTags)
738 # The master shouldn't be readded or put offline; "delay" needs a non-master
740 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
742 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
743 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
744 RunTestIf("delay", qa_cluster.TestDelay, pnode)
748 # Make sure the cluster is clean before running instance tests
749 qa_cluster.AssertClusterVerify()
751 pnode = qa_config.AcquireNode()
753 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
755 if qa_rapi.Enabled():
756 RunTest(qa_rapi.TestNode, pnode)
758 if qa_config.TestEnabled("instance-add-plain-disk"):
759 for use_client in [True, False]:
760 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
763 if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
764 RunCommonInstanceTests(rapi_instance)
765 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
767 rapi_instance.Release()
774 ("default-instance-tests", lambda: None, lambda _: None),
775 (IsExclusiveStorageInstanceTestEnabled,
776 lambda: qa_cluster.TestSetExclStorCluster(True),
777 qa_cluster.TestSetExclStorCluster),
779 for (conf_name, setup_conf_f, restore_conf_f) in config_list:
780 if qa_config.TestEnabled(conf_name):
781 oldconf = setup_conf_f()
783 restore_conf_f(oldconf)
785 pnode = qa_config.AcquireNode()
787 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
788 for shutdown in [False, True]:
789 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
791 expnode = qa_config.AcquireNode(exclude=pnode)
794 # Stop instance before exporting and removing it
795 RunTest(qa_instance.TestInstanceShutdown, instance)
796 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
797 RunTest(qa_instance.TestBackupList, expnode)
804 qa_cluster.AssertClusterVerify()
809 RunExclusiveStorageTests()
810 RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
811 TestIPolicyPlainInstance)
814 "instance-add-restricted-by-disktemplates",
815 qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
817 # Test removing instance with offline drbd secondary
818 if qa_config.TestEnabled(["instance-remove-drbd-offline",
819 "instance-add-drbd-disk"]):
820 # Make sure the master is not put offline
821 snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
823 pnode = qa_config.AcquireNode(exclude=snode)
825 instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
826 set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
827 set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
828 RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
829 set_offline, set_online)
834 qa_cluster.AssertClusterVerify()
836 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
838 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
846 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
847 parser.add_option("--yes-do-it", dest="yes_do_it",
849 help="Really execute the tests")
850 (opts, args) = parser.parse_args()
853 (config_file, ) = args
855 parser.error("Wrong number of arguments.")
857 if not opts.yes_do_it:
858 print ("Executing this script irreversibly destroys any Ganeti\n"
859 "configuration on all nodes involved. If you really want\n"
860 "to start testing, supply the --yes-do-it option.")
863 qa_config.Load(config_file)
865 primary = qa_config.GetMasterNode().primary
866 qa_utils.StartMultiplexer(primary)
867 print ("SSH command for primary node: %s" %
868 utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
869 print ("SSH command for other nodes: %s" %
870 utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
874 qa_utils.CloseMultiplexers()
876 if __name__ == "__main__":