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
54 import ganeti.rapi.client # pylint: disable=W0611
55 from ganeti.rapi.client import UsesRapiClient
58 def _FormatHeader(line, end=72):
59 """Fill a line up to the end column.
62 line = "---- " + line + " "
63 line += "-" * (end - len(line))
68 def _DescriptionOf(fn):
69 """Computes the description of an item.
73 desc = fn.__doc__.splitlines()[0].strip()
77 return desc.rstrip(".")
80 def RunTest(fn, *args, **kwargs):
81 """Runs a test after printing a header.
85 tstart = datetime.datetime.now()
87 desc = _DescriptionOf(fn)
90 print _FormatHeader("%s start %s" % (tstart, desc))
93 retval = fn(*args, **kwargs)
96 tstop = datetime.datetime.now()
97 tdelta = tstop - tstart
98 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
101 def RunTestIf(testnames, fn, *args, **kwargs):
102 """Runs a test conditionally.
104 @param testnames: either a single test name in the configuration
105 file, or a list of testnames (which will be AND-ed together)
108 if qa_config.TestEnabled(testnames):
109 RunTest(fn, *args, **kwargs)
111 tstart = datetime.datetime.now()
112 desc = _DescriptionOf(fn)
113 # TODO: Formatting test names when non-string names are involved
114 print _FormatHeader("%s skipping %s, test(s) %s disabled" %
115 (tstart, desc, testnames))
119 """Run several environment tests.
122 RunTestIf("env", qa_env.TestSshConnection)
123 RunTestIf("env", qa_env.TestIcmpPing)
124 RunTestIf("env", qa_env.TestGanetiCommands)
127 def SetupCluster(rapi_user, rapi_secret):
128 """Initializes the cluster.
130 @param rapi_user: Login user for RAPI
131 @param rapi_secret: Login secret for RAPI
134 RunTestIf("create-cluster", qa_cluster.TestClusterInit,
135 rapi_user, rapi_secret)
136 if not qa_config.TestEnabled("create-cluster"):
137 # If the cluster is already in place, we assume that exclusive-storage is
138 # already set according to the configuration
139 qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
141 # Test on empty cluster
142 RunTestIf("node-list", qa_node.TestNodeList)
143 RunTestIf("instance-list", qa_instance.TestInstanceList)
144 RunTestIf("job-list", qa_job.TestJobList)
146 RunTestIf("create-cluster", qa_node.TestNodeAddAll)
147 if not qa_config.TestEnabled("create-cluster"):
148 # consider the nodes are already there
149 qa_node.MarkNodeAddedAll()
151 RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
153 # enable the watcher (unconditionally)
154 RunTest(qa_daemon.TestResumeWatcher)
156 RunTestIf("node-list", qa_node.TestNodeList)
158 # Test listing fields
159 RunTestIf("node-list", qa_node.TestNodeListFields)
160 RunTestIf("instance-list", qa_instance.TestInstanceListFields)
161 RunTestIf("job-list", qa_job.TestJobListFields)
162 RunTestIf("instance-export", qa_instance.TestBackupListFields)
164 RunTestIf("node-info", qa_node.TestNodeInfo)
167 def RunClusterTests():
168 """Runs tests related to gnt-cluster.
172 ("create-cluster", qa_cluster.TestClusterInitDisk),
173 ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
174 ("cluster-verify", qa_cluster.TestClusterVerify),
175 ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
176 # TODO: add more cluster modify tests
177 ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
178 ("cluster-modify", qa_cluster.TestClusterModifyIPolicy),
179 ("cluster-modify", qa_cluster.TestClusterModifyISpecs),
180 ("cluster-modify", qa_cluster.TestClusterModifyBe),
181 ("cluster-modify", qa_cluster.TestClusterModifyDisk),
182 ("cluster-modify", qa_cluster.TestClusterModifyDiskTemplates),
183 ("cluster-rename", qa_cluster.TestClusterRename),
184 ("cluster-info", qa_cluster.TestClusterVersion),
185 ("cluster-info", qa_cluster.TestClusterInfo),
186 ("cluster-info", qa_cluster.TestClusterGetmaster),
187 ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
188 (["cluster-copyfile", qa_config.NoVirtualCluster],
189 qa_cluster.TestClusterCopyfile),
190 ("cluster-command", qa_cluster.TestClusterCommand),
191 ("cluster-burnin", qa_cluster.TestClusterBurnin),
192 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
193 ("cluster-master-failover",
194 qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
195 (["cluster-oob", qa_config.NoVirtualCluster],
196 qa_cluster.TestClusterOob),
197 (qa_rapi.Enabled, qa_rapi.TestVersion),
198 (qa_rapi.Enabled, qa_rapi.TestEmptyCluster),
199 (qa_rapi.Enabled, qa_rapi.TestRapiQuery),
204 def RunRepairDiskSizes():
205 """Run the repair disk-sizes test.
208 RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
212 """Runs all tests related to gnt-os.
215 os_enabled = ["os", qa_config.NoVirtualCluster]
217 if qa_config.TestEnabled(qa_rapi.Enabled):
218 rapi_getos = qa_rapi.GetOperatingSystems
224 qa_os.TestOsDiagnose,
226 RunTestIf(os_enabled, fn)
231 qa_os.TestOsPartiallyValid,
233 RunTestIf(os_enabled, fn, rapi_getos)
236 qa_os.TestOsModifyValid,
237 qa_os.TestOsModifyInvalid,
238 qa_os.TestOsStatesNonExisting,
240 RunTestIf(os_enabled, fn)
243 def RunCommonInstanceTests(instance):
244 """Runs a few tests that are common to all disk types.
247 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
248 RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
249 qa_rapi.TestRapiStoppedInstanceConsole, instance)
250 RunTestIf(["instance-shutdown", "instance-modify"],
251 qa_instance.TestInstanceStoppedModify, instance)
252 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
254 # Test shutdown/start via RAPI
255 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
256 qa_rapi.TestRapiInstanceShutdown, instance)
257 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
258 qa_rapi.TestRapiInstanceStartup, instance)
260 RunTestIf("instance-list", qa_instance.TestInstanceList)
262 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
264 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
265 RunTestIf(["instance-modify", qa_rapi.Enabled],
266 qa_rapi.TestRapiInstanceModify, instance)
268 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
269 RunTestIf(["instance-console", qa_rapi.Enabled],
270 qa_rapi.TestRapiInstanceConsole, instance)
272 RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
274 DOWN_TESTS = qa_config.Either([
275 "instance-reinstall",
277 "instance-grow-disk",
280 # shutdown instance for any 'down' tests
281 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
283 # now run the 'down' state tests
284 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
285 RunTestIf(["instance-reinstall", qa_rapi.Enabled],
286 qa_rapi.TestRapiInstanceReinstall, instance)
288 if qa_config.TestEnabled("instance-rename"):
289 tgt_instance = qa_config.AcquireInstance()
291 rename_source = instance.name
292 rename_target = tgt_instance.name
293 # perform instance rename to the same name
294 RunTest(qa_instance.TestInstanceRenameAndBack,
295 rename_source, rename_source)
296 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
297 rename_source, rename_source)
298 if rename_target is not None:
299 # perform instance rename to a different name, if we have one configured
300 RunTest(qa_instance.TestInstanceRenameAndBack,
301 rename_source, rename_target)
302 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
303 rename_source, rename_target)
305 tgt_instance.Release()
307 RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
309 # and now start the instance again
310 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
312 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
314 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
316 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
318 RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)
320 # Lists instances, too
321 RunTestIf("node-list", qa_node.TestNodeList)
323 # Some jobs have been run, let's test listing them
324 RunTestIf("job-list", qa_job.TestJobList)
327 def RunCommonNodeTests():
328 """Run a few common node tests.
331 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
332 RunTestIf("node-storage", qa_node.TestNodeStorage)
333 RunTestIf(["node-oob", qa_config.NoVirtualCluster], qa_node.TestOutOfBand)
336 def RunGroupListTests():
337 """Run tests for listing node groups.
340 RunTestIf("group-list", qa_group.TestGroupList)
341 RunTestIf("group-list", qa_group.TestGroupListFields)
344 def RunNetworkTests():
345 """Run tests for network management.
348 RunTestIf("network", qa_network.TestNetworkAddRemove)
349 RunTestIf("network", qa_network.TestNetworkConnect)
352 def RunGroupRwTests():
353 """Run tests for adding/removing/renaming groups.
356 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
357 RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
358 RunTestIf("group-rwops", qa_group.TestGroupModify)
359 RunTestIf(["group-rwops", qa_rapi.Enabled], qa_rapi.TestRapiNodeGroups)
360 RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
361 qa_group.GetDefaultGroup())
364 def RunExportImportTests(instance, inodes):
365 """Tries to export and import the instance.
367 @type inodes: list of nodes
368 @param inodes: current nodes of the instance
371 # FIXME: export explicitly bails out on file based storage. other non-lvm
372 # based storage types are untested, though. Also note that import could still
373 # work, but is deeply embedded into the "export" case.
374 if (qa_config.TestEnabled("instance-export") and
375 instance.disk_template != constants.DT_FILE):
376 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
379 expnode = qa_config.AcquireNode(exclude=pnode)
381 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
383 RunTest(qa_instance.TestBackupList, expnode)
385 if qa_config.TestEnabled("instance-import"):
386 newinst = qa_config.AcquireInstance()
388 RunTest(qa_instance.TestInstanceImport, newinst, pnode,
390 # Check if starting the instance works
391 RunTest(qa_instance.TestInstanceStartup, newinst)
392 RunTest(qa_instance.TestInstanceRemove, newinst)
398 # FIXME: inter-cluster-instance-move crashes on file based instances :/
400 if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
401 and instance.disk_template != constants.DT_FILE):
402 newinst = qa_config.AcquireInstance()
404 tnode = qa_config.AcquireNode(exclude=inodes)
406 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
414 def RunDaemonTests(instance):
415 """Test the ganeti-watcher script.
418 RunTest(qa_daemon.TestPauseWatcher)
420 RunTestIf("instance-automatic-restart",
421 qa_daemon.TestInstanceAutomaticRestart, instance)
422 RunTestIf("instance-consecutive-failures",
423 qa_daemon.TestInstanceConsecutiveFailures, instance)
425 RunTest(qa_daemon.TestResumeWatcher)
428 def RunHardwareFailureTests(instance, inodes):
429 """Test cluster internal hardware failure recovery.
432 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
433 RunTestIf(["instance-failover", qa_rapi.Enabled],
434 qa_rapi.TestRapiInstanceFailover, instance)
436 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
437 RunTestIf(["instance-migrate", qa_rapi.Enabled],
438 qa_rapi.TestRapiInstanceMigrate, instance)
440 if qa_config.TestEnabled("instance-replace-disks"):
441 # We just need alternative secondary nodes, hence "- 1"
442 othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
444 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
445 RunTest(qa_instance.TestReplaceDisks,
446 instance, inodes, othernodes)
448 qa_config.ReleaseManyNodes(othernodes)
451 if qa_config.TestEnabled("instance-recreate-disks"):
453 acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
454 othernodes = acquirednodes
455 except qa_error.OutOfNodesError:
457 # If the cluster is not big enough, let's reuse some of the nodes, but
458 # with different roles. In this way, we can test a DRBD instance even on
460 acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
461 othernodes = acquirednodes + inodes[:-1]
465 RunTest(qa_instance.TestRecreateDisks,
466 instance, inodes, othernodes)
468 qa_config.ReleaseManyNodes(acquirednodes)
471 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
472 RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
475 def RunExclusiveStorageTests():
476 """Test exclusive storage."""
477 if not qa_config.TestEnabled("cluster-exclusive-storage"):
480 node = qa_config.AcquireNode()
482 old_es = qa_cluster.TestSetExclStorCluster(False)
483 qa_node.TestExclStorSingleNode(node)
485 qa_cluster.TestSetExclStorCluster(True)
486 qa_cluster.TestExclStorSharedPv(node)
488 if qa_config.TestEnabled("instance-add-plain-disk"):
489 # Make sure that the cluster doesn't have any pre-existing problem
490 qa_cluster.AssertClusterVerify()
492 # Create and allocate instances
493 instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
495 instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
497 # cluster-verify checks that disks are allocated correctly
498 qa_cluster.AssertClusterVerify()
501 qa_instance.TestInstanceRemove(instance2)
502 qa_instance.TestInstanceRemove(instance1)
508 if qa_config.TestEnabled("instance-add-drbd-disk"):
509 snode = qa_config.AcquireNode()
511 qa_cluster.TestSetExclStorCluster(False)
512 instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
514 qa_cluster.TestSetExclStorCluster(True)
515 exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
516 qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
517 qa_instance.TestInstanceRemove(instance)
522 qa_cluster.TestSetExclStorCluster(old_es)
527 def _BuildSpecDict(par, mn, st, mx):
529 constants.ISPECS_MINMAX: [{
530 constants.ISPECS_MIN: {par: mn},
531 constants.ISPECS_MAX: {par: mx},
533 constants.ISPECS_STD: {par: st},
537 def _BuildDoubleSpecDict(index, par, mn, st, mx):
539 constants.ISPECS_MINMAX: [{}, {}],
542 new_spec[constants.ISPECS_STD] = {par: st}
543 new_spec[constants.ISPECS_MINMAX][index] = {
544 constants.ISPECS_MIN: {par: mn},
545 constants.ISPECS_MAX: {par: mx},
550 def TestIPolicyPlainInstance():
551 """Test instance policy interaction with instances"""
552 params = ["memory-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
553 if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
554 print "Template %s not supported" % constants.DT_PLAIN
557 # This test assumes that the group policy is empty
558 (_, old_specs) = qa_cluster.TestClusterSetISpecs()
559 # We also assume to have only one min/max bound
560 assert len(old_specs[constants.ISPECS_MINMAX]) == 1
561 node = qa_config.AcquireNode()
563 # Log of policy changes, list of tuples:
564 # (full_change, incremental_change, policy_violated)
566 instance = qa_instance.TestInstanceAddWithPlainDisk([node])
568 policyerror = [constants.CV_EINSTANCEPOLICY]
570 (iminval, imaxval) = qa_instance.GetInstanceSpec(instance.name, par)
571 # Some specs must be multiple of 4
572 new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
573 history.append((None, new_spec, True))
575 # Some specs must be multiple of 4
580 new_spec = _BuildSpecDict(par, 0, upper, upper)
581 history.append((None, new_spec, True))
582 history.append((old_specs, None, False))
584 # Test with two instance specs
585 double_specs = copy.deepcopy(old_specs)
586 double_specs[constants.ISPECS_MINMAX] = \
587 double_specs[constants.ISPECS_MINMAX] * 2
588 (par1, par2) = params[0:2]
589 (_, imaxval1) = qa_instance.GetInstanceSpec(instance.name, par1)
590 (_, imaxval2) = qa_instance.GetInstanceSpec(instance.name, par2)
591 old_minmax = old_specs[constants.ISPECS_MINMAX][0]
593 (double_specs, None, False),
594 # The first min/max limit is being violated
596 _BuildDoubleSpecDict(0, par1, imaxval1 + 4, imaxval1 + 4,
599 # Both min/max limits are being violated
601 _BuildDoubleSpecDict(1, par2, imaxval2 + 4, None, imaxval2 + 4),
603 # The second min/max limit is being violated
605 _BuildDoubleSpecDict(0, par1,
606 old_minmax[constants.ISPECS_MIN][par1],
607 old_specs[constants.ISPECS_STD][par1],
608 old_minmax[constants.ISPECS_MAX][par1]),
610 (old_specs, None, False),
613 # Apply the changes, and check policy violations after each change
614 qa_cluster.AssertClusterVerify()
615 for (new_specs, diff_specs, failed) in history:
616 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
617 diff_specs=diff_specs)
619 qa_cluster.AssertClusterVerify(warnings=policyerror)
621 qa_cluster.AssertClusterVerify()
623 qa_instance.TestInstanceRemove(instance)
627 # Now we replay the same policy changes, and we expect that the instance
628 # cannot be created for the cases where we had a policy violation above
629 for (new_specs, diff_specs, failed) in history:
630 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
631 diff_specs=diff_specs)
633 qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
634 # Instance creation with no policy violation has been tested already
639 def IsExclusiveStorageInstanceTestEnabled():
640 test_name = "exclusive-storage-instance-tests"
641 if qa_config.TestEnabled(test_name):
642 vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
643 vgscmd = utils.ShellQuoteArgs([
644 "vgs", "--noheadings", "-o", "pv_count", vgname,
646 nodes = qa_config.GetConfig()["nodes"]
649 pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
651 msg = ("Cannot get the number of PVs on %s, needed by '%s': %s" %
652 (node.primary, test_name, e))
653 raise qa_error.Error(msg)
655 raise qa_error.Error("Node %s has not enough PVs (%s) to run '%s'" %
656 (node.primary, pvnum, test_name))
663 def RunInstanceTests():
664 """Create and exercise instances."""
666 ("instance-add-plain-disk", constants.DT_PLAIN,
667 qa_instance.TestInstanceAddWithPlainDisk, 1),
668 ("instance-add-drbd-disk", constants.DT_DRBD8,
669 qa_instance.TestInstanceAddWithDrbdDisk, 2),
670 ("instance-add-diskless", constants.DT_DISKLESS,
671 qa_instance.TestInstanceAddDiskless, 1),
672 ("instance-add-file", constants.DT_FILE,
673 qa_instance.TestInstanceAddFile, 1)
676 for (test_name, templ, create_fun, num_nodes) in instance_tests:
677 if (qa_config.TestEnabled(test_name) and
678 qa_config.IsTemplateSupported(templ)):
679 inodes = qa_config.AcquireManyNodes(num_nodes)
681 instance = RunTest(create_fun, inodes)
683 RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
684 RunDaemonTests(instance)
686 RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
688 RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
689 constants.INITIAL_NODE_GROUP_NAME,
690 inodes[0].primary, inodes[1].primary)
691 if qa_config.TestEnabled("instance-convert-disk"):
692 RunTest(qa_instance.TestInstanceShutdown, instance)
693 RunTest(qa_instance.TestInstanceConvertDiskToPlain,
695 RunTest(qa_instance.TestInstanceStartup, instance)
696 RunTestIf("instance-modify-disks",
697 qa_instance.TestInstanceModifyDisks, instance)
698 RunCommonInstanceTests(instance)
699 if qa_config.TestEnabled("instance-modify-primary"):
700 othernode = qa_config.AcquireNode()
701 RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
702 instance, inodes[0], othernode)
705 RunExportImportTests(instance, inodes)
706 RunHardwareFailureTests(instance, inodes)
708 RunTest(qa_instance.TestInstanceRemove, instance)
713 qa_config.ReleaseManyNodes(inodes)
714 qa_cluster.AssertClusterVerify()
717 def RunMonitoringTests():
718 if qa_config.TestEnabled("mon-collector"):
719 RunTest(qa_monitoring.TestInstStatusCollector)
726 rapi_user = "ganeti-qa"
727 rapi_secret = utils.GenerateSecret()
730 SetupCluster(rapi_user, rapi_secret)
732 if qa_rapi.Enabled():
733 # Load RAPI certificate
734 qa_rapi.Setup(rapi_user, rapi_secret)
739 RunTestIf("tags", qa_tags.TestClusterTags)
746 # The master shouldn't be readded or put offline; "delay" needs a non-master
748 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
750 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
751 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
752 RunTestIf("delay", qa_cluster.TestDelay, pnode)
756 # Make sure the cluster is clean before running instance tests
757 qa_cluster.AssertClusterVerify()
759 pnode = qa_config.AcquireNode()
761 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
763 if qa_rapi.Enabled():
764 RunTest(qa_rapi.TestNode, pnode)
766 if qa_config.TestEnabled("instance-add-plain-disk"):
767 for use_client in [True, False]:
768 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
771 if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
772 RunCommonInstanceTests(rapi_instance)
773 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
775 rapi_instance.Release()
782 ("default-instance-tests", lambda: None, lambda _: None),
783 (IsExclusiveStorageInstanceTestEnabled,
784 lambda: qa_cluster.TestSetExclStorCluster(True),
785 qa_cluster.TestSetExclStorCluster),
787 for (conf_name, setup_conf_f, restore_conf_f) in config_list:
788 if qa_config.TestEnabled(conf_name):
789 oldconf = setup_conf_f()
791 restore_conf_f(oldconf)
793 pnode = qa_config.AcquireNode()
795 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
796 for shutdown in [False, True]:
797 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
799 expnode = qa_config.AcquireNode(exclude=pnode)
802 # Stop instance before exporting and removing it
803 RunTest(qa_instance.TestInstanceShutdown, instance)
804 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
805 RunTest(qa_instance.TestBackupList, expnode)
812 qa_cluster.AssertClusterVerify()
817 RunExclusiveStorageTests()
818 RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
819 TestIPolicyPlainInstance)
822 "instance-add-restricted-by-disktemplates",
823 qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
825 # Test removing instance with offline drbd secondary
826 if qa_config.TestEnabled(["instance-remove-drbd-offline",
827 "instance-add-drbd-disk"]):
828 # Make sure the master is not put offline
829 snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
831 pnode = qa_config.AcquireNode(exclude=snode)
833 instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
834 set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
835 set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
836 RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
837 set_offline, set_online)
842 qa_cluster.AssertClusterVerify()
846 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
848 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
856 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
857 parser.add_option("--yes-do-it", dest="yes_do_it",
859 help="Really execute the tests")
860 (opts, args) = parser.parse_args()
863 (config_file, ) = args
865 parser.error("Wrong number of arguments.")
867 if not opts.yes_do_it:
868 print ("Executing this script irreversibly destroys any Ganeti\n"
869 "configuration on all nodes involved. If you really want\n"
870 "to start testing, supply the --yes-do-it option.")
873 qa_config.Load(config_file)
875 primary = qa_config.GetMasterNode().primary
876 qa_utils.StartMultiplexer(primary)
877 print ("SSH command for primary node: %s" %
878 utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
879 print ("SSH command for other nodes: %s" %
880 utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
884 qa_utils.CloseMultiplexers()
886 if __name__ == "__main__":