4 # Copyright (C) 2007 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)
89 # consider the nodes are already there
90 qa_node.MarkNodeAddedAll()
91 if qa_config.TestEnabled('node-info'):
92 RunTest(qa_node.TestNodeInfo)
95 def RunClusterTests():
96 """Runs tests related to gnt-cluster.
99 if qa_config.TestEnabled("cluster-renew-crypto"):
100 RunTest(qa_cluster.TestClusterRenewCrypto)
102 if qa_config.TestEnabled('cluster-verify'):
103 RunTest(qa_cluster.TestClusterVerify)
105 if qa_config.TestEnabled('cluster-reserved-lvs'):
106 RunTest(qa_cluster.TestClusterReservedLvs)
108 if qa_config.TestEnabled('cluster-rename'):
109 RunTest(qa_cluster.TestClusterRename)
111 if qa_config.TestEnabled('cluster-info'):
112 RunTest(qa_cluster.TestClusterVersion)
113 RunTest(qa_cluster.TestClusterInfo)
114 RunTest(qa_cluster.TestClusterGetmaster)
116 if qa_config.TestEnabled('cluster-copyfile'):
117 RunTest(qa_cluster.TestClusterCopyfile)
119 if qa_config.TestEnabled('cluster-command'):
120 RunTest(qa_cluster.TestClusterCommand)
122 if qa_config.TestEnabled('cluster-burnin'):
123 RunTest(qa_cluster.TestClusterBurnin)
125 if qa_config.TestEnabled('cluster-master-failover'):
126 RunTest(qa_cluster.TestClusterMasterFailover)
128 if qa_rapi.Enabled():
129 RunTest(qa_rapi.TestVersion)
130 RunTest(qa_rapi.TestEmptyCluster)
134 """Runs all tests related to gnt-os.
137 if not qa_config.TestEnabled('os'):
140 RunTest(qa_os.TestOsList)
141 RunTest(qa_os.TestOsDiagnose)
142 RunTest(qa_os.TestOsValid)
143 RunTest(qa_os.TestOsInvalid)
144 RunTest(qa_os.TestOsPartiallyValid)
145 RunTest(qa_os.TestOsModifyValid)
146 RunTest(qa_os.TestOsModifyInvalid)
149 def RunCommonInstanceTests(instance):
150 """Runs a few tests that are common to all disk types.
153 if qa_config.TestEnabled('instance-shutdown'):
154 RunTest(qa_instance.TestInstanceShutdown, instance)
155 RunTest(qa_instance.TestInstanceStartup, instance)
157 if qa_config.TestEnabled('instance-list'):
158 RunTest(qa_instance.TestInstanceList)
160 if qa_config.TestEnabled('instance-info'):
161 RunTest(qa_instance.TestInstanceInfo, instance)
163 if qa_config.TestEnabled('instance-modify'):
164 RunTest(qa_instance.TestInstanceModify, instance)
166 if qa_config.TestEnabled('instance-console'):
167 RunTest(qa_instance.TestInstanceConsole, instance)
169 if qa_config.TestEnabled('instance-reinstall'):
170 RunTest(qa_instance.TestInstanceShutdown, instance)
171 RunTest(qa_instance.TestInstanceReinstall, instance)
172 RunTest(qa_instance.TestInstanceStartup, instance)
174 if qa_config.TestEnabled('instance-reboot'):
175 RunTest(qa_instance.TestInstanceReboot, instance)
177 if qa_config.TestEnabled('instance-rename'):
178 rename_target = qa_config.get("rename", None)
179 if rename_target is None:
180 print qa_utils.FormatError("Can rename instance, 'rename' entry is"
181 " missing from configuration")
183 RunTest(qa_instance.TestInstanceShutdown, instance)
184 RunTest(qa_instance.TestInstanceRename, instance, rename_target)
185 if qa_rapi.Enabled():
186 RunTest(qa_rapi.TestRapiInstanceRename, instance, rename_target)
187 RunTest(qa_instance.TestInstanceStartup, instance)
189 if qa_config.TestEnabled('tags'):
190 RunTest(qa_tags.TestInstanceTags, instance)
192 if qa_config.TestEnabled('node-volumes'):
193 RunTest(qa_node.TestNodeVolumes)
195 if qa_config.TestEnabled("node-storage"):
196 RunTest(qa_node.TestNodeStorage)
198 if qa_rapi.Enabled():
199 RunTest(qa_rapi.TestInstance, instance)
202 def RunExportImportTests(instance, pnode):
203 """Tries to export and import the instance.
206 if qa_config.TestEnabled('instance-export'):
207 expnode = qa_config.AcquireNode(exclude=pnode)
209 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
211 RunTest(qa_instance.TestBackupList, expnode)
213 if qa_config.TestEnabled('instance-import'):
214 newinst = qa_config.AcquireInstance()
216 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
218 RunTest(qa_instance.TestInstanceRemove, newinst)
220 qa_config.ReleaseInstance(newinst)
222 qa_config.ReleaseNode(expnode)
224 if (qa_rapi.Enabled() and
225 qa_config.TestEnabled("inter-cluster-instance-move")):
226 newinst = qa_config.AcquireInstance()
228 pnode2 = qa_config.AcquireNode(exclude=pnode)
230 RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
233 qa_config.ReleaseNode(pnode2)
235 qa_config.ReleaseInstance(newinst)
238 def RunDaemonTests(instance, pnode):
239 """Test the ganeti-watcher script.
242 automatic_restart = \
243 qa_config.TestEnabled('instance-automatic-restart')
244 consecutive_failures = \
245 qa_config.TestEnabled('instance-consecutive-failures')
247 if automatic_restart or consecutive_failures:
248 qa_daemon.PrintCronWarning()
250 if automatic_restart:
251 RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
253 if consecutive_failures:
254 RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
257 def RunHardwareFailureTests(instance, pnode, snode):
258 """Test cluster internal hardware failure recovery.
261 if qa_config.TestEnabled('instance-failover'):
262 RunTest(qa_instance.TestInstanceFailover, instance)
264 if qa_config.TestEnabled("instance-migrate"):
265 RunTest(qa_instance.TestInstanceMigrate, instance)
267 if qa_rapi.Enabled():
268 RunTest(qa_rapi.TestRapiInstanceMigrate, instance)
270 if qa_config.TestEnabled('instance-replace-disks'):
271 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
273 RunTest(qa_instance.TestReplaceDisks,
274 instance, pnode, snode, othernode)
276 qa_config.ReleaseNode(othernode)
278 if qa_config.TestEnabled('node-evacuate'):
279 RunTest(qa_node.TestNodeEvacuate, pnode, snode)
281 if qa_config.TestEnabled('node-failover'):
282 RunTest(qa_node.TestNodeFailover, pnode, snode)
284 if qa_config.TestEnabled('instance-disk-failure'):
285 RunTest(qa_instance.TestInstanceMasterDiskFailure,
286 instance, pnode, snode)
287 RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
288 instance, pnode, snode)
291 @rapi.client.UsesRapiClient
296 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
297 parser.add_option('--yes-do-it', dest='yes_do_it',
299 help="Really execute the tests")
300 (qa_config.options, args) = parser.parse_args()
303 (config_file, ) = args
305 parser.error("Wrong number of arguments.")
307 if not qa_config.options.yes_do_it:
308 print ("Executing this script irreversibly destroys any Ganeti\n"
309 "configuration on all nodes involved. If you really want\n"
310 "to start testing, supply the --yes-do-it option.")
313 qa_config.Load(config_file)
315 rapi_user = "ganeti-qa"
316 rapi_secret = utils.GenerateSecret()
319 SetupCluster(rapi_user, rapi_secret)
321 # Load RAPI certificate
322 qa_rapi.Setup(rapi_user, rapi_secret)
327 if qa_config.TestEnabled('tags'):
328 RunTest(qa_tags.TestClusterTags)
330 if qa_config.TestEnabled('node-readd'):
331 master = qa_config.GetMasterNode()
332 pnode = qa_config.AcquireNode(exclude=master)
334 RunTest(qa_node.TestNodeReadd, pnode)
336 qa_config.ReleaseNode(pnode)
338 pnode = qa_config.AcquireNode()
340 if qa_config.TestEnabled('tags'):
341 RunTest(qa_tags.TestNodeTags, pnode)
343 if qa_rapi.Enabled():
344 RunTest(qa_rapi.TestNode, pnode)
346 if qa_config.TestEnabled("instance-add-plain-disk"):
347 for use_client in [True, False]:
348 rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
350 RunCommonInstanceTests(rapi_instance)
351 RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client)
354 if qa_config.TestEnabled('instance-add-plain-disk'):
355 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
356 RunCommonInstanceTests(instance)
357 RunExportImportTests(instance, pnode)
358 RunDaemonTests(instance, pnode)
359 RunTest(qa_instance.TestInstanceRemove, instance)
363 ('instance-add-drbd-disk',
364 qa_instance.TestInstanceAddWithDrbdDisk),
367 for name, func in multinode_tests:
368 if qa_config.TestEnabled(name):
369 snode = qa_config.AcquireNode(exclude=pnode)
371 instance = RunTest(func, pnode, snode)
372 RunCommonInstanceTests(instance)
373 if qa_config.TestEnabled('instance-convert-disk'):
374 RunTest(qa_instance.TestInstanceShutdown, instance)
375 RunTest(qa_instance.TestInstanceConvertDisk, instance, snode)
376 RunTest(qa_instance.TestInstanceStartup, instance)
377 RunExportImportTests(instance, pnode)
378 RunHardwareFailureTests(instance, pnode, snode)
379 RunTest(qa_instance.TestInstanceRemove, instance)
382 qa_config.ReleaseNode(snode)
384 if (qa_config.TestEnabled('instance-add-plain-disk') and
385 qa_config.TestEnabled("instance-export")):
386 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
387 expnode = qa_config.AcquireNode(exclude=pnode)
389 RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
390 RunTest(qa_instance.TestBackupList, expnode)
392 qa_config.ReleaseNode(expnode)
397 qa_config.ReleaseNode(pnode)
399 if qa_config.TestEnabled('create-cluster'):
400 RunTest(qa_node.TestNodeRemoveAll)
402 if qa_config.TestEnabled('cluster-destroy'):
403 RunTest(qa_cluster.TestClusterDestroy)
406 if __name__ == '__main__':