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 RunTest(fn, *args):
48 """Runs a test after printing a header.
52 desc = fn.__doc__.splitlines()[0].strip()
56 now = str(datetime.datetime.now())
59 print '---', now, ('-' * (55 - len(now)))
67 """Run several environment tests.
70 if not qa_config.TestEnabled('env'):
73 RunTest(qa_env.TestSshConnection)
74 RunTest(qa_env.TestIcmpPing)
75 RunTest(qa_env.TestGanetiCommands)
78 def SetupCluster(rapi_user, rapi_secret):
79 """Initializes the cluster.
81 @param rapi_user: Login user for RAPI
82 @param rapi_secret: Login secret for RAPI
85 if qa_config.TestEnabled('create-cluster'):
86 RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret)
87 RunTest(qa_node.TestNodeAddAll)
88 RunTest(qa_cluster.TestJobqueue)
90 # consider the nodes are already there
91 qa_node.MarkNodeAddedAll()
92 if qa_config.TestEnabled('node-info'):
93 RunTest(qa_node.TestNodeInfo)
96 def RunClusterTests():
97 """Runs tests related to gnt-cluster.
100 if qa_config.TestEnabled("cluster-renew-crypto"):
101 RunTest(qa_cluster.TestClusterRenewCrypto)
103 if qa_config.TestEnabled('cluster-verify'):
104 RunTest(qa_cluster.TestClusterVerify)
106 if qa_config.TestEnabled('cluster-reserved-lvs'):
107 RunTest(qa_cluster.TestClusterReservedLvs)
109 if qa_config.TestEnabled('cluster-rename'):
110 RunTest(qa_cluster.TestClusterRename)
112 if qa_config.TestEnabled('cluster-info'):
113 RunTest(qa_cluster.TestClusterVersion)
114 RunTest(qa_cluster.TestClusterInfo)
115 RunTest(qa_cluster.TestClusterGetmaster)
117 if qa_config.TestEnabled('cluster-copyfile'):
118 RunTest(qa_cluster.TestClusterCopyfile)
120 if qa_config.TestEnabled('cluster-command'):
121 RunTest(qa_cluster.TestClusterCommand)
123 if qa_config.TestEnabled('cluster-burnin'):
124 RunTest(qa_cluster.TestClusterBurnin)
126 if qa_config.TestEnabled('cluster-master-failover'):
127 RunTest(qa_cluster.TestClusterMasterFailover)
129 if qa_rapi.Enabled():
130 RunTest(qa_rapi.TestVersion)
131 RunTest(qa_rapi.TestEmptyCluster)
135 """Runs all tests related to gnt-os.
138 if not qa_config.TestEnabled('os'):
141 RunTest(qa_os.TestOsList)
142 RunTest(qa_os.TestOsDiagnose)
143 RunTest(qa_os.TestOsValid)
144 RunTest(qa_os.TestOsInvalid)
145 RunTest(qa_os.TestOsPartiallyValid)
146 RunTest(qa_os.TestOsModifyValid)
147 RunTest(qa_os.TestOsModifyInvalid)
148 RunTest(qa_os.TestOsStates)
151 def RunCommonInstanceTests(instance):
152 """Runs a few tests that are common to all disk types.
155 if qa_config.TestEnabled('instance-shutdown'):
156 RunTest(qa_instance.TestInstanceShutdown, instance)
157 RunTest(qa_instance.TestInstanceStartup, instance)
159 if qa_config.TestEnabled('instance-list'):
160 RunTest(qa_instance.TestInstanceList)
162 if qa_config.TestEnabled('instance-info'):
163 RunTest(qa_instance.TestInstanceInfo, instance)
165 if qa_config.TestEnabled('instance-modify'):
166 RunTest(qa_instance.TestInstanceModify, instance)
167 if qa_rapi.Enabled():
168 RunTest(qa_rapi.TestRapiInstanceModify, instance)
170 if qa_config.TestEnabled('instance-console'):
171 RunTest(qa_instance.TestInstanceConsole, instance)
173 if qa_config.TestEnabled('instance-reinstall'):
174 RunTest(qa_instance.TestInstanceShutdown, instance)
175 RunTest(qa_instance.TestInstanceReinstall, instance)
176 RunTest(qa_instance.TestInstanceStartup, instance)
178 if qa_config.TestEnabled('instance-reboot'):
179 RunTest(qa_instance.TestInstanceReboot, instance)
181 if qa_config.TestEnabled('instance-rename'):
182 rename_target = qa_config.get("rename", None)
183 if rename_target is None:
184 print qa_utils.FormatError("Can rename instance, 'rename' entry is"
185 " missing from configuration")
187 RunTest(qa_instance.TestInstanceShutdown, instance)
188 RunTest(qa_instance.TestInstanceRename, instance, rename_target)
189 if qa_rapi.Enabled():
190 RunTest(qa_rapi.TestRapiInstanceRename, instance, rename_target)
191 RunTest(qa_instance.TestInstanceStartup, instance)
193 if qa_config.TestEnabled('tags'):
194 RunTest(qa_tags.TestInstanceTags, instance)
196 if qa_config.TestEnabled('node-volumes'):
197 RunTest(qa_node.TestNodeVolumes)
199 if qa_config.TestEnabled("node-storage"):
200 RunTest(qa_node.TestNodeStorage)
202 if qa_rapi.Enabled():
203 RunTest(qa_rapi.TestInstance, instance)
206 def RunExportImportTests(instance, pnode):
207 """Tries to export and import the instance.
210 if qa_config.TestEnabled('instance-export'):
211 RunTest(qa_instance.TestInstanceExportNoTarget, instance)
213 expnode = qa_config.AcquireNode(exclude=pnode)
215 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
217 RunTest(qa_instance.TestBackupList, expnode)
219 if qa_config.TestEnabled('instance-import'):
220 newinst = qa_config.AcquireInstance()
222 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
224 RunTest(qa_instance.TestInstanceRemove, newinst)
226 qa_config.ReleaseInstance(newinst)
228 qa_config.ReleaseNode(expnode)
230 if (qa_rapi.Enabled() and
231 qa_config.TestEnabled("inter-cluster-instance-move")):
232 newinst = qa_config.AcquireInstance()
234 pnode2 = qa_config.AcquireNode(exclude=pnode)
236 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
239 qa_config.ReleaseNode(pnode2)
241 qa_config.ReleaseInstance(newinst)
244 def RunDaemonTests(instance, pnode):
245 """Test the ganeti-watcher script.
248 automatic_restart = \
249 qa_config.TestEnabled('instance-automatic-restart')
250 consecutive_failures = \
251 qa_config.TestEnabled('instance-consecutive-failures')
253 if automatic_restart or consecutive_failures:
254 qa_daemon.PrintCronWarning()
256 if automatic_restart:
257 RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
259 if consecutive_failures:
260 RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
263 def RunHardwareFailureTests(instance, pnode, snode):
264 """Test cluster internal hardware failure recovery.
267 if qa_config.TestEnabled('instance-failover'):
268 RunTest(qa_instance.TestInstanceFailover, instance)
270 if qa_config.TestEnabled("instance-migrate"):
271 RunTest(qa_instance.TestInstanceMigrate, instance)
273 if qa_rapi.Enabled():
274 RunTest(qa_rapi.TestRapiInstanceMigrate, instance)
276 if qa_config.TestEnabled('instance-replace-disks'):
277 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
279 RunTest(qa_instance.TestReplaceDisks,
280 instance, pnode, snode, othernode)
282 qa_config.ReleaseNode(othernode)
284 if qa_config.TestEnabled('node-evacuate'):
285 RunTest(qa_node.TestNodeEvacuate, pnode, snode)
287 if qa_config.TestEnabled('node-failover'):
288 RunTest(qa_node.TestNodeFailover, pnode, snode)
290 if qa_config.TestEnabled('instance-disk-failure'):
291 RunTest(qa_instance.TestInstanceMasterDiskFailure,
292 instance, pnode, snode)
293 RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
294 instance, pnode, snode)
297 @rapi.client.UsesRapiClient
302 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
303 parser.add_option('--yes-do-it', dest='yes_do_it',
305 help="Really execute the tests")
306 (qa_config.options, args) = parser.parse_args()
309 (config_file, ) = args
311 parser.error("Wrong number of arguments.")
313 if not qa_config.options.yes_do_it:
314 print ("Executing this script irreversibly destroys any Ganeti\n"
315 "configuration on all nodes involved. If you really want\n"
316 "to start testing, supply the --yes-do-it option.")
319 qa_config.Load(config_file)
321 rapi_user = "ganeti-qa"
322 rapi_secret = utils.GenerateSecret()
325 SetupCluster(rapi_user, rapi_secret)
327 # Load RAPI certificate
328 qa_rapi.Setup(rapi_user, rapi_secret)
333 if qa_config.TestEnabled('tags'):
334 RunTest(qa_tags.TestClusterTags)
336 if qa_config.TestEnabled('node-readd'):
337 master = qa_config.GetMasterNode()
338 pnode = qa_config.AcquireNode(exclude=master)
340 RunTest(qa_node.TestNodeReadd, pnode)
342 qa_config.ReleaseNode(pnode)
344 pnode = qa_config.AcquireNode()
346 if qa_config.TestEnabled('tags'):
347 RunTest(qa_tags.TestNodeTags, pnode)
349 if qa_rapi.Enabled():
350 RunTest(qa_rapi.TestNode, pnode)
352 if qa_config.TestEnabled("instance-add-plain-disk"):
353 for use_client in [True, False]:
354 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
356 RunCommonInstanceTests(rapi_instance)
357 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
360 if qa_config.TestEnabled('instance-add-plain-disk'):
361 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
362 RunCommonInstanceTests(instance)
363 RunExportImportTests(instance, pnode)
364 RunDaemonTests(instance, pnode)
365 RunTest(qa_instance.TestInstanceRemove, instance)
369 ('instance-add-drbd-disk',
370 qa_instance.TestInstanceAddWithDrbdDisk),
373 for name, func in multinode_tests:
374 if qa_config.TestEnabled(name):
375 snode = qa_config.AcquireNode(exclude=pnode)
377 instance = RunTest(func, pnode, snode)
378 RunCommonInstanceTests(instance)
379 if qa_config.TestEnabled('instance-convert-disk'):
380 RunTest(qa_instance.TestInstanceShutdown, instance)
381 RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
382 RunTest(qa_instance.TestInstanceStartup, instance)
383 RunExportImportTests(instance, pnode)
384 RunHardwareFailureTests(instance, pnode, snode)
385 RunTest(qa_instance.TestInstanceRemove, instance)
388 qa_config.ReleaseNode(snode)
390 if (qa_config.TestEnabled('instance-add-plain-disk') and
391 qa_config.TestEnabled("instance-export")):
392 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
393 expnode = qa_config.AcquireNode(exclude=pnode)
395 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
396 RunTest(qa_instance.TestBackupList, expnode)
398 qa_config.ReleaseNode(expnode)
403 qa_config.ReleaseNode(pnode)
405 if qa_config.TestEnabled('create-cluster'):
406 RunTest(qa_node.TestNodeRemoveAll)
408 if qa_config.TestEnabled('cluster-destroy'):
409 RunTest(qa_cluster.TestClusterDestroy)
412 if __name__ == '__main__':