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 not in [constants.DT_FILE,
412 constants.DT_SHARED_FILE]):
413 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
416 expnode = qa_config.AcquireNode(exclude=pnode)
418 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
420 RunTest(qa_instance.TestBackupList, expnode)
422 if qa_config.TestEnabled("instance-import"):
423 newinst = qa_config.AcquireInstance()
425 RunTest(qa_instance.TestInstanceImport, newinst, pnode,
427 # Check if starting the instance works
428 RunTest(qa_instance.TestInstanceStartup, newinst)
429 RunTest(qa_instance.TestInstanceRemove, newinst)
435 # FIXME: inter-cluster-instance-move crashes on file based instances :/
437 if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
438 and instance.disk_template != constants.DT_FILE):
439 newinst = qa_config.AcquireInstance()
441 tnode = qa_config.AcquireNode(exclude=inodes)
443 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
451 def RunDaemonTests(instance):
452 """Test the ganeti-watcher script.
455 RunTest(qa_daemon.TestPauseWatcher)
457 RunTestIf("instance-automatic-restart",
458 qa_daemon.TestInstanceAutomaticRestart, instance)
459 RunTestIf("instance-consecutive-failures",
460 qa_daemon.TestInstanceConsecutiveFailures, instance)
462 RunTest(qa_daemon.TestResumeWatcher)
465 def RunHardwareFailureTests(instance, inodes):
466 """Test cluster internal hardware failure recovery.
469 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
470 RunTestIf(["instance-failover", qa_rapi.Enabled],
471 qa_rapi.TestRapiInstanceFailover, instance)
473 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
474 RunTestIf(["instance-migrate", qa_rapi.Enabled],
475 qa_rapi.TestRapiInstanceMigrate, instance)
477 if qa_config.TestEnabled("instance-replace-disks"):
478 # We just need alternative secondary nodes, hence "- 1"
479 othernodes = qa_config.AcquireManyNodes(len(inodes) - 1, exclude=inodes)
481 RunTestIf(qa_rapi.Enabled, qa_rapi.TestRapiInstanceReplaceDisks, instance)
482 RunTest(qa_instance.TestReplaceDisks,
483 instance, inodes, othernodes)
485 qa_config.ReleaseManyNodes(othernodes)
488 if qa_config.TestEnabled("instance-recreate-disks"):
490 acquirednodes = qa_config.AcquireManyNodes(len(inodes), exclude=inodes)
491 othernodes = acquirednodes
492 except qa_error.OutOfNodesError:
494 # If the cluster is not big enough, let's reuse some of the nodes, but
495 # with different roles. In this way, we can test a DRBD instance even on
497 acquirednodes = [qa_config.AcquireNode(exclude=inodes)]
498 othernodes = acquirednodes + inodes[:-1]
502 RunTest(qa_instance.TestRecreateDisks,
503 instance, inodes, othernodes)
505 qa_config.ReleaseManyNodes(acquirednodes)
508 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, inodes[0], inodes[1])
509 RunTestIf("node-failover", qa_node.TestNodeFailover, inodes[0], inodes[1])
510 RunTestIf("node-migrate", qa_node.TestNodeMigrate, inodes[0], inodes[1])
513 def RunExclusiveStorageTests():
514 """Test exclusive storage."""
515 if not qa_config.TestEnabled("cluster-exclusive-storage"):
518 node = qa_config.AcquireNode()
520 old_es = qa_cluster.TestSetExclStorCluster(False)
521 qa_node.TestExclStorSingleNode(node)
523 qa_cluster.TestSetExclStorCluster(True)
524 qa_cluster.TestExclStorSharedPv(node)
526 if qa_config.TestEnabled("instance-add-plain-disk"):
527 # Make sure that the cluster doesn't have any pre-existing problem
528 qa_cluster.AssertClusterVerify()
530 # Create and allocate instances
531 instance1 = qa_instance.TestInstanceAddWithPlainDisk([node])
533 instance2 = qa_instance.TestInstanceAddWithPlainDisk([node])
535 # cluster-verify checks that disks are allocated correctly
536 qa_cluster.AssertClusterVerify()
539 qa_instance.TestInstanceRemove(instance2)
540 qa_instance.TestInstanceRemove(instance1)
546 if qa_config.TestEnabled("instance-add-drbd-disk"):
547 snode = qa_config.AcquireNode()
549 qa_cluster.TestSetExclStorCluster(False)
550 instance = qa_instance.TestInstanceAddWithDrbdDisk([node, snode])
552 qa_cluster.TestSetExclStorCluster(True)
553 exp_err = [constants.CV_EINSTANCEUNSUITABLENODE]
554 qa_cluster.AssertClusterVerify(fail=True, errors=exp_err)
555 qa_instance.TestInstanceRemove(instance)
560 qa_cluster.TestSetExclStorCluster(old_es)
565 def _BuildSpecDict(par, mn, st, mx):
567 constants.ISPECS_MINMAX: [{
568 constants.ISPECS_MIN: {par: mn},
569 constants.ISPECS_MAX: {par: mx},
571 constants.ISPECS_STD: {par: st},
575 def _BuildDoubleSpecDict(index, par, mn, st, mx):
577 constants.ISPECS_MINMAX: [{}, {}],
580 new_spec[constants.ISPECS_STD] = {par: st}
581 new_spec[constants.ISPECS_MINMAX][index] = {
582 constants.ISPECS_MIN: {par: mn},
583 constants.ISPECS_MAX: {par: mx},
588 def TestIPolicyPlainInstance():
589 """Test instance policy interaction with instances"""
590 params = ["memory-size", "cpu-count", "disk-count", "disk-size", "nic-count"]
591 if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
592 print "Template %s not supported" % constants.DT_PLAIN
595 # This test assumes that the group policy is empty
596 (_, old_specs) = qa_cluster.TestClusterSetISpecs()
597 # We also assume to have only one min/max bound
598 assert len(old_specs[constants.ISPECS_MINMAX]) == 1
599 node = qa_config.AcquireNode()
601 # Log of policy changes, list of tuples:
602 # (full_change, incremental_change, policy_violated)
604 instance = qa_instance.TestInstanceAddWithPlainDisk([node])
606 policyerror = [constants.CV_EINSTANCEPOLICY]
608 (iminval, imaxval) = qa_instance.GetInstanceSpec(instance.name, par)
609 # Some specs must be multiple of 4
610 new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
611 history.append((None, new_spec, True))
613 # Some specs must be multiple of 4
618 new_spec = _BuildSpecDict(par, 0, upper, upper)
619 history.append((None, new_spec, True))
620 history.append((old_specs, None, False))
622 # Test with two instance specs
623 double_specs = copy.deepcopy(old_specs)
624 double_specs[constants.ISPECS_MINMAX] = \
625 double_specs[constants.ISPECS_MINMAX] * 2
626 (par1, par2) = params[0:2]
627 (_, imaxval1) = qa_instance.GetInstanceSpec(instance.name, par1)
628 (_, imaxval2) = qa_instance.GetInstanceSpec(instance.name, par2)
629 old_minmax = old_specs[constants.ISPECS_MINMAX][0]
631 (double_specs, None, False),
632 # The first min/max limit is being violated
634 _BuildDoubleSpecDict(0, par1, imaxval1 + 4, imaxval1 + 4,
637 # Both min/max limits are being violated
639 _BuildDoubleSpecDict(1, par2, imaxval2 + 4, None, imaxval2 + 4),
641 # The second min/max limit is being violated
643 _BuildDoubleSpecDict(0, par1,
644 old_minmax[constants.ISPECS_MIN][par1],
645 old_specs[constants.ISPECS_STD][par1],
646 old_minmax[constants.ISPECS_MAX][par1]),
648 (old_specs, None, False),
651 # Apply the changes, and check policy violations after each change
652 qa_cluster.AssertClusterVerify()
653 for (new_specs, diff_specs, failed) in history:
654 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
655 diff_specs=diff_specs)
657 qa_cluster.AssertClusterVerify(warnings=policyerror)
659 qa_cluster.AssertClusterVerify()
661 qa_instance.TestInstanceRemove(instance)
665 # Now we replay the same policy changes, and we expect that the instance
666 # cannot be created for the cases where we had a policy violation above
667 for (new_specs, diff_specs, failed) in history:
668 qa_cluster.TestClusterSetISpecs(new_specs=new_specs,
669 diff_specs=diff_specs)
671 qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
672 # Instance creation with no policy violation has been tested already
677 def IsExclusiveStorageInstanceTestEnabled():
678 test_name = "exclusive-storage-instance-tests"
679 if qa_config.TestEnabled(test_name):
680 vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
681 vgscmd = utils.ShellQuoteArgs([
682 "vgs", "--noheadings", "-o", "pv_count", vgname,
684 nodes = qa_config.GetConfig()["nodes"]
687 pvnum = int(qa_utils.GetCommandOutput(node.primary, vgscmd))
689 msg = ("Cannot get the number of PVs on %s, needed by '%s': %s" %
690 (node.primary, test_name, e))
691 raise qa_error.Error(msg)
693 raise qa_error.Error("Node %s has not enough PVs (%s) to run '%s'" %
694 (node.primary, pvnum, test_name))
701 def RunInstanceTests():
702 """Create and exercise instances."""
704 ("instance-add-plain-disk", constants.DT_PLAIN,
705 qa_instance.TestInstanceAddWithPlainDisk, 1),
706 ("instance-add-drbd-disk", constants.DT_DRBD8,
707 qa_instance.TestInstanceAddWithDrbdDisk, 2),
708 ("instance-add-diskless", constants.DT_DISKLESS,
709 qa_instance.TestInstanceAddDiskless, 1),
710 ("instance-add-file", constants.DT_FILE,
711 qa_instance.TestInstanceAddFile, 1),
712 ("instance-add-shared-file", constants.DT_SHARED_FILE,
713 qa_instance.TestInstanceAddSharedFile, 1),
716 for (test_name, templ, create_fun, num_nodes) in instance_tests:
717 if (qa_config.TestEnabled(test_name) and
718 qa_config.IsTemplateSupported(templ)):
719 inodes = qa_config.AcquireManyNodes(num_nodes)
721 instance = RunTest(create_fun, inodes)
723 RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
724 RunDaemonTests(instance)
726 RunTestIf("haskell-confd", qa_node.TestNodeListDrbd, node)
728 RunTestIf("group-rwops", qa_group.TestAssignNodesIncludingSplit,
729 constants.INITIAL_NODE_GROUP_NAME,
730 inodes[0].primary, inodes[1].primary)
731 if qa_config.TestEnabled("instance-convert-disk"):
732 RunTest(qa_instance.TestInstanceShutdown, instance)
733 RunTest(qa_instance.TestInstanceConvertDiskToPlain,
735 RunTest(qa_instance.TestInstanceStartup, instance)
736 RunTestIf("instance-modify-disks",
737 qa_instance.TestInstanceModifyDisks, instance)
738 RunCommonInstanceTests(instance, inodes)
739 if qa_config.TestEnabled("instance-modify-primary"):
740 othernode = qa_config.AcquireNode()
741 RunTest(qa_instance.TestInstanceModifyPrimaryAndBack,
742 instance, inodes[0], othernode)
745 RunExportImportTests(instance, inodes)
746 RunHardwareFailureTests(instance, inodes)
748 RunTest(qa_instance.TestInstanceRemove, instance)
753 qa_config.ReleaseManyNodes(inodes)
754 qa_cluster.AssertClusterVerify()
757 def RunMonitoringTests():
758 if qa_config.TestEnabled("mon-collector"):
759 RunTest(qa_monitoring.TestInstStatusCollector)
766 rapi_user = "ganeti-qa"
769 rapi_secret = SetupCluster(rapi_user)
771 if qa_rapi.Enabled():
772 # Load RAPI certificate
773 qa_rapi.Setup(rapi_user, rapi_secret)
778 RunTestIf("tags", qa_tags.TestClusterTags)
785 # The master shouldn't be readded or put offline; "delay" needs a non-master
787 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
789 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
790 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
791 RunTestIf("delay", qa_cluster.TestDelay, pnode)
795 # Make sure the cluster is clean before running instance tests
796 qa_cluster.AssertClusterVerify()
798 pnode = qa_config.AcquireNode()
800 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
802 if qa_rapi.Enabled():
803 RunTest(qa_rapi.TestNode, pnode)
805 if qa_config.TestEnabled("instance-add-plain-disk"):
806 for use_client in [True, False]:
807 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
810 if qa_config.TestEnabled("instance-plain-rapi-common-tests"):
811 RunCommonInstanceTests(rapi_instance, [pnode])
812 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
814 rapi_instance.Release()
821 ("default-instance-tests", lambda: None, lambda _: None),
822 (IsExclusiveStorageInstanceTestEnabled,
823 lambda: qa_cluster.TestSetExclStorCluster(True),
824 qa_cluster.TestSetExclStorCluster),
826 for (conf_name, setup_conf_f, restore_conf_f) in config_list:
827 if qa_config.TestEnabled(conf_name):
828 oldconf = setup_conf_f()
830 restore_conf_f(oldconf)
832 pnode = qa_config.AcquireNode()
834 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
835 for shutdown in [False, True]:
836 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, [pnode])
838 expnode = qa_config.AcquireNode(exclude=pnode)
841 # Stop instance before exporting and removing it
842 RunTest(qa_instance.TestInstanceShutdown, instance)
843 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
844 RunTest(qa_instance.TestBackupList, expnode)
851 qa_cluster.AssertClusterVerify()
856 RunExclusiveStorageTests()
857 RunTestIf(["cluster-instance-policy", "instance-add-plain-disk"],
858 TestIPolicyPlainInstance)
861 "instance-add-restricted-by-disktemplates",
862 qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
864 # Test removing instance with offline drbd secondary
865 if qa_config.TestEnabled(["instance-remove-drbd-offline",
866 "instance-add-drbd-disk"]):
867 # Make sure the master is not put offline
868 snode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
870 pnode = qa_config.AcquireNode(exclude=snode)
872 instance = qa_instance.TestInstanceAddWithDrbdDisk([pnode, snode])
873 set_offline = lambda node: qa_node.MakeNodeOffline(node, "yes")
874 set_online = lambda node: qa_node.MakeNodeOffline(node, "no")
875 RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
876 set_offline, set_online)
881 qa_cluster.AssertClusterVerify()
885 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
887 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
895 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
896 parser.add_option("--yes-do-it", dest="yes_do_it",
898 help="Really execute the tests")
899 (opts, args) = parser.parse_args()
902 (config_file, ) = args
904 parser.error("Wrong number of arguments.")
906 if not opts.yes_do_it:
907 print ("Executing this script irreversibly destroys any Ganeti\n"
908 "configuration on all nodes involved. If you really want\n"
909 "to start testing, supply the --yes-do-it option.")
912 qa_config.Load(config_file)
914 primary = qa_config.GetMasterNode().primary
915 qa_utils.StartMultiplexer(primary)
916 print ("SSH command for primary node: %s" %
917 utils.ShellQuoteArgs(qa_utils.GetSSHCommand(primary, "")))
918 print ("SSH command for other nodes: %s" %
919 utils.ShellQuoteArgs(qa_utils.GetSSHCommand("NODE", "")))
923 qa_utils.CloseMultiplexers()
925 if __name__ == "__main__":