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
52 from ganeti import pathutils
54 from ganeti.http.auth import ParsePasswordFile
55 import ganeti.rapi.client # pylint: disable=W0611
56 from ganeti.rapi.client import UsesRapiClient
59 def _FormatHeader(line, end=72):
60 """Fill a line up to the end column.
63 line = "---- " + line + " "
64 line += "-" * (end - len(line))
69 def _DescriptionOf(fn):
70 """Computes the description of an item.
74 desc = fn.__doc__.splitlines()[0].strip()
78 return desc.rstrip(".")
81 def RunTest(fn, *args, **kwargs):
82 """Runs a test after printing a header.
86 tstart = datetime.datetime.now()
88 desc = _DescriptionOf(fn)
91 print _FormatHeader("%s start %s" % (tstart, desc))
94 retval = fn(*args, **kwargs)
97 tstop = datetime.datetime.now()
98 tdelta = tstop - tstart
99 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
102 def RunTestIf(testnames, fn, *args, **kwargs):
103 """Runs a test conditionally.
105 @param testnames: either a single test name in the configuration
106 file, or a list of testnames (which will be AND-ed together)
109 if qa_config.TestEnabled(testnames):
110 RunTest(fn, *args, **kwargs)
112 tstart = datetime.datetime.now()
113 desc = _DescriptionOf(fn)
114 # TODO: Formatting test names when non-string names are involved
115 print _FormatHeader("%s skipping %s, test(s) %s disabled" %
116 (tstart, desc, testnames))
120 """Run several environment tests.
123 RunTestIf("env", qa_env.TestSshConnection)
124 RunTestIf("env", qa_env.TestIcmpPing)
125 RunTestIf("env", qa_env.TestGanetiCommands)
128 def _LookupRapiSecret(rapi_user):
129 """Find the RAPI secret for the given user.
131 @param rapi_user: Login user
132 @return: Login secret for the user
135 CTEXT = "{CLEARTEXT}"
136 master = qa_config.GetMasterNode()
137 cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)]
138 file_content = qa_utils.GetCommandOutput(master.primary,
139 utils.ShellQuoteArgs(cmd))
140 users = ParsePasswordFile(file_content)
141 entry = users.get(rapi_user)
143 raise qa_error.Error("User %s not found in RAPI users file" % rapi_user)
144 secret = entry.password
145 if secret.upper().startswith(CTEXT):
146 secret = secret[len(CTEXT):]
147 elif secret.startswith("{"):
148 raise qa_error.Error("Unsupported password schema for RAPI user %s:"
149 " not a clear text password" % rapi_user)
153 def SetupCluster(rapi_user):
154 """Initializes the cluster.
156 @param rapi_user: Login user for RAPI
157 @return: Login secret for RAPI
160 rapi_secret = utils.GenerateSecret()
161 RunTestIf("create-cluster", qa_cluster.TestClusterInit,
162 rapi_user, rapi_secret)
163 if not qa_config.TestEnabled("create-cluster"):
164 # If the cluster is already in place, we assume that exclusive-storage is
165 # already set according to the configuration
166 qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
167 if qa_rapi.Enabled():
168 # To support RAPI on an existing cluster we have to find out the secret
169 rapi_secret = _LookupRapiSecret(rapi_user)
171 # Test on empty cluster
172 RunTestIf("node-list", qa_node.TestNodeList)
173 RunTestIf("instance-list", qa_instance.TestInstanceList)
174 RunTestIf("job-list", qa_job.TestJobList)
176 RunTestIf("create-cluster", qa_node.TestNodeAddAll)
177 if not qa_config.TestEnabled("create-cluster"):
178 # consider the nodes are already there
179 qa_node.MarkNodeAddedAll()
181 RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
183 # enable the watcher (unconditionally)
184 RunTest(qa_daemon.TestResumeWatcher)
186 RunTestIf("node-list", qa_node.TestNodeList)
188 # Test listing fields
189 RunTestIf("node-list", qa_node.TestNodeListFields)
190 RunTestIf("instance-list", qa_instance.TestInstanceListFields)
191 RunTestIf("job-list", qa_job.TestJobListFields)
192 RunTestIf("instance-export", qa_instance.TestBackupListFields)
194 RunTestIf("node-info", qa_node.TestNodeInfo)
199 def RunClusterTests():
200 """Runs tests related to gnt-cluster.
204 ("create-cluster", qa_cluster.TestClusterInitDisk),
205 ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
206 ("cluster-verify", qa_cluster.TestClusterVerify),
207 ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
208 # TODO: add more cluster modify tests
209 ("cluster-modify", qa_cluster.TestClusterModifyEmpty),
210 ("cluster-modify", qa_cluster.TestClusterModifyIPolicy),
211 ("cluster-modify", qa_cluster.TestClusterModifyISpecs),
212 ("cluster-modify", qa_cluster.TestClusterModifyBe),
213 ("cluster-modify", qa_cluster.TestClusterModifyDisk),
214 ("cluster-modify", qa_cluster.TestClusterModifyDiskTemplates),
215 ("cluster-rename", qa_cluster.TestClusterRename),
216 ("cluster-info", qa_cluster.TestClusterVersion),
217 ("cluster-info", qa_cluster.TestClusterInfo),
218 ("cluster-info", qa_cluster.TestClusterGetmaster),
219 ("cluster-redist-conf", qa_cluster.TestClusterRedistConf),
220 (["cluster-copyfile", qa_config.NoVirtualCluster],
221 qa_cluster.TestClusterCopyfile),
222 ("cluster-command", qa_cluster.TestClusterCommand),
223 ("cluster-burnin", qa_cluster.TestClusterBurnin),
224 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
225 ("cluster-master-failover",
226 qa_cluster.TestClusterMasterFailoverWithDrainedQueue),
227 (["cluster-oob", qa_config.NoVirtualCluster],
228 qa_cluster.TestClusterOob),
229 (qa_rapi.Enabled, qa_rapi.TestVersion),
230 (qa_rapi.Enabled, qa_rapi.TestEmptyCluster),
231 (qa_rapi.Enabled, qa_rapi.TestRapiQuery),
236 def RunRepairDiskSizes():
237 """Run the repair disk-sizes test.
240 RunTestIf("cluster-repair-disk-sizes", qa_cluster.TestClusterRepairDiskSizes)
244 """Runs all tests related to gnt-os.
247 os_enabled = ["os", qa_config.NoVirtualCluster]
249 if qa_config.TestEnabled(qa_rapi.Enabled):
250 rapi_getos = qa_rapi.GetOperatingSystems
256 qa_os.TestOsDiagnose,
258 RunTestIf(os_enabled, fn)
263 qa_os.TestOsPartiallyValid,
265 RunTestIf(os_enabled, fn, rapi_getos)
268 qa_os.TestOsModifyValid,
269 qa_os.TestOsModifyInvalid,
270 qa_os.TestOsStatesNonExisting,
272 RunTestIf(os_enabled, fn)
275 def RunCommonInstanceTests(instance):
276 """Runs a few tests that are common to all disk types.
279 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
280 RunTestIf(["instance-shutdown", "instance-console", qa_rapi.Enabled],
281 qa_rapi.TestRapiStoppedInstanceConsole, instance)
282 RunTestIf(["instance-shutdown", "instance-modify"],
283 qa_instance.TestInstanceStoppedModify, instance)
284 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
286 # Test shutdown/start via RAPI
287 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
288 qa_rapi.TestRapiInstanceShutdown, instance)
289 RunTestIf(["instance-shutdown", qa_rapi.Enabled],
290 qa_rapi.TestRapiInstanceStartup, instance)
292 RunTestIf("instance-list", qa_instance.TestInstanceList)
294 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
296 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
297 RunTestIf(["instance-modify", qa_rapi.Enabled],
298 qa_rapi.TestRapiInstanceModify, instance)
300 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
301 RunTestIf(["instance-console", qa_rapi.Enabled],
302 qa_rapi.TestRapiInstanceConsole, instance)
304 RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
306 DOWN_TESTS = qa_config.Either([
307 "instance-reinstall",
309 "instance-grow-disk",
312 # shutdown instance for any 'down' tests
313 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceShutdown, instance)
315 # now run the 'down' state tests
316 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
317 RunTestIf(["instance-reinstall", qa_rapi.Enabled],
318 qa_rapi.TestRapiInstanceReinstall, instance)
320 if qa_config.TestEnabled("instance-rename"):
321 tgt_instance = qa_config.AcquireInstance()
323 rename_source = instance.name
324 rename_target = tgt_instance.name
325 # perform instance rename to the same name
326 RunTest(qa_instance.TestInstanceRenameAndBack,
327 rename_source, rename_source)
328 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
329 rename_source, rename_source)
330 if rename_target is not None:
331 # perform instance rename to a different name, if we have one configured
332 RunTest(qa_instance.TestInstanceRenameAndBack,
333 rename_source, rename_target)
334 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceRenameAndBack,
335 rename_source, rename_target)
337 tgt_instance.Release()
339 RunTestIf(["instance-grow-disk"], qa_instance.TestInstanceGrowDisk, instance)
341 # and now start the instance again
342 RunTestIf(DOWN_TESTS, qa_instance.TestInstanceStartup, instance)
344 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
346 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
348 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
350 RunTestIf(qa_rapi.Enabled, qa_rapi.TestInstance, instance)
352 # Lists instances, too
353 RunTestIf("node-list", qa_node.TestNodeList)
355 # Some jobs have been run, let's test listing them
356 RunTestIf("job-list", qa_job.TestJobList)
359 def RunCommonNodeTests():
360 """Run a few common node tests.
363 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
364 RunTestIf("node-storage", qa_node.TestNodeStorage)
365 RunTestIf(["node-oob", qa_config.NoVirtualCluster], qa_node.TestOutOfBand)
368 def RunGroupListTests():
369 """Run tests for listing node groups.
372 RunTestIf("group-list", qa_group.TestGroupList)
373 RunTestIf("group-list", qa_group.TestGroupListFields)
376 def RunNetworkTests():
377 """Run tests for network management.
380 RunTestIf("network", qa_network.TestNetworkAddRemove)
381 RunTestIf("network", qa_network.TestNetworkConnect)
384 def RunGroupRwTests():
385 """Run tests for adding/removing/renaming groups.
388 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
389 RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
390 RunTestIf("group-rwops", qa_group.TestGroupModify)
391 RunTestIf(["group-rwops", qa_rapi.Enabled], qa_rapi.TestRapiNodeGroups)
392 RunTestIf(["group-rwops", "tags"], qa_tags.TestGroupTags,
393 qa_group.GetDefaultGroup())
396 def RunExportImportTests(instance, inodes):
397 """Tries to export and import the instance.
399 @type inodes: list of nodes
400 @param inodes: current nodes of the instance
403 # FIXME: export explicitly bails out on file based storage. other non-lvm
404 # based storage types are untested, though. Also note that import could still
405 # work, but is deeply embedded into the "export" case.
406 if (qa_config.TestEnabled("instance-export") and
407 instance.disk_template != constants.DT_FILE):
408 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
411 expnode = qa_config.AcquireNode(exclude=pnode)
413 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
415 RunTest(qa_instance.TestBackupList, expnode)
417 if qa_config.TestEnabled("instance-import"):
418 newinst = qa_config.AcquireInstance()
420 RunTest(qa_instance.TestInstanceImport, newinst, pnode,
422 # Check if starting the instance works
423 RunTest(qa_instance.TestInstanceStartup, newinst)
424 RunTest(qa_instance.TestInstanceRemove, newinst)
430 # FIXME: inter-cluster-instance-move crashes on file based instances :/
432 if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
433 and instance.disk_template != constants.DT_FILE):
434 newinst = qa_config.AcquireInstance()
436 tnode = qa_config.AcquireNode(exclude=inodes)
438 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
446 def RunDaemonTests(instance):
447 """Test the ganeti-watcher script.
450 RunTest(qa_daemon.TestPauseWatcher)
452 RunTestIf("instance-automatic-restart",
453 qa_daemon.TestInstanceAutomaticRestart, instance)
454 RunTestIf("instance-consecutive-failures",
455 qa_daemon.TestInstanceConsecutiveFailures, instance)
457 RunTest(qa_daemon.TestResumeWatcher)
460 def RunHardwareFailureTests(instance, inodes):
461 """Test cluster internal hardware failure recovery.
464 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
465 RunTestIf(["instance-failover", qa_rapi.Enabled],
466 qa_rapi.TestRapiInstanceFailover, instance)
468 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
469 RunTestIf(["instance-migrate", qa_rapi.Enabled],
470 qa_rapi.TestRapiInstanceMigrate, instance)
472 if qa_config.TestEnabled("instance-replace-disks"):
473 # We just need alternative secondary nodes, hence "- 1"
474 othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
476 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
477 RunTest(qa_instance.TestReplaceDisks,
478 instance, inodes, othernodes)
480 qa_config.ReleaseManyNodes(othernodes)
483 if qa_config.TestEnabled("instance-recreate-disks"):
485 acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
486 othernodes = acquirednodes
487 except qa_error.OutOfNodesError:
489 # If the cluster is not big enough, let's reuse some of the nodes, but
490 # with different roles. In this way, we can test a DRBD instance even on
492 acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
493 othernodes = acquirednodes + inodes[:-1]
497 RunTest(qa_instance.TestRecreateDisks,
498 instance, inodes, othernodes)
500 qa_config.ReleaseManyNodes(acquirednodes)
503 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
504 RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
507 def RunExclusiveStorageTests():
508 """Test exclusive storage."""
509 if not qa_config.TestEnabled("cluster-exclusive-storage"):
512 node = qa_config.AcquireNode()
514 old_es = qa_cluster.TestSetExclStorCluster(False)
515 qa_node.TestExclStorSingleNode(node)
517 qa_cluster.TestSetExclStorCluster(True)
518 qa_cluster.TestExclStorSharedPv(node)
520 if qa_config.TestEnabled("instance-add-plain-disk"):
521 # Make sure that the cluster doesn't have any pre-existing problem
522 qa_cluster.AssertClusterVerify()
524 # Create and allocate instances
525 instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
527 instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
529 # cluster-verify checks that disks are allocated correctly
530 qa_cluster.AssertClusterVerify()
533 qa_instance.TestInstanceRemove(instance2)
534 qa_instance.TestInstanceRemove(instance1)
540 if qa_config.TestEnabled("instance-add-drbd-disk"):
541 snode = qa_config.AcquireNode()
543 qa_cluster.TestSetExclStorCluster(False)
544 instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
546 qa_cluster.TestSetExclStorCluster(True)
547 exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
548 qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
549 qa_instance.TestInstanceRemove(instance)
554 qa_cluster.TestSetExclStorCluster(old_es)
559 def _BuildSpecDict(par, mn, st, mx):
561 constants.ISPECS_MINMAX: [{
562 constants.ISPECS_MIN: {par: mn},
563 constants.ISPECS_MAX: {par: mx},
565 constants.ISPECS_STD: {par: st},
569 def _BuildDoubleSpecDict(index, par, mn, st, mx):
571 constants.ISPECS_MINMAX: [{}, {}],
574 new_spec[constants.ISPECS_STD] = {par: st}
575 new_spec[constants.ISPECS_MINMAX][index] = {
576 constants.ISPECS_MIN: {par: mn},
577 constants.ISPECS_MAX: {par: mx},
582 def TestIPolicyPlainInstance():
583 """Test instance policy interaction with instances"""
584 params = ["memory-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
585 if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
586 print "Template %s not supported" % constants.DT_PLAIN
589 # This test assumes that the group policy is empty
590 (_, old_specs) = qa_cluster.TestClusterSetISpecs()
591 # We also assume to have only one min/max bound
592 assert len(old_specs[constants.ISPECS_MINMAX]) == 1
593 node = qa_config.AcquireNode()
595 # Log of policy changes, list of tuples:
596 # (full_change, incremental_change, policy_violated)
598 instance = qa_instance.TestInstanceAddWithPlainDisk([node])
600 policyerror = [constants.CV_EINSTANCEPOLICY]
602 (iminval, imaxval) = qa_instance.GetInstanceSpec(instance.name, par)
603 # Some specs must be multiple of 4
604 new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
605 history.append((None, new_spec, True))
607 # Some specs must be multiple of 4
612 new_spec = _BuildSpecDict(par, 0, upper, upper)
613 history.append((None, new_spec, True))
614 history.append((old_specs, None, False))
616 # Test with two instance specs
617 double_specs = copy.deepcopy(old_specs)
618 double_specs[constants.ISPECS_MINMAX] = \
619 double_specs[constants.ISPECS_MINMAX] * 2
620 (par1, par2) = params[0:2]
621 (_, imaxval1) = qa_instance.GetInstanceSpec(instance.name, par1)
622 (_, imaxval2) = qa_instance.GetInstanceSpec(instance.name, par2)
623 old_minmax = old_specs[constants.ISPECS_MINMAX][0]
625 (double_specs, None, False),
626 # The first min/max limit is being violated
628 _BuildDoubleSpecDict(0, par1, imaxval1 + 4, imaxval1 + 4,
631 # Both min/max limits are being violated
633 _BuildDoubleSpecDict(1, par2, imaxval2 + 4, None, imaxval2 + 4),
635 # The second min/max limit is being violated
637 _BuildDoubleSpecDict(0, par1,
638 old_minmax[constants.ISPECS_MIN][par1],
639 old_specs[constants.ISPECS_STD][par1],
640 old_minmax[constants.ISPECS_MAX][par1]),
642 (old_specs, None, False),
645 # Apply the changes, and check policy violations after each change
646 qa_cluster.AssertClusterVerify()
647 for (new_specs, diff_specs, failed) in history:
648 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
649 diff_specs=diff_specs)
651 qa_cluster.AssertClusterVerify(warnings=policyerror)
653 qa_cluster.AssertClusterVerify()
655 qa_instance.TestInstanceRemove(instance)
659 # Now we replay the same policy changes, and we expect that the instance
660 # cannot be created for the cases where we had a policy violation above
661 for (new_specs, diff_specs, failed) in history:
662 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
663 diff_specs=diff_specs)
665 qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
666 # Instance creation with no policy violation has been tested already
671 def IsExclusiveStorageInstanceTestEnabled():
672 test_name = "exclusive-storage-instance-tests"
673 if qa_config.TestEnabled(test_name):
674 vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
675 vgscmd = utils.ShellQuoteArgs([
676 "vgs", "--noheadings", "-o", "pv_count", vgname,
678 nodes = qa_config.GetConfig()["nodes"]
681 pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
683 msg = ("Cannot get the number of PVs on %s, needed by '%s': %s" %
684 (node.primary, test_name, e))
685 raise qa_error.Error(msg)
687 raise qa_error.Error("Node %s has not enough PVs (%s) to run '%s'" %
688 (node.primary, pvnum, test_name))
695 def RunInstanceTests():
696 """Create and exercise instances."""
698 ("instance-add-plain-disk", constants.DT_PLAIN,
699 qa_instance.TestInstanceAddWithPlainDisk, 1),
700 ("instance-add-drbd-disk", constants.DT_DRBD8,
701 qa_instance.TestInstanceAddWithDrbdDisk, 2),
702 ("instance-add-diskless", constants.DT_DISKLESS,
703 qa_instance.TestInstanceAddDiskless, 1),
704 ("instance-add-file", constants.DT_FILE,
705 qa_instance.TestInstanceAddFile, 1)
708 for (test_name, templ, create_fun, num_nodes) in instance_tests:
709 if (qa_config.TestEnabled(test_name) and
710 qa_config.IsTemplateSupported(templ)):
711 inodes = qa_config.AcquireManyNodes(num_nodes)
713 instance = RunTest(create_fun, inodes)
715 RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
716 RunDaemonTests(instance)
718 RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
720 RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
721 constants.INITIAL_NODE_GROUP_NAME,
722 inodes[0].primary, inodes[1].primary)
723 if qa_config.TestEnabled("instance-convert-disk"):
724 RunTest(qa_instance.TestInstanceShutdown, instance)
725 RunTest(qa_instance.TestInstanceConvertDiskToPlain,
727 RunTest(qa_instance.TestInstanceStartup, instance)
728 RunTestIf("instance-modify-disks",
729 qa_instance.TestInstanceModifyDisks, instance)
730 RunCommonInstanceTests(instance)
731 if qa_config.TestEnabled("instance-modify-primary"):
732 othernode = qa_config.AcquireNode()
733 RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
734 instance, inodes[0], othernode)
737 RunExportImportTests(instance, inodes)
738 RunHardwareFailureTests(instance, inodes)
740 RunTest(qa_instance.TestInstanceRemove, instance)
745 qa_config.ReleaseManyNodes(inodes)
746 qa_cluster.AssertClusterVerify()
753 rapi_user = "ganeti-qa"
756 rapi_secret = SetupCluster(rapi_user)
758 if qa_rapi.Enabled():
759 # Load RAPI certificate
760 qa_rapi.Setup(rapi_user, rapi_secret)
765 RunTestIf("tags", qa_tags.TestClusterTags)
772 # The master shouldn't be readded or put offline; "delay" needs a non-master
774 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
776 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
777 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
778 RunTestIf("delay", qa_cluster.TestDelay, pnode)
782 # Make sure the cluster is clean before running instance tests
783 qa_cluster.AssertClusterVerify()
785 pnode = qa_config.AcquireNode()
787 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
789 if qa_rapi.Enabled():
790 RunTest(qa_rapi.TestNode, pnode)
792 if qa_config.TestEnabled("instance-add-plain-disk"):
793 for use_client in [True, False]:
794 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
797 if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
798 RunCommonInstanceTests(rapi_instance)
799 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
801 rapi_instance.Release()
808 ("default-instance-tests", lambda: None, lambda _: None),
809 (IsExclusiveStorageInstanceTestEnabled,
810 lambda: qa_cluster.TestSetExclStorCluster(True),
811 qa_cluster.TestSetExclStorCluster),
813 for (conf_name, setup_conf_f, restore_conf_f) in config_list:
814 if qa_config.TestEnabled(conf_name):
815 oldconf = setup_conf_f()
817 restore_conf_f(oldconf)
819 pnode = qa_config.AcquireNode()
821 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
822 for shutdown in [False, True]:
823 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
825 expnode = qa_config.AcquireNode(exclude=pnode)
828 # Stop instance before exporting and removing it
829 RunTest(qa_instance.TestInstanceShutdown, instance)
830 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
831 RunTest(qa_instance.TestBackupList, expnode)
838 qa_cluster.AssertClusterVerify()
843 RunExclusiveStorageTests()
844 RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
845 TestIPolicyPlainInstance)
848 "instance-add-restricted-by-disktemplates",
849 qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
851 # Test removing instance with offline drbd secondary
852 if qa_config.TestEnabled(["instance-remove-drbd-offline",
853 "instance-add-drbd-disk"]):
854 # Make sure the master is not put offline
855 snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
857 pnode = qa_config.AcquireNode(exclude=snode)
859 instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
860 set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
861 set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
862 RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
863 set_offline, set_online)
868 qa_cluster.AssertClusterVerify()
870 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
872 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
880 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
881 parser.add_option("--yes-do-it", dest="yes_do_it",
883 help="Really execute the tests")
884 (opts, args) = parser.parse_args()
887 (config_file, ) = args
889 parser.error("Wrong number of arguments.")
891 if not opts.yes_do_it:
892 print ("Executing this script irreversibly destroys any Ganeti\n"
893 "configuration on all nodes involved. If you really want\n"
894 "to start testing, supply the --yes-do-it option.")
897 qa_config.Load(config_file)
899 primary = qa_config.GetMasterNode().primary
900 qa_utils.StartMultiplexer(primary)
901 print ("SSH command for primary node: %s" %
902 utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
903 print ("SSH command for other nodes: %s" %
904 utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
908 qa_utils.CloseMultiplexers()
910 if __name__ == "__main__":