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