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