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