Revision 2f4b4f78 qa/qa_cluster.py
b/qa/qa_cluster.py | ||
---|---|---|
32 | 32 |
import qa_utils |
33 | 33 |
import qa_error |
34 | 34 |
|
35 |
from qa_utils import AssertEqual, AssertNotEqual, StartSSH
|
|
35 |
from qa_utils import AssertEqual, AssertCommand
|
|
36 | 36 |
|
37 | 37 |
|
38 | 38 |
def _RemoveFileFromAllNodes(filename): |
39 | 39 |
"""Removes a file from all nodes. |
40 | 40 |
|
41 | 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) |
|
42 |
for node in qa_config.get("nodes"): |
|
43 |
AssertCommand(["rm", "-f", filename], node=node) |
|
46 | 44 |
|
47 | 45 |
|
48 | 46 |
def _CheckFileOnAllNodes(filename, content): |
... | ... | |
50 | 48 |
|
51 | 49 |
""" |
52 | 50 |
cmd = utils.ShellQuoteArgs(["cat", filename]) |
53 |
for node in qa_config.get('nodes'): |
|
54 |
AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd), |
|
55 |
content) |
|
51 |
for node in qa_config.get("nodes"): |
|
52 |
AssertEqual(qa_utils.GetCommandOutput(node["primary"], cmd), content) |
|
56 | 53 |
|
57 | 54 |
|
58 | 55 |
def TestClusterInit(rapi_user, rapi_secret): |
... | ... | |
67 | 64 |
|
68 | 65 |
tmpru = qa_utils.UploadFile(master["primary"], fh.name) |
69 | 66 |
try: |
70 |
cmd = ["mv", tmpru, constants.RAPI_USERS_FILE] |
|
71 |
AssertEqual(StartSSH(master["primary"], |
|
72 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
67 |
AssertCommand(["mv", tmpru, constants.RAPI_USERS_FILE]) |
|
73 | 68 |
finally: |
74 |
cmd = ["rm", "-f", tmpru] |
|
75 |
AssertEqual(StartSSH(master["primary"], |
|
76 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
69 |
AssertCommand(["rm", "-f", tmpru]) |
|
77 | 70 |
finally: |
78 | 71 |
fh.close() |
79 | 72 |
|
... | ... | |
97 | 90 |
|
98 | 91 |
cmd.append(qa_config.get('name')) |
99 | 92 |
|
100 |
AssertEqual(StartSSH(master['primary'], |
|
101 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
93 |
AssertCommand(cmd) |
|
102 | 94 |
|
103 | 95 |
|
104 | 96 |
def TestClusterRename(): |
105 | 97 |
"""gnt-cluster rename""" |
106 |
master = qa_config.GetMasterNode() |
|
107 |
|
|
108 | 98 |
cmd = ['gnt-cluster', 'rename', '-f'] |
109 | 99 |
|
110 | 100 |
original_name = qa_config.get('name') |
... | ... | |
113 | 103 |
print qa_utils.FormatError('"rename" entry is missing') |
114 | 104 |
return |
115 | 105 |
|
116 |
cmd_1 = cmd + [rename_target] |
|
117 |
cmd_2 = cmd + [original_name] |
|
118 |
|
|
119 | 106 |
cmd_verify = ['gnt-cluster', 'verify'] |
120 | 107 |
|
121 |
AssertEqual(StartSSH(master['primary'], |
|
122 |
utils.ShellQuoteArgs(cmd_1)).wait(), 0) |
|
123 |
|
|
124 |
AssertEqual(StartSSH(master['primary'], |
|
125 |
utils.ShellQuoteArgs(cmd_verify)).wait(), 0) |
|
126 |
|
|
127 |
AssertEqual(StartSSH(master['primary'], |
|
128 |
utils.ShellQuoteArgs(cmd_2)).wait(), 0) |
|
129 |
|
|
130 |
AssertEqual(StartSSH(master['primary'], |
|
131 |
utils.ShellQuoteArgs(cmd_verify)).wait(), 0) |
|
108 |
for data in [ |
|
109 |
cmd + [rename_target], |
|
110 |
cmd_verify, |
|
111 |
cmd + [original_name], |
|
112 |
cmd_verify, |
|
113 |
]: |
|
114 |
AssertCommand(data) |
|
132 | 115 |
|
133 | 116 |
|
134 | 117 |
def TestClusterVerify(): |
135 | 118 |
"""gnt-cluster verify""" |
136 |
master = qa_config.GetMasterNode() |
|
137 |
|
|
138 |
cmd = ['gnt-cluster', 'verify'] |
|
139 |
AssertEqual(StartSSH(master['primary'], |
|
140 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
119 |
AssertCommand(["gnt-cluster", "verify"]) |
|
141 | 120 |
|
142 | 121 |
|
143 | 122 |
def TestJobqueue(): |
144 | 123 |
"""gnt-debug test-jobqueue""" |
145 |
master = qa_config.GetMasterNode() |
|
146 |
|
|
147 |
cmd = ["gnt-debug", "test-jobqueue"] |
|
148 |
AssertEqual(StartSSH(master["primary"], |
|
149 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
124 |
AssertCommand(["gnt-debug", "test-jobqueue"]) |
|
150 | 125 |
|
151 | 126 |
|
152 | 127 |
def TestClusterReservedLvs(): |
153 | 128 |
"""gnt-cluster reserved lvs""" |
154 |
master = qa_config.GetMasterNode() |
|
155 |
CVERIFY = ['gnt-cluster', 'verify'] |
|
156 |
for rcode, cmd in [ |
|
157 |
(0, CVERIFY), |
|
158 |
(0, ['gnt-cluster', 'modify', '--reserved-lvs', '']), |
|
159 |
(0, ['lvcreate', '-L1G', '-nqa-test', 'xenvg']), |
|
160 |
(1, CVERIFY), |
|
161 |
(0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-test,other-test']), |
|
162 |
(0, CVERIFY), |
|
163 |
(0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-.*']), |
|
164 |
(0, CVERIFY), |
|
165 |
(0, ['gnt-cluster', 'modify', '--reserved-lvs', '']), |
|
166 |
(1, CVERIFY), |
|
167 |
(0, ['lvremove', '-f', 'xenvg/qa-test']), |
|
168 |
(0, CVERIFY), |
|
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), |
|
169 | 143 |
]: |
170 |
AssertEqual(StartSSH(master['primary'], |
|
171 |
utils.ShellQuoteArgs(cmd)).wait(), rcode) |
|
144 |
AssertCommand(cmd, fail=fail) |
|
172 | 145 |
|
173 | 146 |
|
174 | 147 |
def TestClusterModifyBe(): |
175 | 148 |
"""gnt-cluster modify -B""" |
176 |
master = qa_config.GetMasterNode() |
|
177 |
|
|
178 |
for rcode, cmd in [ |
|
149 |
for fail, cmd in [ |
|
179 | 150 |
# mem |
180 |
(0, ["gnt-cluster", "modify", "-B", "memory=256"]),
|
|
181 |
(0, ["sh", "-c", "gnt-cluster info|grep '^ *memory: 256$'"]),
|
|
182 |
(1, ["gnt-cluster", "modify", "-B", "memory=a"]),
|
|
183 |
(0, ["gnt-cluster", "modify", "-B", "memory=128"]),
|
|
184 |
(0, ["sh", "-c", "gnt-cluster info|grep '^ *memory: 128$'"]),
|
|
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$'"]),
|
|
185 | 156 |
# vcpus |
186 |
(0, ["gnt-cluster", "modify", "-B", "vcpus=4"]),
|
|
187 |
(0, ["sh", "-c", "gnt-cluster info|grep '^ *vcpus: 4$'"]),
|
|
188 |
(1, ["gnt-cluster", "modify", "-B", "vcpus=a"]),
|
|
189 |
(0, ["gnt-cluster", "modify", "-B", "vcpus=1"]),
|
|
190 |
(0, ["sh", "-c", "gnt-cluster info|grep '^ *vcpus: 1$'"]),
|
|
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$'"]),
|
|
191 | 162 |
# auto_balance |
192 |
(0, ["gnt-cluster", "modify", "-B", "auto_balance=False"]),
|
|
193 |
(0, ["sh", "-c", "gnt-cluster info|grep '^ *auto_balance: False$'"]),
|
|
194 |
(1, ["gnt-cluster", "modify", "-B", "auto_balance=1"]),
|
|
195 |
(0, ["gnt-cluster", "modify", "-B", "auto_balance=True"]),
|
|
196 |
(0, ["sh", "-c", "gnt-cluster info|grep '^ *auto_balance: True$'"]),
|
|
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$'"]),
|
|
197 | 168 |
]: |
198 |
AssertEqual(StartSSH(master['primary'], |
|
199 |
utils.ShellQuoteArgs(cmd)).wait(), rcode) |
|
169 |
AssertCommand(cmd, fail=fail) |
|
200 | 170 |
|
201 | 171 |
|
202 | 172 |
def TestClusterInfo(): |
203 | 173 |
"""gnt-cluster info""" |
204 |
master = qa_config.GetMasterNode() |
|
205 |
|
|
206 |
cmd = ['gnt-cluster', 'info'] |
|
207 |
AssertEqual(StartSSH(master['primary'], |
|
208 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
174 |
AssertCommand(["gnt-cluster", "info"]) |
|
209 | 175 |
|
210 | 176 |
|
211 | 177 |
def TestClusterGetmaster(): |
212 | 178 |
"""gnt-cluster getmaster""" |
213 |
master = qa_config.GetMasterNode() |
|
214 |
|
|
215 |
cmd = ['gnt-cluster', 'getmaster'] |
|
216 |
AssertEqual(StartSSH(master['primary'], |
|
217 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
179 |
AssertCommand(["gnt-cluster", "getmaster"]) |
|
218 | 180 |
|
219 | 181 |
|
220 | 182 |
def TestClusterVersion(): |
221 | 183 |
"""gnt-cluster version""" |
222 |
master = qa_config.GetMasterNode() |
|
223 |
|
|
224 |
cmd = ['gnt-cluster', 'version'] |
|
225 |
AssertEqual(StartSSH(master['primary'], |
|
226 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
184 |
AssertCommand(["gnt-cluster", "version"]) |
|
227 | 185 |
|
228 | 186 |
|
229 | 187 |
def TestClusterRenewCrypto(): |
... | ... | |
238 | 196 |
["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"], |
239 | 197 |
] |
240 | 198 |
for i in conflicting: |
241 |
AssertNotEqual(StartSSH(master["primary"], |
|
242 |
utils.ShellQuoteArgs(cmd + i)).wait(), 0) |
|
199 |
AssertCommand(cmd+i, fail=True) |
|
243 | 200 |
|
244 | 201 |
# Invalid RAPI certificate |
245 | 202 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
246 | 203 |
"--rapi-certificate=/dev/null"] |
247 |
AssertNotEqual(StartSSH(master["primary"], |
|
248 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
204 |
AssertCommand(cmd, fail=True) |
|
249 | 205 |
|
250 | 206 |
rapi_cert_backup = qa_utils.BackupFile(master["primary"], |
251 | 207 |
constants.RAPI_CERT_FILE) |
... | ... | |
260 | 216 |
|
261 | 217 |
tmpcert = qa_utils.UploadFile(master["primary"], fh.name) |
262 | 218 |
try: |
263 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
|
264 |
"--rapi-certificate=%s" % tmpcert] |
|
265 |
AssertEqual(StartSSH(master["primary"], |
|
266 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
219 |
AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
|
220 |
"--rapi-certificate=%s" % tmpcert]) |
|
267 | 221 |
finally: |
268 |
cmd = ["rm", "-f", tmpcert] |
|
269 |
AssertEqual(StartSSH(master["primary"], |
|
270 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
222 |
AssertCommand(["rm", "-f", tmpcert]) |
|
271 | 223 |
|
272 | 224 |
# Custom cluster domain secret |
273 | 225 |
cds_fh = tempfile.NamedTemporaryFile() |
... | ... | |
277 | 229 |
|
278 | 230 |
tmpcds = qa_utils.UploadFile(master["primary"], cds_fh.name) |
279 | 231 |
try: |
280 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
|
281 |
"--cluster-domain-secret=%s" % tmpcds] |
|
282 |
AssertEqual(StartSSH(master["primary"], |
|
283 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
232 |
AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
|
233 |
"--cluster-domain-secret=%s" % tmpcds]) |
|
284 | 234 |
finally: |
285 |
cmd = ["rm", "-f", tmpcds] |
|
286 |
AssertEqual(StartSSH(master["primary"], |
|
287 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
235 |
AssertCommand(["rm", "-f", tmpcds]) |
|
288 | 236 |
|
289 | 237 |
# Normal case |
290 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
|
291 |
"--new-cluster-certificate", "--new-confd-hmac-key", |
|
292 |
"--new-rapi-certificate", "--new-cluster-domain-secret"] |
|
293 |
AssertEqual(StartSSH(master["primary"], |
|
294 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
238 |
AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
|
239 |
"--new-cluster-certificate", "--new-confd-hmac-key", |
|
240 |
"--new-rapi-certificate", "--new-cluster-domain-secret"]) |
|
295 | 241 |
|
296 | 242 |
# Restore RAPI certificate |
297 |
cmd = ["gnt-cluster", "renew-crypto", "--force", |
|
298 |
"--rapi-certificate=%s" % rapi_cert_backup] |
|
299 |
AssertEqual(StartSSH(master["primary"], |
|
300 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
243 |
AssertCommand(["gnt-cluster", "renew-crypto", "--force", |
|
244 |
"--rapi-certificate=%s" % rapi_cert_backup]) |
|
301 | 245 |
finally: |
302 |
cmd = ["rm", "-f", rapi_cert_backup] |
|
303 |
AssertEqual(StartSSH(master["primary"], |
|
304 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
246 |
AssertCommand(["rm", "-f", rapi_cert_backup]) |
|
305 | 247 |
|
306 | 248 |
|
307 | 249 |
def TestClusterBurnin(): |
... | ... | |
349 | 291 |
else: |
350 | 292 |
cmd.append('--reboot-types=%s' % ",".join(reboot_types)) |
351 | 293 |
cmd += [inst['name'] for inst in instances] |
352 |
AssertEqual(StartSSH(master['primary'], |
|
353 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
294 |
AssertCommand(cmd) |
|
354 | 295 |
finally: |
355 |
cmd = ['rm', '-f', script] |
|
356 |
AssertEqual(StartSSH(master['primary'], |
|
357 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
296 |
AssertCommand(["rm", "-f", script]) |
|
297 |
|
|
358 | 298 |
finally: |
359 | 299 |
for inst in instances: |
360 | 300 |
qa_config.ReleaseInstance(inst) |
... | ... | |
363 | 303 |
def TestClusterMasterFailover(): |
364 | 304 |
"""gnt-cluster master-failover""" |
365 | 305 |
master = qa_config.GetMasterNode() |
366 |
|
|
367 | 306 |
failovermaster = qa_config.AcquireNode(exclude=master) |
368 |
try: |
|
369 |
cmd = ['gnt-cluster', 'master-failover'] |
|
370 |
AssertEqual(StartSSH(failovermaster['primary'], |
|
371 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
372 | 307 |
|
373 |
cmd = ['gnt-cluster', 'master-failover'] |
|
374 |
AssertEqual(StartSSH(master['primary'], |
|
375 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
308 |
cmd = ["gnt-cluster", "master-failover"] |
|
309 |
try: |
|
310 |
AssertCommand(cmd, node=failovermaster) |
|
311 |
AssertCommand(cmd, node=master) |
|
376 | 312 |
finally: |
377 | 313 |
qa_config.ReleaseNode(failovermaster) |
378 | 314 |
|
... | ... | |
393 | 329 |
testname = qa_utils.UploadFile(master['primary'], f.name) |
394 | 330 |
try: |
395 | 331 |
# Copy file to all nodes |
396 |
cmd = ['gnt-cluster', 'copyfile', testname] |
|
397 |
AssertEqual(StartSSH(master['primary'], |
|
398 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
332 |
AssertCommand(["gnt-cluster", "copyfile", testname]) |
|
399 | 333 |
_CheckFileOnAllNodes(testname, uniqueid) |
400 | 334 |
finally: |
401 | 335 |
_RemoveFileFromAllNodes(testname) |
... | ... | |
403 | 337 |
|
404 | 338 |
def TestClusterCommand(): |
405 | 339 |
"""gnt-cluster command""" |
406 |
master = qa_config.GetMasterNode() |
|
407 |
|
|
408 | 340 |
uniqueid = utils.NewUUID() |
409 | 341 |
rfile = "/tmp/gnt%s" % utils.NewUUID() |
410 | 342 |
rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid]) |
... | ... | |
412 | 344 |
"%s >%s" % (rcmd, rfile)]) |
413 | 345 |
|
414 | 346 |
try: |
415 |
AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
|
|
347 |
AssertCommand(cmd)
|
|
416 | 348 |
_CheckFileOnAllNodes(rfile, uniqueid) |
417 | 349 |
finally: |
418 | 350 |
_RemoveFileFromAllNodes(rfile) |
... | ... | |
420 | 352 |
|
421 | 353 |
def TestClusterDestroy(): |
422 | 354 |
"""gnt-cluster destroy""" |
423 |
master = qa_config.GetMasterNode() |
|
424 |
|
|
425 |
cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
|
426 |
AssertEqual(StartSSH(master['primary'], |
|
427 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
355 |
AssertCommand(["gnt-cluster", "destroy", "--yes-do-it"]) |
Also available in: Unified diff