root / qa / ganeti-qa.py @ d7e49c13
History | View | Annotate | Download (7.2 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 |
from datetime import datetime |
32 |
from optparse import OptionParser |
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_other |
41 |
|
42 |
|
43 |
def RunTest(fn, *args): |
44 |
"""Runs a test after printing a header.
|
45 |
|
46 |
"""
|
47 |
if fn.__doc__:
|
48 |
desc = fn.__doc__.splitlines()[0].strip()
|
49 |
else:
|
50 |
desc = '%r' % fn
|
51 |
|
52 |
now = str(datetime.now())
|
53 |
|
54 |
print
|
55 |
print '---', now, ('-' * (55 - len(now))) |
56 |
print desc
|
57 |
print '-' * 60 |
58 |
|
59 |
return fn(*args)
|
60 |
|
61 |
|
62 |
def main(): |
63 |
"""Main program.
|
64 |
|
65 |
"""
|
66 |
parser = OptionParser(usage="%prog [options] <config-file> "
|
67 |
"<known-hosts-file>")
|
68 |
parser.add_option('--dry-run', dest='dry_run', |
69 |
action="store_true",
|
70 |
help="Show what would be done")
|
71 |
parser.add_option('--yes-do-it', dest='yes_do_it', |
72 |
action="store_true",
|
73 |
help="Really execute the tests")
|
74 |
(qa_config.options, args) = parser.parse_args() |
75 |
|
76 |
if len(args) == 2: |
77 |
(config_file, known_hosts_file) = args |
78 |
else:
|
79 |
parser.error("Not enough arguments.")
|
80 |
|
81 |
if not qa_config.options.yes_do_it: |
82 |
print ("Executing this script irreversibly destroys any Ganeti\n" |
83 |
"configuration on all nodes involved. If you really want\n"
|
84 |
"to start testing, supply the --yes-do-it option.")
|
85 |
sys.exit(1)
|
86 |
|
87 |
qa_config.Load(config_file) |
88 |
|
89 |
RunTest(qa_other.TestUploadKnownHostsFile, known_hosts_file) |
90 |
|
91 |
if qa_config.TestEnabled('env'): |
92 |
RunTest(qa_env.TestSshConnection) |
93 |
RunTest(qa_env.TestIcmpPing) |
94 |
RunTest(qa_env.TestGanetiCommands) |
95 |
|
96 |
RunTest(qa_cluster.TestClusterInit) |
97 |
|
98 |
RunTest(qa_node.TestNodeAddAll) |
99 |
|
100 |
if qa_config.TestEnabled('cluster-verify'): |
101 |
RunTest(qa_cluster.TestClusterVerify) |
102 |
|
103 |
if qa_config.TestEnabled('cluster-info'): |
104 |
RunTest(qa_cluster.TestClusterInfo) |
105 |
|
106 |
if qa_config.TestEnabled('cluster-getmaster'): |
107 |
RunTest(qa_cluster.TestClusterGetmaster) |
108 |
|
109 |
if qa_config.TestEnabled('cluster-version'): |
110 |
RunTest(qa_cluster.TestClusterVersion) |
111 |
|
112 |
if qa_config.TestEnabled('cluster-copyfile'): |
113 |
RunTest(qa_cluster.TestClusterCopyfile) |
114 |
|
115 |
if qa_config.TestEnabled('node-info'): |
116 |
RunTest(qa_node.TestNodeInfo) |
117 |
|
118 |
if qa_config.TestEnabled('cluster-burnin'): |
119 |
RunTest(qa_cluster.TestClusterBurnin) |
120 |
|
121 |
if qa_config.TestEnabled('cluster-master-failover'): |
122 |
RunTest(qa_cluster.TestClusterMasterFailover) |
123 |
|
124 |
node = qa_config.AcquireNode() |
125 |
try:
|
126 |
if qa_config.TestEnabled('instance-add-plain-disk'): |
127 |
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node) |
128 |
|
129 |
if qa_config.TestEnabled('instance-shutdown'): |
130 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
131 |
RunTest(qa_instance.TestInstanceStartup, instance) |
132 |
|
133 |
if qa_config.TestEnabled('instance-list'): |
134 |
RunTest(qa_instance.TestInstanceList) |
135 |
|
136 |
if qa_config.TestEnabled('instance-info'): |
137 |
RunTest(qa_instance.TestInstanceInfo, instance) |
138 |
|
139 |
automatic_restart = \ |
140 |
qa_config.TestEnabled('instance-automatic-restart')
|
141 |
consecutive_failures = \ |
142 |
qa_config.TestEnabled('instance-consecutive-failures')
|
143 |
|
144 |
if automatic_restart or consecutive_failures: |
145 |
qa_daemon.PrintCronWarning() |
146 |
|
147 |
if automatic_restart:
|
148 |
RunTest(qa_daemon.TestInstanceAutomaticRestart, node, instance) |
149 |
|
150 |
if consecutive_failures:
|
151 |
RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance) |
152 |
|
153 |
if qa_config.TestEnabled('instance-export'): |
154 |
expnode = qa_config.AcquireNode(exclude=node) |
155 |
try:
|
156 |
name = RunTest(qa_instance.TestInstanceExport, instance, expnode) |
157 |
|
158 |
RunTest(qa_instance.TestBackupList, expnode) |
159 |
|
160 |
if qa_config.TestEnabled('instance-import'): |
161 |
newinst = qa_config.AcquireInstance() |
162 |
try:
|
163 |
RunTest(qa_instance.TestInstanceImport, node, newinst, |
164 |
expnode, name) |
165 |
RunTest(qa_instance.TestInstanceRemove, newinst) |
166 |
finally:
|
167 |
qa_config.ReleaseInstance(newinst) |
168 |
finally:
|
169 |
qa_config.ReleaseNode(expnode) |
170 |
|
171 |
if qa_config.TestEnabled('instance-reinstall'): |
172 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
173 |
RunTest(qa_instance.TestInstanceReinstall, instance) |
174 |
RunTest(qa_instance.TestInstanceStartup, instance) |
175 |
|
176 |
if qa_config.TestEnabled('node-volumes'): |
177 |
RunTest(qa_node.TestNodeVolumes) |
178 |
|
179 |
RunTest(qa_instance.TestInstanceRemove, instance) |
180 |
del instance
|
181 |
|
182 |
if qa_config.TestEnabled('instance-add-local-mirror-disk'): |
183 |
instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node) |
184 |
|
185 |
if qa_config.TestEnabled('instance-shutdown'): |
186 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
187 |
RunTest(qa_instance.TestInstanceStartup, instance) |
188 |
|
189 |
if qa_config.TestEnabled('instance-info'): |
190 |
RunTest(qa_instance.TestInstanceInfo, instance) |
191 |
|
192 |
if qa_config.TestEnabled('node-volumes'): |
193 |
RunTest(qa_node.TestNodeVolumes) |
194 |
|
195 |
RunTest(qa_instance.TestInstanceRemove, instance) |
196 |
del instance
|
197 |
|
198 |
if qa_config.TestEnabled('instance-add-remote-raid-disk'): |
199 |
node2 = qa_config.AcquireNode(exclude=node) |
200 |
try:
|
201 |
instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk, |
202 |
node, node2) |
203 |
|
204 |
if qa_config.TestEnabled('instance-shutdown'): |
205 |
RunTest(qa_instance.TestInstanceShutdown, instance) |
206 |
RunTest(qa_instance.TestInstanceStartup, instance) |
207 |
|
208 |
if qa_config.TestEnabled('instance-info'): |
209 |
RunTest(qa_instance.TestInstanceInfo, instance) |
210 |
|
211 |
if qa_config.TestEnabled('instance-failover'): |
212 |
RunTest(qa_instance.TestInstanceFailover, instance) |
213 |
|
214 |
if qa_config.TestEnabled('node-evacuate'): |
215 |
RunTest(qa_node.TestNodeEvacuate, node, node2) |
216 |
|
217 |
if qa_config.TestEnabled('node-failover'): |
218 |
RunTest(qa_node.TestNodeFailover, node, node2) |
219 |
|
220 |
if qa_config.TestEnabled('node-volumes'): |
221 |
RunTest(qa_node.TestNodeVolumes) |
222 |
|
223 |
RunTest(qa_instance.TestInstanceRemove, instance) |
224 |
del instance
|
225 |
finally:
|
226 |
qa_config.ReleaseNode(node2) |
227 |
|
228 |
finally:
|
229 |
qa_config.ReleaseNode(node) |
230 |
|
231 |
RunTest(qa_node.TestNodeRemoveAll) |
232 |
|
233 |
if qa_config.TestEnabled('cluster-destroy'): |
234 |
RunTest(qa_cluster.TestClusterDestroy) |
235 |
|
236 |
|
237 |
if __name__ == '__main__': |
238 |
main() |