root / qa / ganeti-qa.py @ 2a7c3583
History | View | Annotate | Download (10.8 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007 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 |
else:
|
89 |
# consider the nodes are already there
|
90 |
qa_node.MarkNodeAddedAll() |
91 |
if qa_config.TestEnabled('node-info'): |
92 |
RunTest(qa_node.TestNodeInfo) |
93 |
|
94 |
|
95 |
def RunClusterTests(): |
96 |
"""Runs tests related to gnt-cluster.
|
97 |
|
98 |
"""
|
99 |
if qa_config.TestEnabled("cluster-renew-crypto"): |
100 |
RunTest(qa_cluster.TestClusterRenewCrypto) |
101 |
|
102 |
if qa_config.TestEnabled('cluster-verify'): |
103 |
RunTest(qa_cluster.TestClusterVerify) |
104 |
|
105 |
if qa_config.TestEnabled('cluster-rename'): |
106 |
RunTest(qa_cluster.TestClusterRename) |
107 |
|
108 |
if qa_config.TestEnabled('cluster-info'): |
109 |
RunTest(qa_cluster.TestClusterVersion) |
110 |
RunTest(qa_cluster.TestClusterInfo) |
111 |
RunTest(qa_cluster.TestClusterGetmaster) |
112 |
|
113 |
if qa_config.TestEnabled('cluster-copyfile'): |
114 |
RunTest(qa_cluster.TestClusterCopyfile) |
115 |
|
116 |
if qa_config.TestEnabled('cluster-command'): |
117 |
RunTest(qa_cluster.TestClusterCommand) |
118 |
|
119 |
if qa_config.TestEnabled('cluster-burnin'): |
120 |
RunTest(qa_cluster.TestClusterBurnin) |
121 |
|
122 |
if qa_config.TestEnabled('cluster-master-failover'): |
123 |
RunTest(qa_cluster.TestClusterMasterFailover) |
124 |
|
125 |
if qa_rapi.Enabled():
|
126 |
RunTest(qa_rapi.TestVersion) |
127 |
RunTest(qa_rapi.TestEmptyCluster) |
128 |
|
129 |
|
130 |
def RunOsTests(): |
131 |
"""Runs all tests related to gnt-os.
|
132 |
|
133 |
"""
|
134 |
if not qa_config.TestEnabled('os'): |
135 |
return
|
136 |
|
137 |
RunTest(qa_os.TestOsList) |
138 |
RunTest(qa_os.TestOsDiagnose) |
139 |
RunTest(qa_os.TestOsValid) |
140 |
RunTest(qa_os.TestOsInvalid) |
141 |
RunTest(qa_os.TestOsPartiallyValid) |
142 |
RunTest(qa_os.TestOsModifyValid) |
143 |
RunTest(qa_os.TestOsModifyInvalid) |
144 |
|
145 |
|
146 |
def RunCommonInstanceTests(instance): |
147 |
"""Runs a few tests that are common to all disk types.
|
148 |
|
149 |
"""
|
150 |
if qa_config.TestEnabled('instance-shutdown'): |
151 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
152 |
RunTest(qa_instance.TestInstanceStartup, instance) |
153 |
|
154 |
if qa_config.TestEnabled('instance-list'): |
155 |
RunTest(qa_instance.TestInstanceList) |
156 |
|
157 |
if qa_config.TestEnabled('instance-info'): |
158 |
RunTest(qa_instance.TestInstanceInfo, instance) |
159 |
|
160 |
if qa_config.TestEnabled('instance-modify'): |
161 |
RunTest(qa_instance.TestInstanceModify, instance) |
162 |
|
163 |
if qa_config.TestEnabled('instance-console'): |
164 |
RunTest(qa_instance.TestInstanceConsole, instance) |
165 |
|
166 |
if qa_config.TestEnabled('instance-reinstall'): |
167 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
168 |
RunTest(qa_instance.TestInstanceReinstall, instance) |
169 |
RunTest(qa_instance.TestInstanceStartup, instance) |
170 |
|
171 |
if qa_config.TestEnabled('instance-reboot'): |
172 |
RunTest(qa_instance.TestInstanceReboot, instance) |
173 |
|
174 |
if qa_config.TestEnabled('instance-rename'): |
175 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
176 |
RunTest(qa_instance.TestInstanceRename, instance) |
177 |
RunTest(qa_instance.TestInstanceStartup, instance) |
178 |
|
179 |
if qa_config.TestEnabled('tags'): |
180 |
RunTest(qa_tags.TestInstanceTags, instance) |
181 |
|
182 |
if qa_config.TestEnabled('node-volumes'): |
183 |
RunTest(qa_node.TestNodeVolumes) |
184 |
|
185 |
if qa_config.TestEnabled("node-storage"): |
186 |
RunTest(qa_node.TestNodeStorage) |
187 |
|
188 |
if qa_rapi.Enabled():
|
189 |
RunTest(qa_rapi.TestInstance, instance) |
190 |
|
191 |
|
192 |
def RunExportImportTests(instance, pnode): |
193 |
"""Tries to export and import the instance.
|
194 |
|
195 |
"""
|
196 |
if qa_config.TestEnabled('instance-export'): |
197 |
expnode = qa_config.AcquireNode(exclude=pnode) |
198 |
try:
|
199 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
200 |
|
201 |
RunTest(qa_instance.TestBackupList, expnode) |
202 |
|
203 |
if qa_config.TestEnabled('instance-import'): |
204 |
newinst = qa_config.AcquireInstance() |
205 |
try:
|
206 |
RunTest(qa_instance.TestInstanceImport, pnode, newinst, |
207 |
expnode, name) |
208 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
209 |
finally:
|
210 |
qa_config.ReleaseInstance(newinst) |
211 |
finally:
|
212 |
qa_config.ReleaseNode(expnode) |
213 |
|
214 |
if (qa_rapi.Enabled() and |
215 |
qa_config.TestEnabled("inter-cluster-instance-move")):
|
216 |
newinst = qa_config.AcquireInstance() |
217 |
try:
|
218 |
pnode2 = qa_config.AcquireNode(exclude=pnode) |
219 |
try:
|
220 |
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst, |
221 |
pnode2, pnode) |
222 |
finally:
|
223 |
qa_config.ReleaseNode(pnode2) |
224 |
finally:
|
225 |
qa_config.ReleaseInstance(newinst) |
226 |
|
227 |
|
228 |
def RunDaemonTests(instance, pnode): |
229 |
"""Test the ganeti-watcher script.
|
230 |
|
231 |
"""
|
232 |
automatic_restart = \ |
233 |
qa_config.TestEnabled('instance-automatic-restart')
|
234 |
consecutive_failures = \ |
235 |
qa_config.TestEnabled('instance-consecutive-failures')
|
236 |
|
237 |
if automatic_restart or consecutive_failures: |
238 |
qa_daemon.PrintCronWarning() |
239 |
|
240 |
if automatic_restart:
|
241 |
RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance) |
242 |
|
243 |
if consecutive_failures:
|
244 |
RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance) |
245 |
|
246 |
|
247 |
def RunHardwareFailureTests(instance, pnode, snode): |
248 |
"""Test cluster internal hardware failure recovery.
|
249 |
|
250 |
"""
|
251 |
if qa_config.TestEnabled('instance-failover'): |
252 |
RunTest(qa_instance.TestInstanceFailover, instance) |
253 |
|
254 |
if qa_config.TestEnabled('instance-replace-disks'): |
255 |
othernode = qa_config.AcquireNode(exclude=[pnode, snode]) |
256 |
try:
|
257 |
RunTest(qa_instance.TestReplaceDisks, |
258 |
instance, pnode, snode, othernode) |
259 |
finally:
|
260 |
qa_config.ReleaseNode(othernode) |
261 |
|
262 |
if qa_config.TestEnabled('node-evacuate'): |
263 |
RunTest(qa_node.TestNodeEvacuate, pnode, snode) |
264 |
|
265 |
if qa_config.TestEnabled('node-failover'): |
266 |
RunTest(qa_node.TestNodeFailover, pnode, snode) |
267 |
|
268 |
if qa_config.TestEnabled('instance-disk-failure'): |
269 |
RunTest(qa_instance.TestInstanceMasterDiskFailure, |
270 |
instance, pnode, snode) |
271 |
RunTest(qa_instance.TestInstanceSecondaryDiskFailure, |
272 |
instance, pnode, snode) |
273 |
|
274 |
|
275 |
@rapi.client.UsesRapiClient
|
276 |
def main(): |
277 |
"""Main program.
|
278 |
|
279 |
"""
|
280 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>")
|
281 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
282 |
action="store_true",
|
283 |
help="Really execute the tests")
|
284 |
(qa_config.options, args) = parser.parse_args() |
285 |
|
286 |
if len(args) == 1: |
287 |
(config_file, ) = args |
288 |
else:
|
289 |
parser.error("Wrong number of arguments.")
|
290 |
|
291 |
if not qa_config.options.yes_do_it: |
292 |
print ("Executing this script irreversibly destroys any Ganeti\n" |
293 |
"configuration on all nodes involved. If you really want\n"
|
294 |
"to start testing, supply the --yes-do-it option.")
|
295 |
sys.exit(1)
|
296 |
|
297 |
qa_config.Load(config_file) |
298 |
|
299 |
rapi_user = "ganeti-qa"
|
300 |
rapi_secret = utils.GenerateSecret() |
301 |
|
302 |
RunEnvTests() |
303 |
SetupCluster(rapi_user, rapi_secret) |
304 |
|
305 |
# Load RAPI certificate
|
306 |
qa_rapi.Setup(rapi_user, rapi_secret) |
307 |
|
308 |
RunClusterTests() |
309 |
RunOsTests() |
310 |
|
311 |
if qa_config.TestEnabled('tags'): |
312 |
RunTest(qa_tags.TestClusterTags) |
313 |
|
314 |
if qa_config.TestEnabled('node-readd'): |
315 |
master = qa_config.GetMasterNode() |
316 |
pnode = qa_config.AcquireNode(exclude=master) |
317 |
try:
|
318 |
RunTest(qa_node.TestNodeReadd, pnode) |
319 |
finally:
|
320 |
qa_config.ReleaseNode(pnode) |
321 |
|
322 |
pnode = qa_config.AcquireNode() |
323 |
try:
|
324 |
if qa_config.TestEnabled('tags'): |
325 |
RunTest(qa_tags.TestNodeTags, pnode) |
326 |
|
327 |
if qa_rapi.Enabled():
|
328 |
RunTest(qa_rapi.TestNode, pnode) |
329 |
|
330 |
if qa_config.TestEnabled("instance-add-plain-disk"): |
331 |
for use_client in [True, False]: |
332 |
rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode, |
333 |
use_client) |
334 |
RunCommonInstanceTests(rapi_instance) |
335 |
RunTest(qa_rapi.TestRapiInstanceRemove, rapi_instance, use_client) |
336 |
del rapi_instance
|
337 |
|
338 |
if qa_config.TestEnabled('instance-add-plain-disk'): |
339 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
340 |
RunCommonInstanceTests(instance) |
341 |
RunExportImportTests(instance, pnode) |
342 |
RunDaemonTests(instance, pnode) |
343 |
RunTest(qa_instance.TestInstanceRemove, instance) |
344 |
del instance
|
345 |
|
346 |
multinode_tests = [ |
347 |
('instance-add-drbd-disk',
|
348 |
qa_instance.TestInstanceAddWithDrbdDisk), |
349 |
] |
350 |
|
351 |
for name, func in multinode_tests: |
352 |
if qa_config.TestEnabled(name):
|
353 |
snode = qa_config.AcquireNode(exclude=pnode) |
354 |
try:
|
355 |
instance = RunTest(func, pnode, snode) |
356 |
RunCommonInstanceTests(instance) |
357 |
if qa_config.TestEnabled('instance-convert-disk'): |
358 |
RunTest(qa_instance.TestInstanceConvertDisk, instance, snode) |
359 |
RunExportImportTests(instance, pnode) |
360 |
RunHardwareFailureTests(instance, pnode, snode) |
361 |
RunTest(qa_instance.TestInstanceRemove, instance) |
362 |
del instance
|
363 |
finally:
|
364 |
qa_config.ReleaseNode(snode) |
365 |
|
366 |
if (qa_config.TestEnabled('instance-add-plain-disk') and |
367 |
qa_config.TestEnabled("instance-export")):
|
368 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
369 |
expnode = qa_config.AcquireNode(exclude=pnode) |
370 |
try:
|
371 |
RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode) |
372 |
RunTest(qa_instance.TestBackupList, expnode) |
373 |
finally:
|
374 |
qa_config.ReleaseNode(expnode) |
375 |
del expnode
|
376 |
del instance
|
377 |
|
378 |
finally:
|
379 |
qa_config.ReleaseNode(pnode) |
380 |
|
381 |
if qa_config.TestEnabled('create-cluster'): |
382 |
RunTest(qa_node.TestNodeRemoveAll) |
383 |
|
384 |
if qa_config.TestEnabled('cluster-destroy'): |
385 |
RunTest(qa_cluster.TestClusterDestroy) |
386 |
|
387 |
|
388 |
if __name__ == '__main__': |
389 |
main() |