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.
41 from ganeti import utils
42 from ganeti import rapi
44 import ganeti.rapi.client
47 def _FormatHeader(line, end=72, char="-"):
48 """Fill a line up to the end column.
51 line = "---- " + line + " "
52 line += "-" * (end-len(line))
57 def RunTest(fn, *args):
58 """Runs a test after printing a header.
62 desc = fn.__doc__.splitlines()[0].strip()
66 desc = desc.rstrip(".")
68 tstart = datetime.datetime.now()
71 print _FormatHeader("%s start %s" % (tstart, desc))
77 tstop = datetime.datetime.now()
78 tdelta = tstop - tstart
79 print _FormatHeader("%s time=%s %s" % (tstop, tdelta, desc))
83 """Run several environment tests.
86 if not qa_config.TestEnabled('env'):
89 RunTest(qa_env.TestSshConnection)
90 RunTest(qa_env.TestIcmpPing)
91 RunTest(qa_env.TestGanetiCommands)
94 def SetupCluster(rapi_user, rapi_secret):
95 """Initializes the cluster.
97 @param rapi_user: Login user for RAPI
98 @param rapi_secret: Login secret for RAPI
101 if qa_config.TestEnabled('create-cluster'):
102 RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret)
103 RunTest(qa_node.TestNodeAddAll)
105 # consider the nodes are already there
106 qa_node.MarkNodeAddedAll()
108 if qa_config.TestEnabled("test-jobqueue"):
109 RunTest(qa_cluster.TestJobqueue)
111 # enable the watcher (unconditionally)
112 RunTest(qa_daemon.TestResumeWatcher)
114 if qa_config.TestEnabled('node-info'):
115 RunTest(qa_node.TestNodeInfo)
118 def RunClusterTests():
119 """Runs tests related to gnt-cluster.
122 if qa_config.TestEnabled("cluster-renew-crypto"):
123 RunTest(qa_cluster.TestClusterRenewCrypto)
125 if qa_config.TestEnabled('cluster-verify'):
126 RunTest(qa_cluster.TestClusterVerify)
128 if qa_config.TestEnabled('cluster-reserved-lvs'):
129 RunTest(qa_cluster.TestClusterReservedLvs)
131 if qa_config.TestEnabled("cluster-modify"):
132 RunTest(qa_cluster.TestClusterModifyBe)
133 # TODO: add more cluster modify tests
135 if qa_config.TestEnabled('cluster-rename'):
136 RunTest(qa_cluster.TestClusterRename)
138 if qa_config.TestEnabled('cluster-info'):
139 RunTest(qa_cluster.TestClusterVersion)
140 RunTest(qa_cluster.TestClusterInfo)
141 RunTest(qa_cluster.TestClusterGetmaster)
143 if qa_config.TestEnabled('cluster-copyfile'):
144 RunTest(qa_cluster.TestClusterCopyfile)
146 if qa_config.TestEnabled('cluster-command'):
147 RunTest(qa_cluster.TestClusterCommand)
149 if qa_config.TestEnabled('cluster-burnin'):
150 RunTest(qa_cluster.TestClusterBurnin)
152 if qa_config.TestEnabled('cluster-master-failover'):
153 RunTest(qa_cluster.TestClusterMasterFailover)
155 if qa_rapi.Enabled():
156 RunTest(qa_rapi.TestVersion)
157 RunTest(qa_rapi.TestEmptyCluster)
161 """Runs all tests related to gnt-os.
164 if not qa_config.TestEnabled('os'):
167 RunTest(qa_os.TestOsList)
168 RunTest(qa_os.TestOsDiagnose)
169 RunTest(qa_os.TestOsValid)
170 RunTest(qa_os.TestOsInvalid)
171 RunTest(qa_os.TestOsPartiallyValid)
172 RunTest(qa_os.TestOsModifyValid)
173 RunTest(qa_os.TestOsModifyInvalid)
174 RunTest(qa_os.TestOsStates)
177 def RunCommonInstanceTests(instance):
178 """Runs a few tests that are common to all disk types.
181 if qa_config.TestEnabled('instance-shutdown'):
182 RunTest(qa_instance.TestInstanceShutdown, instance)
183 RunTest(qa_instance.TestInstanceStartup, instance)
185 if qa_config.TestEnabled('instance-list'):
186 RunTest(qa_instance.TestInstanceList)
188 if qa_config.TestEnabled('instance-info'):
189 RunTest(qa_instance.TestInstanceInfo, instance)
191 if qa_config.TestEnabled('instance-modify'):
192 RunTest(qa_instance.TestInstanceModify, instance)
193 if qa_rapi.Enabled():
194 RunTest(qa_rapi.TestRapiInstanceModify, instance)
196 if qa_config.TestEnabled('instance-console'):
197 RunTest(qa_instance.TestInstanceConsole, instance)
199 if qa_config.TestEnabled('instance-reinstall'):
200 RunTest(qa_instance.TestInstanceShutdown, instance)
201 RunTest(qa_instance.TestInstanceReinstall, instance)
202 RunTest(qa_instance.TestInstanceStartup, instance)
204 if qa_config.TestEnabled('instance-reboot'):
205 RunTest(qa_instance.TestInstanceReboot, instance)
207 if qa_config.TestEnabled('instance-rename'):
208 rename_target = qa_config.get("rename", None)
209 if rename_target is None:
210 print qa_utils.FormatError("Can rename instance, 'rename' entry is"
211 " missing from configuration")
213 RunTest(qa_instance.TestInstanceShutdown, instance)
214 RunTest(qa_instance.TestInstanceRename, instance, rename_target)
215 if qa_rapi.Enabled():
216 RunTest(qa_rapi.TestRapiInstanceRename, instance, rename_target)
217 RunTest(qa_instance.TestInstanceStartup, instance)
219 if qa_config.TestEnabled('tags'):
220 RunTest(qa_tags.TestInstanceTags, instance)
222 if qa_rapi.Enabled():
223 RunTest(qa_rapi.TestInstance, instance)
226 def RunCommonNodeTests():
227 """Run a few common node tests.
230 if qa_config.TestEnabled('node-volumes'):
231 RunTest(qa_node.TestNodeVolumes)
233 if qa_config.TestEnabled("node-storage"):
234 RunTest(qa_node.TestNodeStorage)
237 def RunExportImportTests(instance, pnode, snode):
238 """Tries to export and import the instance.
240 @param pnode: current primary node of the instance
241 @param snode: current secondary node of the instance, if any,
245 if qa_config.TestEnabled('instance-export'):
246 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
248 expnode = qa_config.AcquireNode(exclude=pnode)
250 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
252 RunTest(qa_instance.TestBackupList, expnode)
254 if qa_config.TestEnabled('instance-import'):
255 newinst = qa_config.AcquireInstance()
257 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
259 RunTest(qa_instance.TestInstanceRemove, newinst)
261 qa_config.ReleaseInstance(newinst)
263 qa_config.ReleaseNode(expnode)
265 if (qa_rapi.Enabled() and
266 qa_config.TestEnabled("inter-cluster-instance-move")):
267 newinst = qa_config.AcquireInstance()
272 excl = [pnode, snode]
273 tnode = qa_config.AcquireNode(exclude=excl)
275 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
278 qa_config.ReleaseNode(tnode)
280 qa_config.ReleaseInstance(newinst)
283 def RunDaemonTests(instance, pnode):
284 """Test the ganeti-watcher script.
287 automatic_restart = \
288 qa_config.TestEnabled('instance-automatic-restart')
289 consecutive_failures = \
290 qa_config.TestEnabled('instance-consecutive-failures')
292 RunTest(qa_daemon.TestPauseWatcher)
293 if automatic_restart or consecutive_failures:
295 if automatic_restart:
296 RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
298 if consecutive_failures:
299 RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
301 RunTest(qa_daemon.TestResumeWatcher)
304 def RunHardwareFailureTests(instance, pnode, snode):
305 """Test cluster internal hardware failure recovery.
308 if qa_config.TestEnabled('instance-failover'):
309 RunTest(qa_instance.TestInstanceFailover, instance)
311 if qa_config.TestEnabled("instance-migrate"):
312 RunTest(qa_instance.TestInstanceMigrate, instance)
314 if qa_rapi.Enabled():
315 RunTest(qa_rapi.TestRapiInstanceMigrate, instance)
317 if qa_config.TestEnabled('instance-replace-disks'):
318 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
320 RunTest(qa_instance.TestReplaceDisks,
321 instance, pnode, snode, othernode)
323 qa_config.ReleaseNode(othernode)
325 if qa_config.TestEnabled('node-evacuate'):
326 RunTest(qa_node.TestNodeEvacuate, pnode, snode)
328 if qa_config.TestEnabled('node-failover'):
329 RunTest(qa_node.TestNodeFailover, pnode, snode)
331 if qa_config.TestEnabled('instance-disk-failure'):
332 RunTest(qa_instance.TestInstanceMasterDiskFailure,
333 instance, pnode, snode)
334 RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
335 instance, pnode, snode)
338 @rapi.client.UsesRapiClient
343 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
344 parser.add_option('--yes-do-it', dest='yes_do_it',
346 help="Really execute the tests")
347 (qa_config.options, args) = parser.parse_args()
350 (config_file, ) = args
352 parser.error("Wrong number of arguments.")
354 if not qa_config.options.yes_do_it:
355 print ("Executing this script irreversibly destroys any Ganeti\n"
356 "configuration on all nodes involved. If you really want\n"
357 "to start testing, supply the --yes-do-it option.")
360 qa_config.Load(config_file)
362 rapi_user = "ganeti-qa"
363 rapi_secret = utils.GenerateSecret()
366 SetupCluster(rapi_user, rapi_secret)
368 # Load RAPI certificate
369 qa_rapi.Setup(rapi_user, rapi_secret)
374 if qa_config.TestEnabled('tags'):
375 RunTest(qa_tags.TestClusterTags)
379 pnode = qa_config.AcquireNode(exclude=qa_config.GetMasterNode())
381 if qa_config.TestEnabled('node-readd'):
382 RunTest(qa_node.TestNodeReadd, pnode)
384 if qa_config.TestEnabled("node-modify"):
385 RunTest(qa_node.TestNodeModify, pnode)
387 qa_config.ReleaseNode(pnode)
389 pnode = qa_config.AcquireNode()
391 if qa_config.TestEnabled('tags'):
392 RunTest(qa_tags.TestNodeTags, pnode)
394 if qa_rapi.Enabled():
395 RunTest(qa_rapi.TestNode, pnode)
397 if qa_config.TestEnabled("instance-add-plain-disk"):
398 for use_client in [True, False]:
399 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
401 RunCommonInstanceTests(rapi_instance)
402 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
405 if qa_config.TestEnabled('instance-add-plain-disk'):
406 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
407 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 if qa_config.TestEnabled("cluster-verify"):
424 RunTest(qa_cluster.TestClusterVerify)
425 RunCommonInstanceTests(instance)
426 if qa_config.TestEnabled('instance-convert-disk'):
427 RunTest(qa_instance.TestInstanceShutdown, instance)
428 RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
429 RunTest(qa_instance.TestInstanceStartup, instance)
430 RunExportImportTests(instance, pnode, snode)
431 RunHardwareFailureTests(instance, pnode, snode)
432 RunTest(qa_instance.TestInstanceRemove, instance)
435 qa_config.ReleaseNode(snode)
437 if (qa_config.TestEnabled('instance-add-plain-disk') and
438 qa_config.TestEnabled("instance-export")):
439 for shutdown in [False, True]:
440 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
441 expnode = qa_config.AcquireNode(exclude=pnode)
444 # Stop instance before exporting and removing it
445 RunTest(qa_instance.TestInstanceShutdown, instance)
446 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
447 RunTest(qa_instance.TestBackupList, expnode)
449 qa_config.ReleaseNode(expnode)
454 qa_config.ReleaseNode(pnode)
456 if qa_config.TestEnabled('create-cluster'):
457 RunTest(qa_node.TestNodeRemoveAll)
459 if qa_config.TestEnabled('cluster-destroy'):
460 RunTest(qa_cluster.TestClusterDestroy)
463 if __name__ == '__main__':