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-rename", qa_cluster.TestClusterRename),
217 ("cluster-info", qa_cluster.TestClusterVersion),
218 ("cluster-info", qa_cluster.TestClusterInfo),
219 ("cluster-info", qa_cluster.TestClusterGetmaster),
220 ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
221 (["cluster-copyfile", qa_config.NoVirtualCluster],
222 qa_cluster.TestClusterCopyfile),
223 ("cluster-command", qa_cluster.TestClusterCommand),
224 ("cluster-burnin", qa_cluster.TestClusterBurnin),
225 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
226 ("cluster-master-failover",
227 qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
228 (["cluster-oob", qa_config.NoVirtualCluster],
229 qa_cluster.TestClusterOob),
230 (qa_rapi.Enabled, qa_rapi.TestVersion),
231 (qa_rapi.Enabled, qa_rapi.TestEmptyCluster),
232 (qa_rapi.Enabled, qa_rapi.TestRapiQuery),
237 def RunRepairDiskSizes():
238 """Run the repair disk-sizes test.
241 RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
245 """Runs all tests related to gnt-os.
248 os_enabled = ["os", qa_config.NoVirtualCluster]
250 if qa_config.TestEnabled(qa_rapi.Enabled):
251 rapi_getos = qa_rapi.GetOperatingSystems
257 qa_os.TestOsDiagnose,
259 RunTestIf(os_enabled, fn)
264 qa_os.TestOsPartiallyValid,
266 RunTestIf(os_enabled, fn, rapi_getos)
269 qa_os.TestOsModifyValid,
270 qa_os.TestOsModifyInvalid,
271 qa_os.TestOsStatesNonExisting,
273 RunTestIf(os_enabled, fn)
276 def RunCommonInstanceTests(instance, inst_nodes):
277 """Runs a few tests that are common to all disk types.
280 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
281 RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
282 qa_rapi.TestRapiStoppedInstanceConsole, instance)
283 RunTestIf(["instance-shutdown", "instance-modify"],
284 qa_instance.TestInstanceStoppedModify, instance)
285 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
287 # Test shutdown/start via RAPI
288 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
289 qa_rapi.TestRapiInstanceShutdown, instance)
290 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
291 qa_rapi.TestRapiInstanceStartup, instance)
293 RunTestIf("instance-list", qa_instance.TestInstanceList)
295 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
297 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
298 RunTestIf(["instance-modify", qa_rapi.Enabled],
299 qa_rapi.TestRapiInstanceModify, instance)
301 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
302 RunTestIf(["instance-console", qa_rapi.Enabled],
303 qa_rapi.TestRapiInstanceConsole, instance)
305 RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
307 DOWN_TESTS = qa_config.Either([
308 "instance-reinstall",
310 "instance-grow-disk",
313 # shutdown instance for any 'down' tests
314 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
316 # now run the 'down' state tests
317 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
318 RunTestIf(["instance-reinstall", qa_rapi.Enabled],
319 qa_rapi.TestRapiInstanceReinstall, instance)
321 if qa_config.TestEnabled("instance-rename"):
322 tgt_instance = qa_config.AcquireInstance()
324 rename_source = instance.name
325 rename_target = tgt_instance.name
326 # perform instance rename to the same name
327 RunTest(qa_instance.TestInstanceRenameAndBack,
328 rename_source, rename_source)
329 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
330 rename_source, rename_source)
331 if rename_target is not None:
332 # perform instance rename to a different name, if we have one configured
333 RunTest(qa_instance.TestInstanceRenameAndBack,
334 rename_source, rename_target)
335 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
336 rename_source, rename_target)
338 tgt_instance.Release()
340 RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
342 # and now start the instance again
343 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
345 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
347 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
349 if instance.disk_template == constants.DT_DRBD8:
350 RunTestIf("cluster-verify",
351 qa_cluster.TestClusterVerifyDisksBrokenDRBD, instance, inst_nodes)
352 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
354 RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)
356 # Lists instances, too
357 RunTestIf("node-list", qa_node.TestNodeList)
359 # Some jobs have been run, let's test listing them
360 RunTestIf("job-list", qa_job.TestJobList)
363 def RunCommonNodeTests():
364 """Run a few common node tests.
367 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
368 RunTestIf("node-storage", qa_node.TestNodeStorage)
369 RunTestIf(["node-oob", qa_config.NoVirtualCluster], qa_node.TestOutOfBand)
372 def RunGroupListTests():
373 """Run tests for listing node groups.
376 RunTestIf("group-list", qa_group.TestGroupList)
377 RunTestIf("group-list", qa_group.TestGroupListFields)
380 def RunNetworkTests():
381 """Run tests for network management.
384 RunTestIf("network", qa_network.TestNetworkAddRemove)
385 RunTestIf("network", qa_network.TestNetworkConnect)
388 def RunGroupRwTests():
389 """Run tests for adding/removing/renaming groups.
392 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
393 RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
394 RunTestIf("group-rwops", qa_group.TestGroupModify)
395 RunTestIf(["group-rwops", qa_rapi.Enabled], qa_rapi.TestRapiNodeGroups)
396 RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
397 qa_group.GetDefaultGroup())
400 def RunExportImportTests(instance, inodes):
401 """Tries to export and import the instance.
403 @type inodes: list of nodes
404 @param inodes: current nodes of the instance
407 # FIXME: export explicitly bails out on file based storage. other non-lvm
408 # based storage types are untested, though. Also note that import could still
409 # work, but is deeply embedded into the "export" case.
410 if (qa_config.TestEnabled("instance-export") and
411 instance.disk_template != constants.DT_FILE):
412 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
415 expnode = qa_config.AcquireNode(exclude=pnode)
417 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
419 RunTest(qa_instance.TestBackupList, expnode)
421 if qa_config.TestEnabled("instance-import"):
422 newinst = qa_config.AcquireInstance()
424 RunTest(qa_instance.TestInstanceImport, newinst, pnode,
426 # Check if starting the instance works
427 RunTest(qa_instance.TestInstanceStartup, newinst)
428 RunTest(qa_instance.TestInstanceRemove, newinst)
434 # FIXME: inter-cluster-instance-move crashes on file based instances :/
436 if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
437 and instance.disk_template != constants.DT_FILE):
438 newinst = qa_config.AcquireInstance()
440 tnode = qa_config.AcquireNode(exclude=inodes)
442 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
450 def RunDaemonTests(instance):
451 """Test the ganeti-watcher script.
454 RunTest(qa_daemon.TestPauseWatcher)
456 RunTestIf("instance-automatic-restart",
457 qa_daemon.TestInstanceAutomaticRestart, instance)
458 RunTestIf("instance-consecutive-failures",
459 qa_daemon.TestInstanceConsecutiveFailures, instance)
461 RunTest(qa_daemon.TestResumeWatcher)
464 def RunHardwareFailureTests(instance, inodes):
465 """Test cluster internal hardware failure recovery.
468 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
469 RunTestIf(["instance-failover", qa_rapi.Enabled],
470 qa_rapi.TestRapiInstanceFailover, instance)
472 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
473 RunTestIf(["instance-migrate", qa_rapi.Enabled],
474 qa_rapi.TestRapiInstanceMigrate, instance)
476 if qa_config.TestEnabled("instance-replace-disks"):
477 # We just need alternative secondary nodes, hence "- 1"
478 othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
480 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
481 RunTest(qa_instance.TestReplaceDisks,
482 instance, inodes, othernodes)
484 qa_config.ReleaseManyNodes(othernodes)
487 if qa_config.TestEnabled("instance-recreate-disks"):
489 acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
490 othernodes = acquirednodes
491 except qa_error.OutOfNodesError:
493 # If the cluster is not big enough, let's reuse some of the nodes, but
494 # with different roles. In this way, we can test a DRBD instance even on
496 acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
497 othernodes = acquirednodes + inodes[:-1]
501 RunTest(qa_instance.TestRecreateDisks,
502 instance, inodes, othernodes)
504 qa_config.ReleaseManyNodes(acquirednodes)
507 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
508 RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
509 RunTestIf("node-migrate", qa_node.TestNodeMigrate, inodes[0], inodes[1])
512 def RunExclusiveStorageTests():
513 """Test exclusive storage."""
514 if not qa_config.TestEnabled("cluster-exclusive-storage"):
517 node = qa_config.AcquireNode()
519 old_es = qa_cluster.TestSetExclStorCluster(False)
520 qa_node.TestExclStorSingleNode(node)
522 qa_cluster.TestSetExclStorCluster(True)
523 qa_cluster.TestExclStorSharedPv(node)
525 if qa_config.TestEnabled("instance-add-plain-disk"):
526 # Make sure that the cluster doesn't have any pre-existing problem
527 qa_cluster.AssertClusterVerify()
529 # Create and allocate instances
530 instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
532 instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
534 # cluster-verify checks that disks are allocated correctly
535 qa_cluster.AssertClusterVerify()
538 qa_instance.TestInstanceRemove(instance2)
539 qa_instance.TestInstanceRemove(instance1)
545 if qa_config.TestEnabled("instance-add-drbd-disk"):
546 snode = qa_config.AcquireNode()
548 qa_cluster.TestSetExclStorCluster(False)
549 instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
551 qa_cluster.TestSetExclStorCluster(True)
552 exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
553 qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
554 qa_instance.TestInstanceRemove(instance)
559 qa_cluster.TestSetExclStorCluster(old_es)
564 def _BuildSpecDict(par, mn, st, mx):
566 constants.ISPECS_MINMAX: [{
567 constants.ISPECS_MIN: {par: mn},
568 constants.ISPECS_MAX: {par: mx},
570 constants.ISPECS_STD: {par: st},
574 def _BuildDoubleSpecDict(index, par, mn, st, mx):
576 constants.ISPECS_MINMAX: [{}, {}],
579 new_spec[constants.ISPECS_STD] = {par: st}
580 new_spec[constants.ISPECS_MINMAX][index] = {
581 constants.ISPECS_MIN: {par: mn},
582 constants.ISPECS_MAX: {par: mx},
587 def TestIPolicyPlainInstance():
588 """Test instance policy interaction with instances"""
589 params = ["memory-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
590 if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
591 print "Template %s not supported" % constants.DT_PLAIN
594 # This test assumes that the group policy is empty
595 (_, old_specs) = qa_cluster.TestClusterSetISpecs()
596 # We also assume to have only one min/max bound
597 assert len(old_specs[constants.ISPECS_MINMAX]) == 1
598 node = qa_config.AcquireNode()
600 # Log of policy changes, list of tuples:
601 # (full_change, incremental_change, policy_violated)
603 instance = qa_instance.TestInstanceAddWithPlainDisk([node])
605 policyerror = [constants.CV_EINSTANCEPOLICY]
607 (iminval, imaxval) = qa_instance.GetInstanceSpec(instance.name, par)
608 # Some specs must be multiple of 4
609 new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
610 history.append((None, new_spec, True))
612 # Some specs must be multiple of 4
617 new_spec = _BuildSpecDict(par, 0, upper, upper)
618 history.append((None, new_spec, True))
619 history.append((old_specs, None, False))
621 # Test with two instance specs
622 double_specs = copy.deepcopy(old_specs)
623 double_specs[constants.ISPECS_MINMAX] = \
624 double_specs[constants.ISPECS_MINMAX] * 2
625 (par1, par2) = params[0:2]
626 (_, imaxval1) = qa_instance.GetInstanceSpec(instance.name, par1)
627 (_, imaxval2) = qa_instance.GetInstanceSpec(instance.name, par2)
628 old_minmax = old_specs[constants.ISPECS_MINMAX][0]
630 (double_specs, None, False),
631 # The first min/max limit is being violated
633 _BuildDoubleSpecDict(0, par1, imaxval1 + 4, imaxval1 + 4,
636 # Both min/max limits are being violated
638 _BuildDoubleSpecDict(1, par2, imaxval2 + 4, None, imaxval2 + 4),
640 # The second min/max limit is being violated
642 _BuildDoubleSpecDict(0, par1,
643 old_minmax[constants.ISPECS_MIN][par1],
644 old_specs[constants.ISPECS_STD][par1],
645 old_minmax[constants.ISPECS_MAX][par1]),
647 (old_specs, None, False),
650 # Apply the changes, and check policy violations after each change
651 qa_cluster.AssertClusterVerify()
652 for (new_specs, diff_specs, failed) in history:
653 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
654 diff_specs=diff_specs)
656 qa_cluster.AssertClusterVerify(warnings=policyerror)
658 qa_cluster.AssertClusterVerify()
660 qa_instance.TestInstanceRemove(instance)
664 # Now we replay the same policy changes, and we expect that the instance
665 # cannot be created for the cases where we had a policy violation above
666 for (new_specs, diff_specs, failed) in history:
667 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
668 diff_specs=diff_specs)
670 qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
671 # Instance creation with no policy violation has been tested already
676 def IsExclusiveStorageInstanceTestEnabled():
677 test_name = "exclusive-storage-instance-tests"
678 if qa_config.TestEnabled(test_name):
679 vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
680 vgscmd = utils.ShellQuoteArgs([
681 "vgs", "--noheadings", "-o", "pv_count", vgname,
683 nodes = qa_config.GetConfig()["nodes"]
686 pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
688 msg = ("Cannot get the number of PVs on %s, needed by '%s': %s" %
689 (node.primary, test_name, e))
690 raise qa_error.Error(msg)
692 raise qa_error.Error("Node %s has not enough PVs (%s) to run '%s'" %
693 (node.primary, pvnum, test_name))
700 def RunInstanceTests():
701 """Create and exercise instances."""
703 ("instance-add-plain-disk", constants.DT_PLAIN,
704 qa_instance.TestInstanceAddWithPlainDisk, 1),
705 ("instance-add-drbd-disk", constants.DT_DRBD8,
706 qa_instance.TestInstanceAddWithDrbdDisk, 2),
707 ("instance-add-diskless", constants.DT_DISKLESS,
708 qa_instance.TestInstanceAddDiskless, 1),
709 ("instance-add-file", constants.DT_FILE,
710 qa_instance.TestInstanceAddFile, 1)
713 for (test_name, templ, create_fun, num_nodes) in instance_tests:
714 if (qa_config.TestEnabled(test_name) and
715 qa_config.IsTemplateSupported(templ)):
716 inodes = qa_config.AcquireManyNodes(num_nodes)
718 instance = RunTest(create_fun, inodes)
720 RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
721 RunDaemonTests(instance)
723 RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
725 RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
726 constants.INITIAL_NODE_GROUP_NAME,
727 inodes[0].primary, inodes[1].primary)
728 if qa_config.TestEnabled("instance-convert-disk"):
729 RunTest(qa_instance.TestInstanceShutdown, instance)
730 RunTest(qa_instance.TestInstanceConvertDiskToPlain,
732 RunTest(qa_instance.TestInstanceStartup, instance)
733 RunTestIf("instance-modify-disks",
734 qa_instance.TestInstanceModifyDisks, instance)
735 RunCommonInstanceTests(instance, inodes)
736 if qa_config.TestEnabled("instance-modify-primary"):
737 othernode = qa_config.AcquireNode()
738 RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
739 instance, inodes[0], othernode)
742 RunExportImportTests(instance, inodes)
743 RunHardwareFailureTests(instance, inodes)
745 RunTest(qa_instance.TestInstanceRemove, instance)
750 qa_config.ReleaseManyNodes(inodes)
751 qa_cluster.AssertClusterVerify()
754 def RunMonitoringTests():
755 if qa_config.TestEnabled("mon-collector"):
756 RunTest(qa_monitoring.TestInstStatusCollector)
763 rapi_user = "ganeti-qa"
766 rapi_secret = SetupCluster(rapi_user)
768 if qa_rapi.Enabled():
769 # Load RAPI certificate
770 qa_rapi.Setup(rapi_user, rapi_secret)
775 RunTestIf("tags", qa_tags.TestClusterTags)
782 # The master shouldn't be readded or put offline; "delay" needs a non-master
784 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
786 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
787 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
788 RunTestIf("delay", qa_cluster.TestDelay, pnode)
792 # Make sure the cluster is clean before running instance tests
793 qa_cluster.AssertClusterVerify()
795 pnode = qa_config.AcquireNode()
797 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
799 if qa_rapi.Enabled():
800 RunTest(qa_rapi.TestNode, pnode)
802 if qa_config.TestEnabled("instance-add-plain-disk"):
803 for use_client in [True, False]:
804 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
807 if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
808 RunCommonInstanceTests(rapi_instance, [pnode])
809 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
811 rapi_instance.Release()
818 ("default-instance-tests", lambda: None, lambda _: None),
819 (IsExclusiveStorageInstanceTestEnabled,
820 lambda: qa_cluster.TestSetExclStorCluster(True),
821 qa_cluster.TestSetExclStorCluster),
823 for (conf_name, setup_conf_f, restore_conf_f) in config_list:
824 if qa_config.TestEnabled(conf_name):
825 oldconf = setup_conf_f()
827 restore_conf_f(oldconf)
829 pnode = qa_config.AcquireNode()
831 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
832 for shutdown in [False, True]:
833 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
835 expnode = qa_config.AcquireNode(exclude=pnode)
838 # Stop instance before exporting and removing it
839 RunTest(qa_instance.TestInstanceShutdown, instance)
840 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
841 RunTest(qa_instance.TestBackupList, expnode)
848 qa_cluster.AssertClusterVerify()
853 RunExclusiveStorageTests()
854 RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
855 TestIPolicyPlainInstance)
858 "instance-add-restricted-by-disktemplates",
859 qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
861 # Test removing instance with offline drbd secondary
862 if qa_config.TestEnabled(["instance-remove-drbd-offline",
863 "instance-add-drbd-disk"]):
864 # Make sure the master is not put offline
865 snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
867 pnode = qa_config.AcquireNode(exclude=snode)
869 instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
870 set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
871 set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
872 RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
873 set_offline, set_online)
878 qa_cluster.AssertClusterVerify()
882 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
884 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
892 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
893 parser.add_option("--yes-do-it", dest="yes_do_it",
895 help="Really execute the tests")
896 (opts, args) = parser.parse_args()
899 (config_file, ) = args
901 parser.error("Wrong number of arguments.")
903 if not opts.yes_do_it:
904 print ("Executing this script irreversibly destroys any Ganeti\n"
905 "configuration on all nodes involved. If you really want\n"
906 "to start testing, supply the --yes-do-it option.")
909 qa_config.Load(config_file)
911 primary = qa_config.GetMasterNode().primary
912 qa_utils.StartMultiplexer(primary)
913 print ("SSH command for primary node: %s" %
914 utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
915 print ("SSH command for other nodes: %s" %
916 utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
920 qa_utils.CloseMultiplexers()
922 if __name__ == "__main__":