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.
24 You can create the required known_hosts file using ssh-keyscan. It's mandatory
25 to use the full name of a node (FQDN). For security reasons, verify the keys
27 Example: ssh-keyscan -t rsa node{1,2,3,4}.example.com > known_hosts
46 def RunTest(fn, *args):
47 """Runs a test after printing a header.
51 desc = fn.__doc__.splitlines()[0].strip()
55 now = str(datetime.datetime.now())
58 print '---', now, ('-' * (55 - len(now)))
66 """Run several environment tests.
69 if not qa_config.TestEnabled('env'):
72 RunTest(qa_env.TestSshConnection)
73 RunTest(qa_env.TestIcmpPing)
74 RunTest(qa_env.TestGanetiCommands)
78 """Initializes the cluster.
81 RunTest(qa_cluster.TestClusterInit)
82 RunTest(qa_node.TestNodeAddAll)
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)
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)
164 def RunExportImportTests(instance, pnode):
165 """Tries to export and import the instance.
168 if qa_config.TestEnabled('instance-export'):
169 expnode = qa_config.AcquireNode(exclude=pnode)
171 name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
173 RunTest(qa_instance.TestBackupList, expnode)
175 if qa_config.TestEnabled('instance-import'):
176 newinst = qa_config.AcquireInstance()
178 RunTest(qa_instance.TestInstanceImport, pnode, newinst,
180 RunTest(qa_instance.TestInstanceRemove, newinst)
182 qa_config.ReleaseInstance(newinst)
184 qa_config.ReleaseNode(expnode)
187 def RunDaemonTests(instance, pnode):
188 """Test the ganeti-watcher script.
191 automatic_restart = \
192 qa_config.TestEnabled('instance-automatic-restart')
193 consecutive_failures = \
194 qa_config.TestEnabled('instance-consecutive-failures')
196 if automatic_restart or consecutive_failures:
197 qa_daemon.PrintCronWarning()
199 if automatic_restart:
200 RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance)
202 if consecutive_failures:
203 RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance)
206 def RunHardwareFailureTests(instance, pnode, snode):
207 """Test cluster internal hardware failure recovery.
210 if qa_config.TestEnabled('instance-failover'):
211 RunTest(qa_instance.TestInstanceFailover, instance)
213 if qa_config.TestEnabled('instance-replace-disks'):
214 othernode = qa_config.AcquireNode(exclude=pnode)
216 RunTest(qa_instance.TestReplaceDisks,
217 instance, pnode, snode, othernode)
219 qa_config.ReleaseNode(othernode)
221 if qa_config.TestEnabled('node-evacuate'):
222 RunTest(qa_node.TestNodeEvacuate, pnode, snode)
224 if qa_config.TestEnabled('node-failover'):
225 RunTest(qa_node.TestNodeFailover, pnode, snode)
227 if qa_config.TestEnabled('instance-disk-failure'):
228 RunTest(qa_instance.TestInstanceMasterDiskFailure,
229 instance, pnode, snode)
230 RunTest(qa_instance.TestInstanceSecondaryDiskFailure,
231 instance, pnode, snode)
238 parser = optparse.OptionParser(usage="%prog [options] <config-file>"
239 " <known-hosts-file>")
240 parser.add_option('--dry-run', dest='dry_run',
242 help="Show what would be done")
243 parser.add_option('--yes-do-it', dest='yes_do_it',
245 help="Really execute the tests")
246 (qa_config.options, args) = parser.parse_args()
249 (config_file, known_hosts_file) = args
251 parser.error("Not enough arguments.")
253 if not qa_config.options.yes_do_it:
254 print ("Executing this script irreversibly destroys any Ganeti\n"
255 "configuration on all nodes involved. If you really want\n"
256 "to start testing, supply the --yes-do-it option.")
259 qa_config.Load(config_file)
262 RunTest(qa_other.UploadKnownHostsFile, known_hosts_file)
269 if qa_config.TestEnabled('tags'):
270 RunTest(qa_tags.TestClusterTags)
272 if qa_config.TestEnabled('node-readd'):
273 master = qa_config.GetMasterNode()
274 pnode = qa_config.AcquireNode(exclude=master)
276 RunTest(qa_node.TestNodeReadd, pnode)
278 qa_config.ReleaseNode(pnode)
280 pnode = qa_config.AcquireNode()
282 if qa_config.TestEnabled('tags'):
283 RunTest(qa_tags.TestNodeTags, pnode)
285 if qa_config.TestEnabled('instance-add-plain-disk'):
286 instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode)
287 RunCommonInstanceTests(instance)
288 RunExportImportTests(instance, pnode)
289 RunDaemonTests(instance, pnode)
290 RunTest(qa_instance.TestInstanceRemove, instance)
294 ('instance-add-drbd-disk',
295 qa_instance.TestInstanceAddWithDrbdDisk),
298 for name, func in multinode_tests:
299 if qa_config.TestEnabled(name):
300 snode = qa_config.AcquireNode(exclude=pnode)
302 instance = RunTest(func, pnode, snode)
303 RunCommonInstanceTests(instance)
304 RunExportImportTests(instance, pnode)
305 RunHardwareFailureTests(instance, pnode, snode)
306 RunTest(qa_instance.TestInstanceRemove, instance)
309 qa_config.ReleaseNode(snode)
312 qa_config.ReleaseNode(pnode)
314 RunTest(qa_node.TestNodeRemoveAll)
316 if qa_config.TestEnabled('cluster-destroy'):
317 RunTest(qa_cluster.TestClusterDestroy)
320 if __name__ == '__main__':