4 # Copyright (C) 2007, 2008, 2009, 2010 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.
42 from ganeti import utils
43 from ganeti import rapi
45 import ganeti.rapi.client
48 def _FormatHeader(line, end=72):
49 """Fill a line up to the end column.
52 line = "---- " + line + " "
53 line += "-" * (end-len(line))
58 def _DescriptionOf(fn):
59 """Computes the description of an item.
63 desc = fn.__doc__.splitlines()[0].strip()
67 return desc.rstrip(".")
69 def RunTest(fn, *args):
70 """Runs a test after printing a header.
74 tstart = datetime.datetime.now()
76 desc = _DescriptionOf(fn)
79 print _FormatHeader("%s start %s" % (tstart, desc))
85 tstop = datetime.datetime.now()
86 tdelta = tstop - tstart
87 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
90 def RunTestIf(testnames, fn, *args):
91 """Runs a test conditionally.
93 @param testnames: either a single test name in the configuration
94 file, or a list of testnames (which will be AND-ed together)
97 if qa_config.TestEnabled(testnames):
100 tstart = datetime.datetime.now()
101 desc = _DescriptionOf(fn)
102 print _FormatHeader("%s skipping %s, test(s) %s disabled" %
103 (tstart, desc, testnames))
107 """Run several environment tests.
110 RunTestIf("env", qa_env.TestSshConnection)
111 RunTestIf("env", qa_env.TestIcmpPing)
112 RunTestIf("env", qa_env.TestGanetiCommands)
115 def SetupCluster(rapi_user, rapi_secret):
116 """Initializes the cluster.
118 @param rapi_user: Login user for RAPI
119 @param rapi_secret: Login secret for RAPI
122 RunTestIf("create-cluster", qa_cluster.TestClusterInit,
123 rapi_user, rapi_secret)
124 RunTestIf("create-cluster", qa_node.TestNodeAddAll)
125 if not qa_config.TestEnabled("create-cluster"):
126 # consider the nodes are already there
127 qa_node.MarkNodeAddedAll()
129 RunTestIf("test-jobqueue", qa_cluster.TestJobqueue)
131 # enable the watcher (unconditionally)
132 RunTest(qa_daemon.TestResumeWatcher)
134 RunTestIf("node-info", qa_node.TestNodeInfo)
137 def RunClusterTests():
138 """Runs tests related to gnt-cluster.
142 ("cluster-renew-crypto", qa_cluster.TestClusterRenewCrypto),
143 ("cluster-verify", qa_cluster.TestClusterVerify),
144 ("cluster-reserved-lvs", qa_cluster.TestClusterReservedLvs),
145 # TODO: add more cluster modify tests
146 ("cluster-modify", qa_cluster.TestClusterModifyBe),
147 ("cluster-rename", qa_cluster.TestClusterRename),
148 ("cluster-info", qa_cluster.TestClusterVersion),
149 ("cluster-info", qa_cluster.TestClusterInfo),
150 ("cluster-info", qa_cluster.TestClusterGetmaster),
151 ("cluster-copyfile", qa_cluster.TestClusterCopyfile),
152 ("cluster-command", qa_cluster.TestClusterCommand),
153 ("cluster-burnin", qa_cluster.TestClusterBurnin),
154 ("cluster-master-failover", qa_cluster.TestClusterMasterFailover),
155 ("rapi", qa_rapi.TestVersion),
156 ("rapi", qa_rapi.TestEmptyCluster),
162 """Runs all tests related to gnt-os.
167 qa_os.TestOsDiagnose,
170 qa_os.TestOsPartiallyValid,
171 qa_os.TestOsModifyValid,
172 qa_os.TestOsModifyInvalid,
178 def RunCommonInstanceTests(instance):
179 """Runs a few tests that are common to all disk types.
182 RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
183 RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
185 RunTestIf("instance-list", qa_instance.TestInstanceList)
187 RunTestIf("instance-info", qa_instance.TestInstanceInfo, instance)
189 RunTestIf("instance-modify", qa_instance.TestInstanceModify, instance)
190 RunTestIf(["instance-modify", "rapi"],
191 qa_rapi.TestRapiInstanceModify, instance)
193 RunTestIf("instance-console", qa_instance.TestInstanceConsole, instance)
195 RunTestIf("instance-reinstall", qa_instance.TestInstanceShutdown, instance)
196 RunTestIf("instance-reinstall", qa_instance.TestInstanceReinstall, instance)
197 RunTestIf("instance-reinstall", qa_instance.TestInstanceStartup, instance)
199 RunTestIf("instance-reboot", qa_instance.TestInstanceReboot, instance)
201 if qa_config.TestEnabled('instance-rename'):
202 rename_source = instance["name"]
203 rename_target = qa_config.get("rename", None)
204 RunTest(qa_instance.TestInstanceShutdown, instance)
205 # perform instance rename to the same name
206 RunTest(qa_instance.TestInstanceRename, rename_source, rename_source)
207 RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, rename_source, rename_source)
208 if rename_target is not None:
209 # perform instance rename to a different name, if we have one configured
210 RunTest(qa_instance.TestInstanceRename, rename_source, rename_target)
211 RunTest(qa_instance.TestInstanceRename, rename_target, rename_source)
212 RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, rename_source, rename_target)
213 RunTestIf("rapi", qa_rapi.TestRapiInstanceRename, rename_target, rename_source)
214 RunTest(qa_instance.TestInstanceStartup, instance)
216 RunTestIf("tags", qa_tags.TestInstanceTags, instance)
218 RunTestIf("rapi", qa_rapi.TestInstance, instance)
221 def RunCommonNodeTests():
222 """Run a few common node tests.
225 RunTestIf("node-volumes", qa_node.TestNodeVolumes)
226 RunTestIf("node-storage", qa_node.TestNodeStorage)
229 def RunGroupListTests():
230 """Run tests for listing node groups.
233 RunTestIf("group-list", qa_group.TestGroupListDefaultFields)
234 RunTestIf("group-list", qa_group.TestGroupListAllFields)
237 def RunGroupRwTests():
238 """Run tests for adding/removing/renaming groups.
241 RunTestIf("group-rwops", qa_group.TestGroupAddRemoveRename)
243 def RunExportImportTests(instance, pnode, snode):
244 """Tries to export and import the instance.
246 @param pnode: current primary node of the instance
247 @param snode: current secondary node of the instance, if any,
251 if qa_config.TestEnabled('instance-export'):
252 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
254 expnode = qa_config.AcquireNode(exclude=pnode)
256 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
258 RunTest(qa_instance.TestBackupList, expnode)
260 if qa_config.TestEnabled('instance-import'):
261 newinst = qa_config.AcquireInstance()
263 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
265 RunTest(qa_instance.TestInstanceRemove, newinst)
267 qa_config.ReleaseInstance(newinst)
269 qa_config.ReleaseNode(expnode)
271 if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
272 newinst = qa_config.AcquireInstance()
277 excl = [pnode, snode]
278 tnode = qa_config.AcquireNode(exclude=excl)
280 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
283 qa_config.ReleaseNode(tnode)
285 qa_config.ReleaseInstance(newinst)
288 def RunDaemonTests(instance, pnode):
289 """Test the ganeti-watcher script.
292 RunTest(qa_daemon.TestPauseWatcher)
294 RunTestIf("instance-automatic-restart",
295 qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
296 RunTestIf("instance-consecutive-failures",
297 qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
299 RunTest(qa_daemon.TestResumeWatcher)
302 def RunHardwareFailureTests(instance, pnode, snode):
303 """Test cluster internal hardware failure recovery.
306 RunTestIf("instance-failover", qa_instance.TestInstanceFailover, instance)
308 RunTestIf("instance-migrate", qa_instance.TestInstanceMigrate, instance)
309 RunTestIf(["instance-migrate", "rapi"],
310 qa_rapi.TestRapiInstanceMigrate, instance)
312 if qa_config.TestEnabled('instance-replace-disks'):
313 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
315 RunTest(qa_instance.TestReplaceDisks,
316 instance, pnode, snode, othernode)
318 qa_config.ReleaseNode(othernode)
320 RunTestIf("node-evacuate", qa_node.TestNodeEvacuate, pnode, snode)
322 RunTestIf("node-failover", qa_node.TestNodeFailover, pnode, snode)
324 RunTestIf("instance-disk-failure", qa_instance.TestInstanceMasterDiskFailure,
325 instance, pnode, snode)
326 RunTestIf("instance-disk-failure",
327 qa_instance.TestInstanceSecondaryDiskFailure, instance,
331 @rapi.client.UsesRapiClient
336 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
337 parser.add_option('--yes-do-it', dest='yes_do_it',
339 help="Really execute the tests")
340 (qa_config.options, args) = parser.parse_args()
343 (config_file, ) = args
345 parser.error("Wrong number of arguments.")
347 if not qa_config.options.yes_do_it:
348 print ("Executing this script irreversibly destroys any Ganeti\n"
349 "configuration on all nodes involved. If you really want\n"
350 "to start testing, supply the --yes-do-it option.")
353 qa_config.Load(config_file)
355 rapi_user = "ganeti-qa"
356 rapi_secret = utils.GenerateSecret()
359 SetupCluster(rapi_user, rapi_secret)
361 # Load RAPI certificate
362 qa_rapi.Setup(rapi_user, rapi_secret)
367 RunTestIf("tags", qa_tags.TestClusterTags)
373 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
375 RunTestIf("node-readd", qa_node.TestNodeReadd, pnode)
376 RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
378 qa_config.ReleaseNode(pnode)
380 pnode = qa_config.AcquireNode()
382 RunTestIf("tags", qa_tags.TestNodeTags, pnode)
384 if qa_rapi.Enabled():
385 RunTest(qa_rapi.TestNode, pnode)
387 if qa_config.TestEnabled("instance-add-plain-disk"):
388 for use_client in [True, False]:
389 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
391 RunCommonInstanceTests(rapi_instance)
392 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
395 if qa_config.TestEnabled('instance-add-plain-disk'):
396 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
397 RunCommonInstanceTests(instance)
399 RunExportImportTests(instance, pnode, None)
400 RunDaemonTests(instance, pnode)
401 RunTest(qa_instance.TestInstanceRemove, instance)
405 ('instance-add-drbd-disk',
406 qa_instance.TestInstanceAddWithDrbdDisk),
409 for name, func in multinode_tests:
410 if qa_config.TestEnabled(name):
411 snode = qa_config.AcquireNode(exclude=pnode)
413 instance = RunTest(func, pnode, snode)
414 RunTestIf("cluster-verify", qa_cluster.TestClusterVerify)
415 RunCommonInstanceTests(instance)
417 if qa_config.TestEnabled('instance-convert-disk'):
418 RunTest(qa_instance.TestInstanceShutdown, instance)
419 RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
420 RunTest(qa_instance.TestInstanceStartup, instance)
421 RunExportImportTests(instance, pnode, snode)
422 RunHardwareFailureTests(instance, pnode, snode)
423 RunTest(qa_instance.TestInstanceRemove, instance)
426 qa_config.ReleaseNode(snode)
428 if qa_config.TestEnabled(["instance-add-plain-disk", "instance-export"]):
429 for shutdown in [False, True]:
430 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
431 expnode = qa_config.AcquireNode(exclude=pnode)
434 # Stop instance before exporting and removing it
435 RunTest(qa_instance.TestInstanceShutdown, instance)
436 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
437 RunTest(qa_instance.TestBackupList, expnode)
439 qa_config.ReleaseNode(expnode)
444 qa_config.ReleaseNode(pnode)
446 RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
448 RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
451 if __name__ == '__main__':