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)
80 if qa_config.TestEnabled('node-info'):
81 RunTest(qa_node.TestNodeInfo)
84 def RunClusterTests():
85 """Runs tests related to gnt-cluster.
88 if qa_config.TestEnabled('cluster-verify'):
89 RunTest(qa_cluster.TestClusterVerify)
91 if qa_config.TestEnabled('cluster-rename'):
92 RunTest(qa_cluster.TestClusterRename)
94 if qa_config.TestEnabled('cluster-info'):
95 RunTest(qa_cluster.TestClusterVersion)
96 RunTest(qa_cluster.TestClusterInfo)
97 RunTest(qa_cluster.TestClusterGetmaster)
99 if qa_config.TestEnabled('cluster-copyfile'):
100 RunTest(qa_cluster.TestClusterCopyfile)
102 if qa_config.TestEnabled('cluster-command'):
103 RunTest(qa_cluster.TestClusterCommand)
105 if qa_config.TestEnabled('cluster-burnin'):
106 RunTest(qa_cluster.TestClusterBurnin)
108 if qa_config.TestEnabled('cluster-master-failover'):
109 RunTest(qa_cluster.TestClusterMasterFailover)
111 if qa_rapi.Enabled():
112 RunTest(qa_rapi.TestVersion)
113 RunTest(qa_rapi.TestEmptyCluster)
116 """Runs all tests related to gnt-os.
119 if not qa_config.TestEnabled('os'):
122 RunTest(qa_os.TestOsList)
123 RunTest(qa_os.TestOsDiagnose)
124 RunTest(qa_os.TestOsValid)
125 RunTest(qa_os.TestOsInvalid)
126 RunTest(qa_os.TestOsPartiallyValid)
129 def RunCommonInstanceTests(instance):
130 """Runs a few tests that are common to all disk types.
133 if qa_config.TestEnabled('instance-shutdown'):
134 RunTest(qa_instance.TestInstanceShutdown, instance)
135 RunTest(qa_instance.TestInstanceStartup, instance)
137 if qa_config.TestEnabled('instance-list'):
138 RunTest(qa_instance.TestInstanceList)
140 if qa_config.TestEnabled('instance-info'):
141 RunTest(qa_instance.TestInstanceInfo, instance)
143 if qa_config.TestEnabled('instance-modify'):
144 RunTest(qa_instance.TestInstanceModify, instance)
146 if qa_config.TestEnabled('instance-console'):
147 RunTest(qa_instance.TestInstanceConsole, instance)
149 if qa_config.TestEnabled('instance-reinstall'):
150 RunTest(qa_instance.TestInstanceShutdown, instance)
151 RunTest(qa_instance.TestInstanceReinstall, instance)
152 RunTest(qa_instance.TestInstanceStartup, instance)
154 if qa_config.TestEnabled('instance-reboot'):
155 RunTest(qa_instance.TestInstanceReboot, instance)
157 if qa_config.TestEnabled('tags'):
158 RunTest(qa_tags.TestInstanceTags, instance)
160 if qa_config.TestEnabled('node-volumes'):
161 RunTest(qa_node.TestNodeVolumes)
163 if qa_rapi.Enabled():
164 RunTest(qa_rapi.TestInstance, instance)
166 def RunExportImportTests(instance, pnode):
167 """Tries to export and import the instance.
170 if qa_config.TestEnabled('instance-export'):
171 expnode = qa_config.AcquireNode(exclude=pnode)
173 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
175 RunTest(qa_instance.TestBackupList, expnode)
177 if qa_config.TestEnabled('instance-import'):
178 newinst = qa_config.AcquireInstance()
180 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
182 RunTest(qa_instance.TestInstanceRemove, newinst)
184 qa_config.ReleaseInstance(newinst)
186 qa_config.ReleaseNode(expnode)
189 def RunDaemonTests(instance, pnode):
190 """Test the ganeti-watcher script.
193 automatic_restart = \
194 qa_config.TestEnabled('instance-automatic-restart')
195 consecutive_failures = \
196 qa_config.TestEnabled('instance-consecutive-failures')
198 if automatic_restart or consecutive_failures:
199 qa_daemon.PrintCronWarning()
201 if automatic_restart:
202 RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
204 if consecutive_failures:
205 RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
208 def RunHardwareFailureTests(instance, pnode, snode):
209 """Test cluster internal hardware failure recovery.
212 if qa_config.TestEnabled('instance-failover'):
213 RunTest(qa_instance.TestInstanceFailover, instance)
215 if qa_config.TestEnabled('instance-replace-disks'):
216 othernode = qa_config.AcquireNode(exclude=[pnode, snode])
218 RunTest(qa_instance.TestReplaceDisks,
219 instance, pnode, snode, othernode)
221 qa_config.ReleaseNode(othernode)
223 if qa_config.TestEnabled('node-evacuate'):
224 RunTest(qa_node.TestNodeEvacuate, pnode, snode)
226 if qa_config.TestEnabled('node-failover'):
227 RunTest(qa_node.TestNodeFailover, pnode, snode)
229 if qa_config.TestEnabled('instance-disk-failure'):
230 RunTest(qa_instance.TestInstanceMasterDiskFailure,
231 instance, pnode, snode)
232 RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
233 instance, pnode, snode)
240 parser = optparse.OptionParser(usage="%prog [options] <config-file>")
241 parser.add_option('--yes-do-it', dest='yes_do_it',
243 help="Really execute the tests")
244 (qa_config.options, args) = parser.parse_args()
247 (config_file, ) = args
249 parser.error("Wrong number of arguments.")
251 if not qa_config.options.yes_do_it:
252 print ("Executing this script irreversibly destroys any Ganeti\n"
253 "configuration on all nodes involved. If you really want\n"
254 "to start testing, supply the --yes-do-it option.")
257 qa_config.Load(config_file)
264 if qa_config.TestEnabled('tags'):
265 RunTest(qa_tags.TestClusterTags)
267 if qa_config.TestEnabled('node-readd'):
268 master = qa_config.GetMasterNode()
269 pnode = qa_config.AcquireNode(exclude=master)
271 RunTest(qa_node.TestNodeReadd, pnode)
273 qa_config.ReleaseNode(pnode)
275 pnode = qa_config.AcquireNode()
277 if qa_config.TestEnabled('tags'):
278 RunTest(qa_tags.TestNodeTags, pnode)
280 if qa_rapi.Enabled():
281 RunTest(qa_rapi.TestNode, pnode)
283 if qa_config.TestEnabled('instance-add-plain-disk'):
284 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
285 RunCommonInstanceTests(instance)
286 RunExportImportTests(instance, pnode)
287 RunDaemonTests(instance, pnode)
288 RunTest(qa_instance.TestInstanceRemove, instance)
292 ('instance-add-drbd-disk',
293 qa_instance.TestInstanceAddWithDrbdDisk),
296 for name, func in multinode_tests:
297 if qa_config.TestEnabled(name):
298 snode = qa_config.AcquireNode(exclude=pnode)
300 instance = RunTest(func, pnode, snode)
301 RunCommonInstanceTests(instance)
302 RunExportImportTests(instance, pnode)
303 RunHardwareFailureTests(instance, pnode, snode)
304 RunTest(qa_instance.TestInstanceRemove, instance)
307 qa_config.ReleaseNode(snode)
310 qa_config.ReleaseNode(pnode)
312 if qa_config.TestEnabled('create-cluster'):
313 RunTest(qa_node.TestNodeRemoveAll)
315 if qa_config.TestEnabled('cluster-destroy'):
316 RunTest(qa_cluster.TestClusterDestroy)
319 if __name__ == '__main__':