4 # Copyright (C) 2007, 2008, 2009, 2010, 2011 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-msg=C0103
45 from ganeti import utils
46 from ganeti import rapi
47 from ganeti import constants
49 import ganeti.rapi.client # pylint: disable-msg=W0611
52 def _FormatHeader(line, end=72):
53 """Fill a line up to the end column.
56 line = "---- " + line + " "
57 line += "-" * (end-len(line))
62 def _DescriptionOf(fn):
63 """Computes the description of an item.
67 desc = fn.__doc__.splitlines()[0].strip()
71 return desc.rstrip(".")
73 def RunTest(fn, *args):
74 """Runs a test after printing a header.
78 tstart = datetime.datetime.now()
80 desc = _DescriptionOf(fn)
83 print _FormatHeader("%s start %s" % (tstart, desc))
89 tstop = datetime.datetime.now()
90 tdelta = tstop - tstart
91 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
94 def RunTestIf(testnames, fn, *args):
95 """Runs a test conditionally.
97 @param testnames: either a single test name in the configuration
98 file, or a list of testnames (which will be AND-ed together)
101 if qa_config.TestEnabled(testnames):
104 tstart = datetime.datetime.now()
105 desc = _DescriptionOf(fn)
106 print _FormatHeader("%s skipping %s, test(s) %s disabled" %
107 (tstart, desc, testnames))
111 """Run several environment tests.
114 RunTestIf("env", qa_env.TestSshConnection)
115 RunTestIf("env", qa_env.TestIcmpPing)
116 RunTestIf("env", qa_env.TestGanetiCommands)
119 def SetupCluster(rapi_user, rapi_secret):
120 """Initializes the cluster.
122 @param rapi_user: Login user for RAPI
123 @param rapi_secret: Login secret for RAPI
126 RunTestIf("create-cluster", qa_cluster.TestClusterInit,
127 rapi_user, rapi_secret)
129 # Test on empty cluster
130 RunTestIf("node-list", qa_node.TestNodeList)
131 RunTestIf("instance-list", qa_instance.TestInstanceList)
133 RunTestIf("create-cluster", qa_node.TestNodeAddAll)
134 if not qa_config.TestEnabled("create-cluster"):
135 # consider the nodes are already there
136 qa_node.MarkNodeAddedAll()
138 RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
140 # enable the watcher (unconditionally)
141 RunTest(qa_daemon.TestResumeWatcher)
143 RunTestIf("node-list", qa_node.TestNodeList)
145 # Test listing fields
146 RunTestIf("node-list", qa_node.TestNodeListFields)
147 RunTestIf("instance-list", qa_instance.TestInstanceListFields)
149 RunTestIf("node-info", qa_node.TestNodeInfo)
152 def RunClusterTests():
153 """Runs tests related to gnt-cluster.
157 ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
158 ("cluster-verify", qa_cluster.TestClusterVerify),
159 ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
160 # TODO: add more cluster modify tests
161 ("cluster-modify", qa_cluster.TestClusterModifyBe),
162 ("cluster-rename", qa_cluster.TestClusterRename),
163 ("cluster-info", qa_cluster.TestClusterVersion),
164 ("cluster-info", qa_cluster.TestClusterInfo),
165 ("cluster-info", qa_cluster.TestClusterGetmaster),
166 ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
167 ("cluster-command", qa_cluster.TestClusterCommand),
168 ("cluster-burnin", qa_cluster.TestClusterBurnin),
169 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
170 ("cluster-oob", qa_cluster.TestClusterOob),
171 ("rapi", qa_rapi.TestVersion),
172 ("rapi", qa_rapi.TestEmptyCluster),
178 """Runs all tests related to gnt-os.
183 qa_os.TestOsDiagnose,
186 qa_os.TestOsPartiallyValid,
187 qa_os.TestOsModifyValid,
188 qa_os.TestOsModifyInvalid,
194 def RunCommonInstanceTests(instance):
195 """Runs a few tests that are common to all disk types.
198 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
199 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
201 RunTestIf("instance-list", qa_instance.TestInstanceList)
203 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
205 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
206 RunTestIf(["instance-modify", "rapi"],
207 qa_rapi.TestRapiInstanceModify, instance)
209 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
211 RunTestIf("instance-reinstall", qa_instance.TestInstanceShutdown, instance)
212 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
213 RunTestIf("instance-reinstall", qa_instance.TestInstanceStartup, instance)
215 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
217 if qa_config.TestEnabled('instance-rename'):
218 rename_source = instance["name"]
219 rename_target = qa_config.get("rename", None)
220 RunTest(qa_instance.TestInstanceShutdown, instance)
221 # perform instance rename to the same name
222 RunTest(qa_instance.TestInstanceRename, rename_source, rename_source)
223 RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
224 rename_source, rename_source)
225 if rename_target is not None:
226 # perform instance rename to a different name, if we have one configured
227 RunTest(qa_instance.TestInstanceRename, rename_source, rename_target)
228 RunTest(qa_instance.TestInstanceRename, rename_target, rename_source)
229 RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
230 rename_source, rename_target)
231 RunTestIf("rapi", qa_rapi.TestRapiInstanceRename,
232 rename_target, rename_source)
233 RunTest(qa_instance.TestInstanceStartup, instance)
235 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
237 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
239 RunTestIf("rapi", qa_rapi.TestInstance, instance)
241 # Lists instances, too
242 RunTestIf("node-list", qa_node.TestNodeList)
245 def RunCommonNodeTests():
246 """Run a few common node tests.
249 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
250 RunTestIf("node-storage", qa_node.TestNodeStorage)
251 RunTestIf("node-oob", qa_node.TestOutOfBand)
254 def RunGroupListTests():
255 """Run tests for listing node groups.
258 RunTestIf("group-list", qa_group.TestGroupList)
259 RunTestIf("group-list", qa_group.TestGroupListFields)
262 def RunGroupRwTests():
263 """Run tests for adding/removing/renaming groups.
266 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
267 RunTestIf("group-rwops", qa_group.TestGroupAddWithOptions)
268 RunTestIf("group-rwops", qa_group.TestGroupModify)
269 RunTestIf("rapi", qa_rapi.TestRapiNodeGroups)
272 def RunExportImportTests(instance, pnode, snode):
273 """Tries to export and import the instance.
275 @param pnode: current primary node of the instance
276 @param snode: current secondary node of the instance, if any,
280 if qa_config.TestEnabled('instance-export'):
281 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
283 expnode = qa_config.AcquireNode(exclude=pnode)
285 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
287 RunTest(qa_instance.TestBackupList, expnode)
289 if qa_config.TestEnabled('instance-import'):
290 newinst = qa_config.AcquireInstance()
292 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
294 RunTest(qa_instance.TestInstanceRemove, newinst)
296 qa_config.ReleaseInstance(newinst)
298 qa_config.ReleaseNode(expnode)
300 if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
301 newinst = qa_config.AcquireInstance()
306 excl = [pnode, snode]
307 tnode = qa_config.AcquireNode(exclude=excl)
309 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
312 qa_config.ReleaseNode(tnode)
314 qa_config.ReleaseInstance(newinst)
317 def RunDaemonTests(instance, pnode):
318 """Test the ganeti-watcher script.
321 RunTest(qa_daemon.TestPauseWatcher)
323 RunTestIf("instance-automatic-restart",
324 qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
325 RunTestIf("instance-consecutive-failures",
326 qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
328 RunTest(qa_daemon.TestResumeWatcher)
331 def RunHardwareFailureTests(instance, pnode, snode):
332 """Test cluster internal hardware failure recovery.
335 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
337 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
338 RunTestIf(["instance-migrate", "rapi"],
339 qa_rapi.TestRapiInstanceMigrate, instance)
341 if qa_config.TestEnabled('instance-replace-disks'):
342 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
344 RunTest(qa_instance.TestReplaceDisks,
345 instance, pnode, snode, othernode)
347 qa_config.ReleaseNode(othernode)
349 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
351 RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
353 RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
354 instance, pnode, snode)
355 RunTestIf("instance-disk-failure",
356 qa_instance.TestInstanceSecondaryDiskFailure, instance,
364 rapi_user = "ganeti-qa"
365 rapi_secret = utils.GenerateSecret()
368 SetupCluster(rapi_user, rapi_secret)
370 # Load RAPI certificate
371 qa_rapi.Setup(rapi_user, rapi_secret)
376 RunTestIf("tags", qa_tags.TestClusterTags)
382 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
384 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
385 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
387 qa_config.ReleaseNode(pnode)
389 pnode = qa_config.AcquireNode()
391 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
393 if qa_rapi.Enabled():
394 RunTest(qa_rapi.TestNode, pnode)
396 if qa_config.TestEnabled("instance-add-plain-disk"):
397 for use_client in [True, False]:
398 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
400 RunCommonInstanceTests(rapi_instance)
401 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
404 if qa_config.TestEnabled('instance-add-plain-disk'):
405 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
406 RunCommonInstanceTests(instance)
408 RunExportImportTests(instance, pnode, None)
409 RunDaemonTests(instance, pnode)
410 RunTest(qa_instance.TestInstanceRemove, instance)
414 ('instance-add-drbd-disk',
415 qa_instance.TestInstanceAddWithDrbdDisk),
418 for name, func in multinode_tests:
419 if qa_config.TestEnabled(name):
420 snode = qa_config.AcquireNode(exclude=pnode)
422 instance = RunTest(func, pnode, snode)
423 RunCommonInstanceTests(instance)
425 RunTest(qa_group.TestAssignNodesIncludingSplit,
426 constants.INITIAL_NODE_GROUP_NAME,
427 pnode["primary"], snode["primary"])
428 if qa_config.TestEnabled('instance-convert-disk'):
429 RunTest(qa_instance.TestInstanceShutdown, instance)
430 RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
431 RunTest(qa_instance.TestInstanceStartup, instance)
432 RunExportImportTests(instance, pnode, snode)
433 RunHardwareFailureTests(instance, pnode, snode)
434 RunTest(qa_instance.TestInstanceRemove, instance)
437 qa_config.ReleaseNode(snode)
439 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
440 for shutdown in [False, True]:
441 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
442 expnode = qa_config.AcquireNode(exclude=pnode)
445 # Stop instance before exporting and removing it
446 RunTest(qa_instance.TestInstanceShutdown, instance)
447 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
448 RunTest(qa_instance.TestBackupList, expnode)
450 qa_config.ReleaseNode(expnode)
455 qa_config.ReleaseNode(pnode)
457 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
459 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
462 @rapi.client.UsesRapiClient
467 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
468 parser.add_option('--yes-do-it', dest='yes_do_it',
470 help="Really execute the tests")
471 (qa_config.options, args) = parser.parse_args()
474 (config_file, ) = args
476 parser.error("Wrong number of arguments.")
478 if not qa_config.options.yes_do_it:
479 print ("Executing this script irreversibly destroys any Ganeti\n"
480 "configuration on all nodes involved. If you really want\n"
481 "to start testing, supply the --yes-do-it option.")
484 qa_config.Load(config_file)
486 qa_utils.StartMultiplexer(qa_config.GetMasterNode()["primary"])
490 qa_utils.CloseMultiplexers()
492 if __name__ == '__main__':