root / qa / ganeti-qa.py @ ed54b47e
History | View | Annotate | Download (9 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 |
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
|
26 |
before using them.
|
27 |
Example: ssh-keyscan -t rsa node{1,2,3,4}.example.com > known_hosts
|
28 |
"""
|
29 |
|
30 |
import sys |
31 |
import datetime |
32 |
import optparse |
33 |
|
34 |
import qa_cluster |
35 |
import qa_config |
36 |
import qa_daemon |
37 |
import qa_env |
38 |
import qa_instance |
39 |
import qa_node |
40 |
import qa_os |
41 |
import qa_other |
42 |
import qa_rapi |
43 |
import qa_tags |
44 |
import qa_utils |
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(): |
79 |
"""Initializes the cluster.
|
80 |
|
81 |
"""
|
82 |
RunTest(qa_cluster.TestClusterInit) |
83 |
RunTest(qa_node.TestNodeAddAll) |
84 |
if qa_config.TestEnabled('node-info'): |
85 |
RunTest(qa_node.TestNodeInfo) |
86 |
|
87 |
|
88 |
def RunClusterTests(): |
89 |
"""Runs tests related to gnt-cluster.
|
90 |
|
91 |
"""
|
92 |
if qa_config.TestEnabled('cluster-verify'): |
93 |
RunTest(qa_cluster.TestClusterVerify) |
94 |
|
95 |
if qa_config.TestEnabled('cluster-rename'): |
96 |
RunTest(qa_cluster.TestClusterRename) |
97 |
|
98 |
if qa_config.TestEnabled('cluster-info'): |
99 |
RunTest(qa_cluster.TestClusterVersion) |
100 |
RunTest(qa_cluster.TestClusterInfo) |
101 |
RunTest(qa_cluster.TestClusterGetmaster) |
102 |
|
103 |
if qa_config.TestEnabled('cluster-copyfile'): |
104 |
RunTest(qa_cluster.TestClusterCopyfile) |
105 |
|
106 |
if qa_config.TestEnabled('cluster-command'): |
107 |
RunTest(qa_cluster.TestClusterCommand) |
108 |
|
109 |
if qa_config.TestEnabled('cluster-burnin'): |
110 |
RunTest(qa_cluster.TestClusterBurnin) |
111 |
|
112 |
if qa_config.TestEnabled('cluster-master-failover'): |
113 |
RunTest(qa_cluster.TestClusterMasterFailover) |
114 |
|
115 |
if qa_rapi.Enabled():
|
116 |
RunTest(qa_rapi.TestVersion) |
117 |
RunTest(qa_rapi.TestEmptyCluster) |
118 |
|
119 |
def RunOsTests(): |
120 |
"""Runs all tests related to gnt-os.
|
121 |
|
122 |
"""
|
123 |
if not qa_config.TestEnabled('os'): |
124 |
return
|
125 |
|
126 |
RunTest(qa_os.TestOsList) |
127 |
RunTest(qa_os.TestOsDiagnose) |
128 |
RunTest(qa_os.TestOsValid) |
129 |
RunTest(qa_os.TestOsInvalid) |
130 |
RunTest(qa_os.TestOsPartiallyValid) |
131 |
|
132 |
|
133 |
def RunCommonInstanceTests(instance): |
134 |
"""Runs a few tests that are common to all disk types.
|
135 |
|
136 |
"""
|
137 |
if qa_config.TestEnabled('instance-shutdown'): |
138 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
139 |
RunTest(qa_instance.TestInstanceStartup, instance) |
140 |
|
141 |
if qa_config.TestEnabled('instance-list'): |
142 |
RunTest(qa_instance.TestInstanceList) |
143 |
|
144 |
if qa_config.TestEnabled('instance-info'): |
145 |
RunTest(qa_instance.TestInstanceInfo, instance) |
146 |
|
147 |
if qa_config.TestEnabled('instance-modify'): |
148 |
RunTest(qa_instance.TestInstanceModify, instance) |
149 |
|
150 |
if qa_config.TestEnabled('instance-console'): |
151 |
RunTest(qa_instance.TestInstanceConsole, instance) |
152 |
|
153 |
if qa_config.TestEnabled('instance-reinstall'): |
154 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
155 |
RunTest(qa_instance.TestInstanceReinstall, instance) |
156 |
RunTest(qa_instance.TestInstanceStartup, instance) |
157 |
|
158 |
if qa_config.TestEnabled('instance-reboot'): |
159 |
RunTest(qa_instance.TestInstanceReboot, instance) |
160 |
|
161 |
if qa_config.TestEnabled('tags'): |
162 |
RunTest(qa_tags.TestInstanceTags, instance) |
163 |
|
164 |
if qa_config.TestEnabled('node-volumes'): |
165 |
RunTest(qa_node.TestNodeVolumes) |
166 |
|
167 |
if qa_rapi.Enabled():
|
168 |
RunTest(qa_rapi.TestInstance, instance) |
169 |
|
170 |
def RunExportImportTests(instance, pnode): |
171 |
"""Tries to export and import the instance.
|
172 |
|
173 |
"""
|
174 |
if qa_config.TestEnabled('instance-export'): |
175 |
expnode = qa_config.AcquireNode(exclude=pnode) |
176 |
try:
|
177 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
178 |
|
179 |
RunTest(qa_instance.TestBackupList, expnode) |
180 |
|
181 |
if qa_config.TestEnabled('instance-import'): |
182 |
newinst = qa_config.AcquireInstance() |
183 |
try:
|
184 |
RunTest(qa_instance.TestInstanceImport, pnode, newinst, |
185 |
expnode, name) |
186 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
187 |
finally:
|
188 |
qa_config.ReleaseInstance(newinst) |
189 |
finally:
|
190 |
qa_config.ReleaseNode(expnode) |
191 |
|
192 |
|
193 |
def RunDaemonTests(instance, pnode): |
194 |
"""Test the ganeti-watcher script.
|
195 |
|
196 |
"""
|
197 |
automatic_restart = \ |
198 |
qa_config.TestEnabled('instance-automatic-restart')
|
199 |
consecutive_failures = \ |
200 |
qa_config.TestEnabled('instance-consecutive-failures')
|
201 |
|
202 |
if automatic_restart or consecutive_failures: |
203 |
qa_daemon.PrintCronWarning() |
204 |
|
205 |
if automatic_restart:
|
206 |
RunTest(qa_daemon.TestInstanceAutomaticRestart, pnode, instance) |
207 |
|
208 |
if consecutive_failures:
|
209 |
RunTest(qa_daemon.TestInstanceConsecutiveFailures, pnode, instance) |
210 |
|
211 |
|
212 |
def RunHardwareFailureTests(instance, pnode, snode): |
213 |
"""Test cluster internal hardware failure recovery.
|
214 |
|
215 |
"""
|
216 |
if qa_config.TestEnabled('instance-failover'): |
217 |
RunTest(qa_instance.TestInstanceFailover, instance) |
218 |
|
219 |
if qa_config.TestEnabled('instance-replace-disks'): |
220 |
othernode = qa_config.AcquireNode(exclude=[pnode, snode]) |
221 |
try:
|
222 |
RunTest(qa_instance.TestReplaceDisks, |
223 |
instance, pnode, snode, othernode) |
224 |
finally:
|
225 |
qa_config.ReleaseNode(othernode) |
226 |
|
227 |
if qa_config.TestEnabled('node-evacuate'): |
228 |
RunTest(qa_node.TestNodeEvacuate, pnode, snode) |
229 |
|
230 |
if qa_config.TestEnabled('node-failover'): |
231 |
RunTest(qa_node.TestNodeFailover, pnode, snode) |
232 |
|
233 |
if qa_config.TestEnabled('instance-disk-failure'): |
234 |
RunTest(qa_instance.TestInstanceMasterDiskFailure, |
235 |
instance, pnode, snode) |
236 |
RunTest(qa_instance.TestInstanceSecondaryDiskFailure, |
237 |
instance, pnode, snode) |
238 |
|
239 |
|
240 |
def main(): |
241 |
"""Main program.
|
242 |
|
243 |
"""
|
244 |
parser = optparse.OptionParser(usage="%prog [options] <config-file>"
|
245 |
" <known-hosts-file>")
|
246 |
parser.add_option('--dry-run', dest='dry_run', |
247 |
action="store_true",
|
248 |
help="Show what would be done")
|
249 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
250 |
action="store_true",
|
251 |
help="Really execute the tests")
|
252 |
(qa_config.options, args) = parser.parse_args() |
253 |
|
254 |
if len(args) == 2: |
255 |
(config_file, known_hosts_file) = args |
256 |
else:
|
257 |
parser.error("Not enough arguments.")
|
258 |
|
259 |
if not qa_config.options.yes_do_it: |
260 |
print ("Executing this script irreversibly destroys any Ganeti\n" |
261 |
"configuration on all nodes involved. If you really want\n"
|
262 |
"to start testing, supply the --yes-do-it option.")
|
263 |
sys.exit(1)
|
264 |
|
265 |
qa_config.Load(config_file) |
266 |
|
267 |
RunTest(qa_other.UploadKnownHostsFile, known_hosts_file) |
268 |
|
269 |
RunEnvTests() |
270 |
SetupCluster() |
271 |
RunClusterTests() |
272 |
RunOsTests() |
273 |
|
274 |
if qa_config.TestEnabled('tags'): |
275 |
RunTest(qa_tags.TestClusterTags) |
276 |
|
277 |
if qa_config.TestEnabled('node-readd'): |
278 |
master = qa_config.GetMasterNode() |
279 |
pnode = qa_config.AcquireNode(exclude=master) |
280 |
try:
|
281 |
RunTest(qa_node.TestNodeReadd, pnode) |
282 |
finally:
|
283 |
qa_config.ReleaseNode(pnode) |
284 |
|
285 |
pnode = qa_config.AcquireNode() |
286 |
try:
|
287 |
if qa_config.TestEnabled('tags'): |
288 |
RunTest(qa_tags.TestNodeTags, pnode) |
289 |
|
290 |
if qa_rapi.Enabled():
|
291 |
RunTest(qa_rapi.TestNode, pnode) |
292 |
|
293 |
if qa_config.TestEnabled('instance-add-plain-disk'): |
294 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, pnode) |
295 |
RunCommonInstanceTests(instance) |
296 |
RunExportImportTests(instance, pnode) |
297 |
RunDaemonTests(instance, pnode) |
298 |
RunTest(qa_instance.TestInstanceRemove, instance) |
299 |
del instance
|
300 |
|
301 |
multinode_tests = [ |
302 |
('instance-add-drbd-disk',
|
303 |
qa_instance.TestInstanceAddWithDrbdDisk), |
304 |
] |
305 |
|
306 |
for name, func in multinode_tests: |
307 |
if qa_config.TestEnabled(name):
|
308 |
snode = qa_config.AcquireNode(exclude=pnode) |
309 |
try:
|
310 |
instance = RunTest(func, pnode, snode) |
311 |
RunCommonInstanceTests(instance) |
312 |
RunExportImportTests(instance, pnode) |
313 |
RunHardwareFailureTests(instance, pnode, snode) |
314 |
RunTest(qa_instance.TestInstanceRemove, instance) |
315 |
del instance
|
316 |
finally:
|
317 |
qa_config.ReleaseNode(snode) |
318 |
|
319 |
finally:
|
320 |
qa_config.ReleaseNode(pnode) |
321 |
|
322 |
RunTest(qa_node.TestNodeRemoveAll) |
323 |
|
324 |
if qa_config.TestEnabled('cluster-destroy'): |
325 |
RunTest(qa_cluster.TestClusterDestroy) |
326 |
|
327 |
|
328 |
if __name__ == '__main__': |
329 |
main() |