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