root / qa / qa_cluster.py @ 745c878a
History | View | Annotate | Download (9.5 kB)
1 |
#
|
---|---|
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 |
"""Cluster related QA tests.
|
23 |
|
24 |
"""
|
25 |
|
26 |
import tempfile |
27 |
|
28 |
from ganeti import constants |
29 |
from ganeti import bootstrap |
30 |
from ganeti import utils |
31 |
|
32 |
import qa_config |
33 |
import qa_utils |
34 |
import qa_error |
35 |
|
36 |
from qa_utils import AssertEqual, AssertNotEqual, StartSSH |
37 |
|
38 |
|
39 |
def _RemoveFileFromAllNodes(filename): |
40 |
"""Removes a file from all nodes.
|
41 |
|
42 |
"""
|
43 |
for node in qa_config.get('nodes'): |
44 |
cmd = ['rm', '-f', filename] |
45 |
AssertEqual(StartSSH(node['primary'],
|
46 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
47 |
|
48 |
|
49 |
def _CheckFileOnAllNodes(filename, content): |
50 |
"""Verifies the content of the given file on all nodes.
|
51 |
|
52 |
"""
|
53 |
cmd = utils.ShellQuoteArgs(["cat", filename])
|
54 |
for node in qa_config.get('nodes'): |
55 |
AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
|
56 |
content) |
57 |
|
58 |
|
59 |
def TestClusterInit(rapi_user, rapi_secret): |
60 |
"""gnt-cluster init"""
|
61 |
master = qa_config.GetMasterNode() |
62 |
|
63 |
# First create the RAPI credentials
|
64 |
fh = tempfile.NamedTemporaryFile() |
65 |
try:
|
66 |
fh.write("%s %s write\n" % (rapi_user, rapi_secret))
|
67 |
fh.flush() |
68 |
|
69 |
tmpru = qa_utils.UploadFile(master["primary"], fh.name)
|
70 |
try:
|
71 |
cmd = ["mv", tmpru, constants.RAPI_USERS_FILE]
|
72 |
AssertEqual(StartSSH(master["primary"],
|
73 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
74 |
finally:
|
75 |
cmd = ["rm", "-f", tmpru] |
76 |
AssertEqual(StartSSH(master["primary"],
|
77 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
78 |
finally:
|
79 |
fh.close() |
80 |
|
81 |
# Initialize cluster
|
82 |
cmd = ['gnt-cluster', 'init'] |
83 |
|
84 |
if master.get('secondary', None): |
85 |
cmd.append('--secondary-ip=%s' % master['secondary']) |
86 |
|
87 |
bridge = qa_config.get('bridge', None) |
88 |
if bridge:
|
89 |
cmd.append('--bridge=%s' % bridge)
|
90 |
cmd.append('--master-netdev=%s' % bridge)
|
91 |
|
92 |
htype = qa_config.get('enabled-hypervisors', None) |
93 |
if htype:
|
94 |
cmd.append('--enabled-hypervisors=%s' % htype)
|
95 |
|
96 |
cmd.append(qa_config.get('name'))
|
97 |
|
98 |
AssertEqual(StartSSH(master['primary'],
|
99 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
100 |
|
101 |
|
102 |
def TestClusterRename(): |
103 |
"""gnt-cluster rename"""
|
104 |
master = qa_config.GetMasterNode() |
105 |
|
106 |
cmd = ['gnt-cluster', 'rename', '-f'] |
107 |
|
108 |
original_name = qa_config.get('name')
|
109 |
rename_target = qa_config.get('rename', None) |
110 |
if rename_target is None: |
111 |
print qa_utils.FormatError('"rename" entry is missing') |
112 |
return
|
113 |
|
114 |
cmd_1 = cmd + [rename_target] |
115 |
cmd_2 = cmd + [original_name] |
116 |
|
117 |
cmd_verify = ['gnt-cluster', 'verify'] |
118 |
|
119 |
AssertEqual(StartSSH(master['primary'],
|
120 |
utils.ShellQuoteArgs(cmd_1)).wait(), 0)
|
121 |
|
122 |
AssertEqual(StartSSH(master['primary'],
|
123 |
utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
|
124 |
|
125 |
AssertEqual(StartSSH(master['primary'],
|
126 |
utils.ShellQuoteArgs(cmd_2)).wait(), 0)
|
127 |
|
128 |
AssertEqual(StartSSH(master['primary'],
|
129 |
utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
|
130 |
|
131 |
|
132 |
def TestClusterVerify(): |
133 |
"""gnt-cluster verify"""
|
134 |
master = qa_config.GetMasterNode() |
135 |
|
136 |
cmd = ['gnt-cluster', 'verify'] |
137 |
AssertEqual(StartSSH(master['primary'],
|
138 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
139 |
|
140 |
|
141 |
def TestClusterInfo(): |
142 |
"""gnt-cluster info"""
|
143 |
master = qa_config.GetMasterNode() |
144 |
|
145 |
cmd = ['gnt-cluster', 'info'] |
146 |
AssertEqual(StartSSH(master['primary'],
|
147 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
148 |
|
149 |
|
150 |
def TestClusterGetmaster(): |
151 |
"""gnt-cluster getmaster"""
|
152 |
master = qa_config.GetMasterNode() |
153 |
|
154 |
cmd = ['gnt-cluster', 'getmaster'] |
155 |
AssertEqual(StartSSH(master['primary'],
|
156 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
157 |
|
158 |
|
159 |
def TestClusterVersion(): |
160 |
"""gnt-cluster version"""
|
161 |
master = qa_config.GetMasterNode() |
162 |
|
163 |
cmd = ['gnt-cluster', 'version'] |
164 |
AssertEqual(StartSSH(master['primary'],
|
165 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
166 |
|
167 |
|
168 |
def TestClusterRenewCrypto(): |
169 |
"""gnt-cluster renew-crypto"""
|
170 |
master = qa_config.GetMasterNode() |
171 |
|
172 |
# Conflicting options
|
173 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
174 |
"--new-cluster-certificate", "--new-confd-hmac-key", |
175 |
"--new-rapi-certificate", "--rapi-certificate=/dev/null"] |
176 |
AssertNotEqual(StartSSH(master["primary"],
|
177 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
178 |
|
179 |
# Invalid RAPI certificate
|
180 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
181 |
"--rapi-certificate=/dev/null"]
|
182 |
AssertNotEqual(StartSSH(master["primary"],
|
183 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
184 |
|
185 |
# Custom RAPI certificate
|
186 |
fh = tempfile.NamedTemporaryFile() |
187 |
|
188 |
# Ensure certificate doesn't cause "gnt-cluster verify" to complain
|
189 |
validity = constants.SSL_CERT_EXPIRATION_WARN * 3
|
190 |
|
191 |
bootstrap.GenerateSelfSignedSslCert(fh.name, validity=validity) |
192 |
|
193 |
tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
|
194 |
try:
|
195 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
196 |
"--rapi-certificate=%s" % tmpcert]
|
197 |
AssertEqual(StartSSH(master["primary"],
|
198 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
199 |
finally:
|
200 |
cmd = ["rm", "-f", tmpcert] |
201 |
AssertEqual(StartSSH(master["primary"],
|
202 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
203 |
|
204 |
# Normal case
|
205 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
206 |
"--new-cluster-certificate", "--new-confd-hmac-key", |
207 |
"--new-rapi-certificate"]
|
208 |
AssertEqual(StartSSH(master["primary"],
|
209 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
210 |
|
211 |
|
212 |
def TestClusterBurnin(): |
213 |
"""Burnin"""
|
214 |
master = qa_config.GetMasterNode() |
215 |
|
216 |
options = qa_config.get('options', {})
|
217 |
disk_template = options.get('burnin-disk-template', 'drbd') |
218 |
parallel = options.get('burnin-in-parallel', False) |
219 |
check_inst = options.get('burnin-check-instances', False) |
220 |
do_rename = options.get('burnin-rename', '') |
221 |
|
222 |
# Get as many instances as we need
|
223 |
instances = [] |
224 |
try:
|
225 |
try:
|
226 |
num = qa_config.get('options', {}).get('burnin-instances', 1) |
227 |
for _ in range(0, num): |
228 |
instances.append(qa_config.AcquireInstance()) |
229 |
except qa_error.OutOfInstancesError:
|
230 |
print "Not enough instances, continuing anyway." |
231 |
|
232 |
if len(instances) < 1: |
233 |
raise qa_error.Error("Burnin needs at least one instance") |
234 |
|
235 |
script = qa_utils.UploadFile(master['primary'], '../tools/burnin') |
236 |
try:
|
237 |
# Run burnin
|
238 |
cmd = [script, |
239 |
'--os=%s' % qa_config.get('os'), |
240 |
'--disk-size=%s' % ",".join(qa_config.get('disk')), |
241 |
'--disk-growth=%s' % ",".join(qa_config.get('disk-growth')), |
242 |
'--disk-template=%s' % disk_template]
|
243 |
if parallel:
|
244 |
cmd.append('--parallel')
|
245 |
cmd.append('--early-release')
|
246 |
if check_inst:
|
247 |
cmd.append('--http-check')
|
248 |
if do_rename:
|
249 |
cmd.append('--rename=%s' % do_rename)
|
250 |
cmd += [inst['name'] for inst in instances] |
251 |
AssertEqual(StartSSH(master['primary'],
|
252 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
253 |
finally:
|
254 |
cmd = ['rm', '-f', script] |
255 |
AssertEqual(StartSSH(master['primary'],
|
256 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
257 |
finally:
|
258 |
for inst in instances: |
259 |
qa_config.ReleaseInstance(inst) |
260 |
|
261 |
|
262 |
def TestClusterMasterFailover(): |
263 |
"""gnt-cluster masterfailover"""
|
264 |
master = qa_config.GetMasterNode() |
265 |
|
266 |
failovermaster = qa_config.AcquireNode(exclude=master) |
267 |
try:
|
268 |
cmd = ['gnt-cluster', 'masterfailover'] |
269 |
AssertEqual(StartSSH(failovermaster['primary'],
|
270 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
271 |
|
272 |
cmd = ['gnt-cluster', 'masterfailover'] |
273 |
AssertEqual(StartSSH(master['primary'],
|
274 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
275 |
finally:
|
276 |
qa_config.ReleaseNode(failovermaster) |
277 |
|
278 |
|
279 |
def TestClusterCopyfile(): |
280 |
"""gnt-cluster copyfile"""
|
281 |
master = qa_config.GetMasterNode() |
282 |
|
283 |
uniqueid = utils.NewUUID() |
284 |
|
285 |
# Create temporary file
|
286 |
f = tempfile.NamedTemporaryFile() |
287 |
f.write(uniqueid) |
288 |
f.flush() |
289 |
f.seek(0)
|
290 |
|
291 |
# Upload file to master node
|
292 |
testname = qa_utils.UploadFile(master['primary'], f.name)
|
293 |
try:
|
294 |
# Copy file to all nodes
|
295 |
cmd = ['gnt-cluster', 'copyfile', testname] |
296 |
AssertEqual(StartSSH(master['primary'],
|
297 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
298 |
_CheckFileOnAllNodes(testname, uniqueid) |
299 |
finally:
|
300 |
_RemoveFileFromAllNodes(testname) |
301 |
|
302 |
|
303 |
def TestClusterCommand(): |
304 |
"""gnt-cluster command"""
|
305 |
master = qa_config.GetMasterNode() |
306 |
|
307 |
uniqueid = utils.NewUUID() |
308 |
rfile = "/tmp/gnt%s" % utils.NewUUID()
|
309 |
rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid]) |
310 |
cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command', |
311 |
"%s >%s" % (rcmd, rfile)])
|
312 |
|
313 |
try:
|
314 |
AssertEqual(StartSSH(master['primary'], cmd).wait(), 0) |
315 |
_CheckFileOnAllNodes(rfile, uniqueid) |
316 |
finally:
|
317 |
_RemoveFileFromAllNodes(rfile) |
318 |
|
319 |
|
320 |
def TestClusterDestroy(): |
321 |
"""gnt-cluster destroy"""
|
322 |
master = qa_config.GetMasterNode() |
323 |
|
324 |
cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
325 |
AssertEqual(StartSSH(master['primary'],
|
326 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|