root / qa / ganeti-qa.py @ 3fc175f0
History | View | Annotate | Download (8.6 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 |
|
42 |
def RunTest(fn, *args): |
43 |
"""Runs a test after printing a header.
|
44 |
|
45 |
"""
|
46 |
if fn.__doc__:
|
47 |
desc = fn.__doc__.splitlines()[0].strip()
|
48 |
else:
|
49 |
desc = '%r' % fn
|
50 |
|
51 |
now = str(datetime.datetime.now())
|
52 |
|
53 |
print
|
54 |
print '---', now, ('-' * (55 - len(now))) |
55 |
print desc
|
56 |
print '-' * 60 |
57 |
|
58 |
return fn(*args)
|
59 |
|
60 |
|
61 |
def RunEnvTests(): |
62 |
"""Run several environment tests.
|
63 |
|
64 |
"""
|
65 |
if not qa_config.TestEnabled('env'): |
66 |
return
|
67 |
|
68 |
RunTest(qa_env.TestSshConnection) |
69 |
RunTest(qa_env.TestIcmpPing) |
70 |
RunTest(qa_env.TestGanetiCommands) |
71 |
|
72 |
|
73 |
def SetupCluster(): |
74 |
"""Initializes the cluster.
|
75 |
|
76 |
"""
|
77 |
RunTest(qa_cluster.TestClusterInit) |
78 |
RunTest(qa_node.TestNodeAddAll) |
79 |
if qa_config.TestEnabled('node-info'): |
80 |
RunTest(qa_node.TestNodeInfo) |
81 |
|
82 |
|
83 |
def RunClusterTests(): |
84 |
"""Runs tests related to gnt-cluster.
|
85 |
|
86 |
"""
|
87 |
if qa_config.TestEnabled('cluster-verify'): |
88 |
RunTest(qa_cluster.TestClusterVerify) |
89 |
|
90 |
if qa_config.TestEnabled('cluster-rename'): |
91 |
RunTest(qa_cluster.TestClusterRename) |
92 |
|
93 |
if qa_config.TestEnabled('cluster-info'): |
94 |
RunTest(qa_cluster.TestClusterVersion) |
95 |
RunTest(qa_cluster.TestClusterInfo) |
96 |
RunTest(qa_cluster.TestClusterGetmaster) |
97 |
|
98 |
if qa_config.TestEnabled('cluster-copyfile'): |
99 |
RunTest(qa_cluster.TestClusterCopyfile) |
100 |
|
101 |
if qa_config.TestEnabled('cluster-command'): |
102 |
RunTest(qa_cluster.TestClusterCommand) |
103 |
|
104 |
if qa_config.TestEnabled('cluster-burnin'): |
105 |
RunTest(qa_cluster.TestClusterBurnin) |
106 |
|
107 |
if qa_config.TestEnabled('cluster-master-failover'): |
108 |
RunTest(qa_cluster.TestClusterMasterFailover) |
109 |
|
110 |
if qa_rapi.Enabled():
|
111 |
RunTest(qa_rapi.TestVersion) |
112 |
RunTest(qa_rapi.TestEmptyCluster) |
113 |
|
114 |
def RunOsTests(): |
115 |
"""Runs all tests related to gnt-os.
|
116 |
|
117 |
"""
|
118 |
if not qa_config.TestEnabled('os'): |
119 |
return
|
120 |
|
121 |
RunTest(qa_os.TestOsList) |
122 |
RunTest(qa_os.TestOsDiagnose) |
123 |
RunTest(qa_os.TestOsValid) |
124 |
RunTest(qa_os.TestOsInvalid) |
125 |
RunTest(qa_os.TestOsPartiallyValid) |
126 |
|
127 |
|
128 |
def RunCommonInstanceTests(instance): |
129 |
"""Runs a few tests that are common to all disk types.
|
130 |
|
131 |
"""
|
132 |
if qa_config.TestEnabled('instance-shutdown'): |
133 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
134 |
RunTest(qa_instance.TestInstanceStartup, instance) |
135 |
|
136 |
if qa_config.TestEnabled('instance-list'): |
137 |
RunTest(qa_instance.TestInstanceList) |
138 |
|
139 |
if qa_config.TestEnabled('instance-info'): |
140 |
RunTest(qa_instance.TestInstanceInfo, instance) |
141 |
|
142 |
if qa_config.TestEnabled('instance-modify'): |
143 |
RunTest(qa_instance.TestInstanceModify, instance) |
144 |
|
145 |
if qa_config.TestEnabled('instance-console'): |
146 |
RunTest(qa_instance.TestInstanceConsole, instance) |
147 |
|
148 |
if qa_config.TestEnabled('instance-reinstall'): |
149 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
150 |
RunTest(qa_instance.TestInstanceReinstall, instance) |
151 |
RunTest(qa_instance.TestInstanceStartup, instance) |
152 |
|
153 |
if qa_config.TestEnabled('instance-reboot'): |
154 |
RunTest(qa_instance.TestInstanceReboot, instance) |
155 |
|
156 |
if qa_config.TestEnabled('tags'): |
157 |
RunTest(qa_tags.TestInstanceTags, instance) |
158 |
|
159 |
if qa_config.TestEnabled('node-volumes'): |
160 |
RunTest(qa_node.TestNodeVolumes) |
161 |
|
162 |
if qa_rapi.Enabled():
|
163 |
RunTest(qa_rapi.TestInstance, instance) |
164 |
|
165 |
def RunExportImportTests(instance, pnode): |
166 |
"""Tries to export and import the instance.
|
167 |
|
168 |
"""
|
169 |
if qa_config.TestEnabled('instance-export'): |
170 |
expnode = qa_config.AcquireNode(exclude=pnode) |
171 |
try:
|
172 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
173 |
|
174 |
RunTest(qa_instance.TestBackupList, expnode) |
175 |
|
176 |
if qa_config.TestEnabled('instance-import'): |
177 |
newinst = qa_config.AcquireInstance() |
178 |
try:
|
179 |
RunTest(qa_instance.TestInstanceImport, pnode, newinst, |
180 |
expnode, name) |
181 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
182 |
finally:
|
183 |
qa_config.ReleaseInstance(newinst) |
184 |
finally:
|
185 |
qa_config.ReleaseNode(expnode) |
186 |
|
187 |
|
188 |
def RunDaemonTests(instance, pnode): |
189 |
"""Test the ganeti-watcher script.
|
190 |
|
191 |
"""
|
192 |
automatic_restart = \ |
193 |
qa_config.TestEnabled('instance-automatic-restart')
|
194 |
consecutive_failures = \ |
195 |
qa_config.TestEnabled('instance-consecutive-failures')
|
196 |
|
197 |
if automatic_restart or consecutive_failures: |
198 |
qa_daemon.PrintCronWarning() |
199 |
|
200 |
if automatic_restart:
|
201 |
RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance) |
202 |
|
203 |
if consecutive_failures:
|
204 |
RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance) |
205 |
|
206 |
|
207 |
def RunHardwareFailureTests(instance, pnode, snode): |
208 |
"""Test cluster internal hardware failure recovery.
|
209 |
|
210 |
"""
|
211 |
if qa_config.TestEnabled('instance-failover'): |
212 |
RunTest(qa_instance.TestInstanceFailover, instance) |
213 |
|
214 |
if qa_config.TestEnabled('instance-replace-disks'): |
215 |
othernode = qa_config.AcquireNode(exclude=[pnode, snode]) |
216 |
try:
|
217 |
RunTest(qa_instance.TestReplaceDisks, |
218 |
instance, pnode, snode, othernode) |
219 |
finally:
|
220 |
qa_config.ReleaseNode(othernode) |
221 |
|
222 |
if qa_config.TestEnabled('node-evacuate'): |
223 |
RunTest(qa_node.TestNodeEvacuate, pnode, snode) |
224 |
|
225 |
if qa_config.TestEnabled('node-failover'): |
226 |
RunTest(qa_node.TestNodeFailover, pnode, snode) |
227 |
|
228 |
if qa_config.TestEnabled('instance-disk-failure'): |
229 |
RunTest(qa_instance.TestInstanceMasterDiskFailure, |
230 |
instance, pnode, snode) |
231 |
RunTest(qa_instance.TestInstanceSecondaryDiskFailure, |
232 |
instance, pnode, snode) |
233 |
|
234 |
|
235 |
def main(): |
236 |
"""Main program.
|
237 |
|
238 |
"""
|
239 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>")
|
240 |
parser.add_option('--dry-run', dest='dry_run', |
241 |
action="store_true",
|
242 |
help="Show what would be done")
|
243 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
244 |
action="store_true",
|
245 |
help="Really execute the tests")
|
246 |
(qa_config.options, args) = parser.parse_args() |
247 |
|
248 |
if len(args) == 1: |
249 |
(config_file, ) = args |
250 |
else:
|
251 |
parser.error("Wrong number of arguments.")
|
252 |
|
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.")
|
257 |
sys.exit(1)
|
258 |
|
259 |
qa_config.Load(config_file) |
260 |
|
261 |
RunEnvTests() |
262 |
SetupCluster() |
263 |
RunClusterTests() |
264 |
RunOsTests() |
265 |
|
266 |
if qa_config.TestEnabled('tags'): |
267 |
RunTest(qa_tags.TestClusterTags) |
268 |
|
269 |
if qa_config.TestEnabled('node-readd'): |
270 |
master = qa_config.GetMasterNode() |
271 |
pnode = qa_config.AcquireNode(exclude=master) |
272 |
try:
|
273 |
RunTest(qa_node.TestNodeReadd, pnode) |
274 |
finally:
|
275 |
qa_config.ReleaseNode(pnode) |
276 |
|
277 |
pnode = qa_config.AcquireNode() |
278 |
try:
|
279 |
if qa_config.TestEnabled('tags'): |
280 |
RunTest(qa_tags.TestNodeTags, pnode) |
281 |
|
282 |
if qa_rapi.Enabled():
|
283 |
RunTest(qa_rapi.TestNode, pnode) |
284 |
|
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) |
291 |
del instance
|
292 |
|
293 |
multinode_tests = [ |
294 |
('instance-add-drbd-disk',
|
295 |
qa_instance.TestInstanceAddWithDrbdDisk), |
296 |
] |
297 |
|
298 |
for name, func in multinode_tests: |
299 |
if qa_config.TestEnabled(name):
|
300 |
snode = qa_config.AcquireNode(exclude=pnode) |
301 |
try:
|
302 |
instance = RunTest(func, pnode, snode) |
303 |
RunCommonInstanceTests(instance) |
304 |
RunExportImportTests(instance, pnode) |
305 |
RunHardwareFailureTests(instance, pnode, snode) |
306 |
RunTest(qa_instance.TestInstanceRemove, instance) |
307 |
del instance
|
308 |
finally:
|
309 |
qa_config.ReleaseNode(snode) |
310 |
|
311 |
finally:
|
312 |
qa_config.ReleaseNode(pnode) |
313 |
|
314 |
RunTest(qa_node.TestNodeRemoveAll) |
315 |
|
316 |
if qa_config.TestEnabled('cluster-destroy'): |
317 |
RunTest(qa_cluster.TestClusterDestroy) |
318 |
|
319 |
|
320 |
if __name__ == '__main__': |
321 |
main() |