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.
42 def RunTest(fn, *args):
43 """Runs a test after printing a header.
47 desc = fn.__doc__.splitlines()[0].strip()
51 now = str(datetime.datetime.now())
54 print '---', now, ('-' * (55 - len(now)))
62 """Run several environment tests.
65 if not qa_config.TestEnabled('env'):
68 RunTest(qa_env.TestSshConnection)
69 RunTest(qa_env.TestIcmpPing)
70 RunTest(qa_env.TestGanetiCommands)
74 """Initializes the cluster.
77 if qa_config.TestEnabled('create-cluster'):
78 RunTest(qa_cluster.TestClusterInit)
79 RunTest(qa_node.TestNodeAddAll)
81 # consider the nodes are already there
82 qa_node.MarkNodeAddedAll()
83 if qa_config.TestEnabled('node-info'):
84 RunTest(qa_node.TestNodeInfo)
87 def RunClusterTests():
88 """Runs tests related to gnt-cluster.
91 if qa_config.TestEnabled('cluster-verify'):
92 RunTest(qa_cluster.TestClusterVerify)
94 if qa_config.TestEnabled('cluster-rename'):
95 RunTest(qa_cluster.TestClusterRename)
97 if qa_config.TestEnabled('cluster-info'):
98 RunTest(qa_cluster.TestClusterVersion)
99 RunTest(qa_cluster.TestClusterInfo)
100 RunTest(qa_cluster.TestClusterGetmaster)
102 if qa_config.TestEnabled('cluster-copyfile'):
103 RunTest(qa_cluster.TestClusterCopyfile)
105 if qa_config.TestEnabled('cluster-command'):
106 RunTest(qa_cluster.TestClusterCommand)
108 if qa_config.TestEnabled('cluster-burnin'):
109 RunTest(qa_cluster.TestClusterBurnin)
111 if qa_config.TestEnabled('cluster-master-failover'):
112 RunTest(qa_cluster.TestClusterMasterFailover)
114 if qa_rapi.Enabled():
115 RunTest(qa_rapi.TestVersion)
116 RunTest(qa_rapi.TestEmptyCluster)
119 """Runs all tests related to gnt-os.
122 if not qa_config.TestEnabled('os'):
125 RunTest(qa_os.TestOsList)
126 RunTest(qa_os.TestOsDiagnose)
127 RunTest(qa_os.TestOsValid)
128 RunTest(qa_os.TestOsInvalid)
129 RunTest(qa_os.TestOsPartiallyValid)
130 RunTest(qa_os.TestOsModifyValid)
131 RunTest(qa_os.TestOsModifyInvalid)
134 def RunCommonInstanceTests(instance):
135 """Runs a few tests that are common to all disk types.
138 if qa_config.TestEnabled('instance-shutdown'):
139 RunTest(qa_instance.TestInstanceShutdown, instance)
140 RunTest(qa_instance.TestInstanceStartup, instance)
142 if qa_config.TestEnabled('instance-list'):
143 RunTest(qa_instance.TestInstanceList)
145 if qa_config.TestEnabled('instance-info'):
146 RunTest(qa_instance.TestInstanceInfo, instance)
148 if qa_config.TestEnabled('instance-modify'):
149 RunTest(qa_instance.TestInstanceModify, instance)
151 if qa_config.TestEnabled('instance-console'):
152 RunTest(qa_instance.TestInstanceConsole, instance)
154 if qa_config.TestEnabled('instance-reinstall'):
155 RunTest(qa_instance.TestInstanceShutdown, instance)
156 RunTest(qa_instance.TestInstanceReinstall, instance)
157 RunTest(qa_instance.TestInstanceStartup, instance)
159 if qa_config.TestEnabled('instance-reboot'):
160 RunTest(qa_instance.TestInstanceReboot, instance)
162 if qa_config.TestEnabled('instance-rename'):
163 RunTest(qa_instance.TestInstanceShutdown, instance)
164 RunTest(qa_instance.TestInstanceRename, instance)
165 RunTest(qa_instance.TestInstanceStartup, instance)
167 if qa_config.TestEnabled('tags'):
168 RunTest(qa_tags.TestInstanceTags, instance)
170 if qa_config.TestEnabled('node-volumes'):
171 RunTest(qa_node.TestNodeVolumes)
173 if qa_config.TestEnabled("node-storage"):
174 RunTest(qa_node.TestNodeStorage)
176 if qa_rapi.Enabled():
177 RunTest(qa_rapi.TestInstance, instance)
179 def RunExportImportTests(instance, pnode):
180 """Tries to export and import the instance.
183 if qa_config.TestEnabled('instance-export'):
184 expnode = qa_config.AcquireNode(exclude=pnode)
186 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
188 RunTest(qa_instance.TestBackupList, expnode)
190 if qa_config.TestEnabled('instance-import'):
191 newinst = qa_config.AcquireInstance()
193 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
195 RunTest(qa_instance.TestInstanceRemove, newinst)
197 qa_config.ReleaseInstance(newinst)
199 qa_config.ReleaseNode(expnode)
202 def RunDaemonTests(instance, pnode):
203 """Test the ganeti-watcher script.
206 automatic_restart = \
207 qa_config.TestEnabled('instance-automatic-restart')
208 consecutive_failures = \
209 qa_config.TestEnabled('instance-consecutive-failures')
211 if automatic_restart or consecutive_failures:
212 qa_daemon.PrintCronWarning()
214 if automatic_restart:
215 RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
217 if consecutive_failures:
218 RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
221 def RunHardwareFailureTests(instance, pnode, snode):
222 """Test cluster internal hardware failure recovery.
225 if qa_config.TestEnabled('instance-failover'):
226 RunTest(qa_instance.TestInstanceFailover, instance)
228 if qa_config.TestEnabled('instance-replace-disks'):
229 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
231 RunTest(qa_instance.TestReplaceDisks,
232 instance, pnode, snode, othernode)
234 qa_config.ReleaseNode(othernode)
236 if qa_config.TestEnabled('node-evacuate'):
237 RunTest(qa_node.TestNodeEvacuate, pnode, snode)
239 if qa_config.TestEnabled('node-failover'):
240 RunTest(qa_node.TestNodeFailover, pnode, snode)
242 if qa_config.TestEnabled('instance-disk-failure'):
243 RunTest(qa_instance.TestInstanceMasterDiskFailure,
244 instance, pnode, snode)
245 RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
246 instance, pnode, snode)
253 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
254 parser.add_option('--yes-do-it', dest='yes_do_it',
256 help="Really execute the tests")
257 (qa_config.options, args) = parser.parse_args()
260 (config_file, ) = args
262 parser.error("Wrong number of arguments.")
264 if not qa_config.options.yes_do_it:
265 print ("Executing this script irreversibly destroys any Ganeti\n"
266 "configuration on all nodes involved. If you really want\n"
267 "to start testing, supply the --yes-do-it option.")
270 qa_config.Load(config_file)
277 if qa_config.TestEnabled('tags'):
278 RunTest(qa_tags.TestClusterTags)
280 if qa_config.TestEnabled('node-readd'):
281 master = qa_config.GetMasterNode()
282 pnode = qa_config.AcquireNode(exclude=master)
284 RunTest(qa_node.TestNodeReadd, pnode)
286 qa_config.ReleaseNode(pnode)
288 pnode = qa_config.AcquireNode()
290 if qa_config.TestEnabled('tags'):
291 RunTest(qa_tags.TestNodeTags, pnode)
293 if qa_rapi.Enabled():
294 RunTest(qa_rapi.TestNode, pnode)
296 if qa_config.TestEnabled('instance-add-plain-disk'):
297 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
298 RunCommonInstanceTests(instance)
299 RunExportImportTests(instance, pnode)
300 RunDaemonTests(instance, pnode)
301 RunTest(qa_instance.TestInstanceRemove, instance)
305 ('instance-add-drbd-disk',
306 qa_instance.TestInstanceAddWithDrbdDisk),
309 for name, func in multinode_tests:
310 if qa_config.TestEnabled(name):
311 snode = qa_config.AcquireNode(exclude=pnode)
313 instance = RunTest(func, pnode, snode)
314 RunCommonInstanceTests(instance)
315 RunExportImportTests(instance, pnode)
316 RunHardwareFailureTests(instance, pnode, snode)
317 RunTest(qa_instance.TestInstanceRemove, instance)
320 qa_config.ReleaseNode(snode)
323 qa_config.ReleaseNode(pnode)
325 if qa_config.TestEnabled('create-cluster'):
326 RunTest(qa_node.TestNodeRemoveAll)
328 if qa_config.TestEnabled('cluster-destroy'):
329 RunTest(qa_cluster.TestClusterDestroy)
332 if __name__ == '__main__':