root / qa / ganeti-qa.py @ e1df06f2
History | View | Annotate | Download (11.8 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007, 2008, 2009, 2010 Google Inc.
|
5 |
#
|
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.
|
10 |
#
|
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.
|
15 |
#
|
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
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""Script for doing QA on Ganeti.
|
23 |
|
24 |
"""
|
25 |
|
26 |
import sys |
27 |
import datetime |
28 |
import optparse |
29 |
|
30 |
import qa_cluster |
31 |
import qa_config |
32 |
import qa_daemon |
33 |
import qa_env |
34 |
import qa_instance |
35 |
import qa_node |
36 |
import qa_os |
37 |
import qa_rapi |
38 |
import qa_tags |
39 |
import qa_utils |
40 |
|
41 |
from ganeti import utils |
42 |
from ganeti import rapi |
43 |
|
44 |
import ganeti.rapi.client |
45 |
|
46 |
|
47 |
def RunTest(fn, *args): |
48 |
"""Runs a test after printing a header.
|
49 |
|
50 |
"""
|
51 |
if fn.__doc__:
|
52 |
desc = fn.__doc__.splitlines()[0].strip()
|
53 |
else:
|
54 |
desc = '%r' % fn
|
55 |
|
56 |
now = str(datetime.datetime.now())
|
57 |
|
58 |
print
|
59 |
print '---', now, ('-' * (55 - len(now))) |
60 |
print desc
|
61 |
print '-' * 60 |
62 |
|
63 |
return fn(*args)
|
64 |
|
65 |
|
66 |
def RunEnvTests(): |
67 |
"""Run several environment tests.
|
68 |
|
69 |
"""
|
70 |
if not qa_config.TestEnabled('env'): |
71 |
return
|
72 |
|
73 |
RunTest(qa_env.TestSshConnection) |
74 |
RunTest(qa_env.TestIcmpPing) |
75 |
RunTest(qa_env.TestGanetiCommands) |
76 |
|
77 |
|
78 |
def SetupCluster(rapi_user, rapi_secret): |
79 |
"""Initializes the cluster.
|
80 |
|
81 |
@param rapi_user: Login user for RAPI
|
82 |
@param rapi_secret: Login secret for RAPI
|
83 |
|
84 |
"""
|
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) |
89 |
else:
|
90 |
# consider the nodes are already there
|
91 |
qa_node.MarkNodeAddedAll() |
92 |
if qa_config.TestEnabled('node-info'): |
93 |
RunTest(qa_node.TestNodeInfo) |
94 |
|
95 |
|
96 |
def RunClusterTests(): |
97 |
"""Runs tests related to gnt-cluster.
|
98 |
|
99 |
"""
|
100 |
if qa_config.TestEnabled("cluster-renew-crypto"): |
101 |
RunTest(qa_cluster.TestClusterRenewCrypto) |
102 |
|
103 |
if qa_config.TestEnabled('cluster-verify'): |
104 |
RunTest(qa_cluster.TestClusterVerify) |
105 |
|
106 |
if qa_config.TestEnabled('cluster-reserved-lvs'): |
107 |
RunTest(qa_cluster.TestClusterReservedLvs) |
108 |
|
109 |
if qa_config.TestEnabled('cluster-rename'): |
110 |
RunTest(qa_cluster.TestClusterRename) |
111 |
|
112 |
if qa_config.TestEnabled('cluster-info'): |
113 |
RunTest(qa_cluster.TestClusterVersion) |
114 |
RunTest(qa_cluster.TestClusterInfo) |
115 |
RunTest(qa_cluster.TestClusterGetmaster) |
116 |
|
117 |
if qa_config.TestEnabled('cluster-copyfile'): |
118 |
RunTest(qa_cluster.TestClusterCopyfile) |
119 |
|
120 |
if qa_config.TestEnabled('cluster-command'): |
121 |
RunTest(qa_cluster.TestClusterCommand) |
122 |
|
123 |
if qa_config.TestEnabled('cluster-burnin'): |
124 |
RunTest(qa_cluster.TestClusterBurnin) |
125 |
|
126 |
if qa_config.TestEnabled('cluster-master-failover'): |
127 |
RunTest(qa_cluster.TestClusterMasterFailover) |
128 |
|
129 |
if qa_rapi.Enabled():
|
130 |
RunTest(qa_rapi.TestVersion) |
131 |
RunTest(qa_rapi.TestEmptyCluster) |
132 |
|
133 |
|
134 |
def RunOsTests(): |
135 |
"""Runs all tests related to gnt-os.
|
136 |
|
137 |
"""
|
138 |
if not qa_config.TestEnabled('os'): |
139 |
return
|
140 |
|
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) |
149 |
|
150 |
|
151 |
def RunCommonInstanceTests(instance): |
152 |
"""Runs a few tests that are common to all disk types.
|
153 |
|
154 |
"""
|
155 |
if qa_config.TestEnabled('instance-shutdown'): |
156 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
157 |
RunTest(qa_instance.TestInstanceStartup, instance) |
158 |
|
159 |
if qa_config.TestEnabled('instance-list'): |
160 |
RunTest(qa_instance.TestInstanceList) |
161 |
|
162 |
if qa_config.TestEnabled('instance-info'): |
163 |
RunTest(qa_instance.TestInstanceInfo, instance) |
164 |
|
165 |
if qa_config.TestEnabled('instance-modify'): |
166 |
RunTest(qa_instance.TestInstanceModify, instance) |
167 |
if qa_rapi.Enabled():
|
168 |
RunTest(qa_rapi.TestRapiInstanceModify, instance) |
169 |
|
170 |
if qa_config.TestEnabled('instance-console'): |
171 |
RunTest(qa_instance.TestInstanceConsole, instance) |
172 |
|
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) |
177 |
|
178 |
if qa_config.TestEnabled('instance-reboot'): |
179 |
RunTest(qa_instance.TestInstanceReboot, instance) |
180 |
|
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")
|
186 |
else:
|
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) |
192 |
|
193 |
if qa_config.TestEnabled('tags'): |
194 |
RunTest(qa_tags.TestInstanceTags, instance) |
195 |
|
196 |
if qa_config.TestEnabled('node-volumes'): |
197 |
RunTest(qa_node.TestNodeVolumes) |
198 |
|
199 |
if qa_config.TestEnabled("node-storage"): |
200 |
RunTest(qa_node.TestNodeStorage) |
201 |
|
202 |
if qa_rapi.Enabled():
|
203 |
RunTest(qa_rapi.TestInstance, instance) |
204 |
|
205 |
|
206 |
def RunExportImportTests(instance, pnode): |
207 |
"""Tries to export and import the instance.
|
208 |
|
209 |
"""
|
210 |
if qa_config.TestEnabled('instance-export'): |
211 |
RunTest(qa_instance.TestInstanceExportNoTarget, instance) |
212 |
|
213 |
expnode = qa_config.AcquireNode(exclude=pnode) |
214 |
try:
|
215 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
216 |
|
217 |
RunTest(qa_instance.TestBackupList, expnode) |
218 |
|
219 |
if qa_config.TestEnabled('instance-import'): |
220 |
newinst = qa_config.AcquireInstance() |
221 |
try:
|
222 |
RunTest(qa_instance.TestInstanceImport, pnode, newinst, |
223 |
expnode, name) |
224 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
225 |
finally:
|
226 |
qa_config.ReleaseInstance(newinst) |
227 |
finally:
|
228 |
qa_config.ReleaseNode(expnode) |
229 |
|
230 |
if (qa_rapi.Enabled() and |
231 |
qa_config.TestEnabled("inter-cluster-instance-move")):
|
232 |
newinst = qa_config.AcquireInstance() |
233 |
try:
|
234 |
pnode2 = qa_config.AcquireNode(exclude=pnode) |
235 |
try:
|
236 |
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst, |
237 |
pnode2, pnode) |
238 |
finally:
|
239 |
qa_config.ReleaseNode(pnode2) |
240 |
finally:
|
241 |
qa_config.ReleaseInstance(newinst) |
242 |
|
243 |
|
244 |
def RunDaemonTests(instance, pnode): |
245 |
"""Test the ganeti-watcher script.
|
246 |
|
247 |
"""
|
248 |
automatic_restart = \ |
249 |
qa_config.TestEnabled('instance-automatic-restart')
|
250 |
consecutive_failures = \ |
251 |
qa_config.TestEnabled('instance-consecutive-failures')
|
252 |
|
253 |
if automatic_restart or consecutive_failures: |
254 |
qa_daemon.PrintCronWarning() |
255 |
|
256 |
if automatic_restart:
|
257 |
RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance) |
258 |
|
259 |
if consecutive_failures:
|
260 |
RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance) |
261 |
|
262 |
|
263 |
def RunHardwareFailureTests(instance, pnode, snode): |
264 |
"""Test cluster internal hardware failure recovery.
|
265 |
|
266 |
"""
|
267 |
if qa_config.TestEnabled('instance-failover'): |
268 |
RunTest(qa_instance.TestInstanceFailover, instance) |
269 |
|
270 |
if qa_config.TestEnabled("instance-migrate"): |
271 |
RunTest(qa_instance.TestInstanceMigrate, instance) |
272 |
|
273 |
if qa_rapi.Enabled():
|
274 |
RunTest(qa_rapi.TestRapiInstanceMigrate, instance) |
275 |
|
276 |
if qa_config.TestEnabled('instance-replace-disks'): |
277 |
othernode = qa_config.AcquireNode(exclude=[pnode, snode]) |
278 |
try:
|
279 |
RunTest(qa_instance.TestReplaceDisks, |
280 |
instance, pnode, snode, othernode) |
281 |
finally:
|
282 |
qa_config.ReleaseNode(othernode) |
283 |
|
284 |
if qa_config.TestEnabled('node-evacuate'): |
285 |
RunTest(qa_node.TestNodeEvacuate, pnode, snode) |
286 |
|
287 |
if qa_config.TestEnabled('node-failover'): |
288 |
RunTest(qa_node.TestNodeFailover, pnode, snode) |
289 |
|
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) |
295 |
|
296 |
|
297 |
@rapi.client.UsesRapiClient
|
298 |
def main(): |
299 |
"""Main program.
|
300 |
|
301 |
"""
|
302 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>")
|
303 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
304 |
action="store_true",
|
305 |
help="Really execute the tests")
|
306 |
(qa_config.options, args) = parser.parse_args() |
307 |
|
308 |
if len(args) == 1: |
309 |
(config_file, ) = args |
310 |
else:
|
311 |
parser.error("Wrong number of arguments.")
|
312 |
|
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.")
|
317 |
sys.exit(1)
|
318 |
|
319 |
qa_config.Load(config_file) |
320 |
|
321 |
rapi_user = "ganeti-qa"
|
322 |
rapi_secret = utils.GenerateSecret() |
323 |
|
324 |
RunEnvTests() |
325 |
SetupCluster(rapi_user, rapi_secret) |
326 |
|
327 |
# Load RAPI certificate
|
328 |
qa_rapi.Setup(rapi_user, rapi_secret) |
329 |
|
330 |
RunClusterTests() |
331 |
RunOsTests() |
332 |
|
333 |
if qa_config.TestEnabled('tags'): |
334 |
RunTest(qa_tags.TestClusterTags) |
335 |
|
336 |
if qa_config.TestEnabled('node-readd'): |
337 |
master = qa_config.GetMasterNode() |
338 |
pnode = qa_config.AcquireNode(exclude=master) |
339 |
try:
|
340 |
RunTest(qa_node.TestNodeReadd, pnode) |
341 |
finally:
|
342 |
qa_config.ReleaseNode(pnode) |
343 |
|
344 |
pnode = qa_config.AcquireNode() |
345 |
try:
|
346 |
if qa_config.TestEnabled('tags'): |
347 |
RunTest(qa_tags.TestNodeTags, pnode) |
348 |
|
349 |
if qa_rapi.Enabled():
|
350 |
RunTest(qa_rapi.TestNode, pnode) |
351 |
|
352 |
if qa_config.TestEnabled("instance-add-plain-disk"): |
353 |
for use_client in [True, False]: |
354 |
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode, |
355 |
use_client) |
356 |
RunCommonInstanceTests(rapi_instance) |
357 |
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client) |
358 |
del rapi_instance
|
359 |
|
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) |
366 |
del instance
|
367 |
|
368 |
multinode_tests = [ |
369 |
('instance-add-drbd-disk',
|
370 |
qa_instance.TestInstanceAddWithDrbdDisk), |
371 |
] |
372 |
|
373 |
for name, func in multinode_tests: |
374 |
if qa_config.TestEnabled(name):
|
375 |
snode = qa_config.AcquireNode(exclude=pnode) |
376 |
try:
|
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) |
386 |
del instance
|
387 |
finally:
|
388 |
qa_config.ReleaseNode(snode) |
389 |
|
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) |
394 |
try:
|
395 |
RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode) |
396 |
RunTest(qa_instance.TestBackupList, expnode) |
397 |
finally:
|
398 |
qa_config.ReleaseNode(expnode) |
399 |
del expnode
|
400 |
del instance
|
401 |
|
402 |
finally:
|
403 |
qa_config.ReleaseNode(pnode) |
404 |
|
405 |
if qa_config.TestEnabled('create-cluster'): |
406 |
RunTest(qa_node.TestNodeRemoveAll) |
407 |
|
408 |
if qa_config.TestEnabled('cluster-destroy'): |
409 |
RunTest(qa_cluster.TestClusterDestroy) |
410 |
|
411 |
|
412 |
if __name__ == '__main__': |
413 |
main() |