4 # Copyright (C) 2007 Google Inc.
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.
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.
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
22 """Cluster related QA tests.
28 from ganeti import constants
29 from ganeti import utils
35 from qa_utils import AssertEqual, AssertNotEqual, StartSSH
38 def _RemoveFileFromAllNodes(filename):
39 """Removes a file from all nodes.
42 for node in qa_config.get('nodes'):
43 cmd = ['rm', '-f', filename]
44 AssertEqual(StartSSH(node['primary'],
45 utils.ShellQuoteArgs(cmd)).wait(), 0)
48 def _CheckFileOnAllNodes(filename, content):
49 """Verifies the content of the given file on all nodes.
52 cmd = utils.ShellQuoteArgs(["cat", filename])
53 for node in qa_config.get('nodes'):
54 AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
58 def TestClusterInit(rapi_user, rapi_secret):
59 """gnt-cluster init"""
60 master = qa_config.GetMasterNode()
62 # First create the RAPI credentials
63 fh = tempfile.NamedTemporaryFile()
65 fh.write("%s %s write\n" % (rapi_user, rapi_secret))
68 tmpru = qa_utils.UploadFile(master["primary"], fh.name)
70 cmd = ["mv", tmpru, constants.RAPI_USERS_FILE]
71 AssertEqual(StartSSH(master["primary"],
72 utils.ShellQuoteArgs(cmd)).wait(), 0)
74 cmd = ["rm", "-f", tmpru]
75 AssertEqual(StartSSH(master["primary"],
76 utils.ShellQuoteArgs(cmd)).wait(), 0)
81 cmd = ['gnt-cluster', 'init']
83 if master.get('secondary', None):
84 cmd.append('--secondary-ip=%s' % master['secondary'])
86 bridge = qa_config.get('bridge', None)
88 cmd.append('--bridge=%s' % bridge)
89 cmd.append('--master-netdev=%s' % bridge)
91 htype = qa_config.get('enabled-hypervisors', None)
93 cmd.append('--enabled-hypervisors=%s' % htype)
95 cmd.append(qa_config.get('name'))
97 AssertEqual(StartSSH(master['primary'],
98 utils.ShellQuoteArgs(cmd)).wait(), 0)
101 def TestClusterRename():
102 """gnt-cluster rename"""
103 master = qa_config.GetMasterNode()
105 cmd = ['gnt-cluster', 'rename', '-f']
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')
113 cmd_1 = cmd + [rename_target]
114 cmd_2 = cmd + [original_name]
116 cmd_verify = ['gnt-cluster', 'verify']
118 AssertEqual(StartSSH(master['primary'],
119 utils.ShellQuoteArgs(cmd_1)).wait(), 0)
121 AssertEqual(StartSSH(master['primary'],
122 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
124 AssertEqual(StartSSH(master['primary'],
125 utils.ShellQuoteArgs(cmd_2)).wait(), 0)
127 AssertEqual(StartSSH(master['primary'],
128 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
131 def TestClusterVerify():
132 """gnt-cluster verify"""
133 master = qa_config.GetMasterNode()
135 cmd = ['gnt-cluster', 'verify']
136 AssertEqual(StartSSH(master['primary'],
137 utils.ShellQuoteArgs(cmd)).wait(), 0)
139 def TestClusterReservedLvs():
140 """gnt-cluster reserved lvs"""
141 master = qa_config.GetMasterNode()
142 CVERIFY = ['gnt-cluster', 'verify']
145 (0, ['gnt-cluster', 'modify', '--reserved-lvs', '']),
146 (0, ['lvcreate', '-L1G', '-nqa-test', 'xenvg']),
148 (0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-test,other-test']),
150 (0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-.*']),
152 (0, ['gnt-cluster', 'modify', '--reserved-lvs', '']),
154 (0, ['lvremove', '-f', 'xenvg/qa-test']),
157 AssertEqual(StartSSH(master['primary'],
158 utils.ShellQuoteArgs(cmd)).wait(), rcode)
161 def TestClusterInfo():
162 """gnt-cluster info"""
163 master = qa_config.GetMasterNode()
165 cmd = ['gnt-cluster', 'info']
166 AssertEqual(StartSSH(master['primary'],
167 utils.ShellQuoteArgs(cmd)).wait(), 0)
170 def TestClusterGetmaster():
171 """gnt-cluster getmaster"""
172 master = qa_config.GetMasterNode()
174 cmd = ['gnt-cluster', 'getmaster']
175 AssertEqual(StartSSH(master['primary'],
176 utils.ShellQuoteArgs(cmd)).wait(), 0)
179 def TestClusterVersion():
180 """gnt-cluster version"""
181 master = qa_config.GetMasterNode()
183 cmd = ['gnt-cluster', 'version']
184 AssertEqual(StartSSH(master['primary'],
185 utils.ShellQuoteArgs(cmd)).wait(), 0)
188 def TestClusterRenewCrypto():
189 """gnt-cluster renew-crypto"""
190 master = qa_config.GetMasterNode()
192 # Conflicting options
193 cmd = ["gnt-cluster", "renew-crypto", "--force",
194 "--new-cluster-certificate", "--new-confd-hmac-key"]
196 ["--new-rapi-certificate", "--rapi-certificate=/dev/null"],
197 ["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"],
199 for i in conflicting:
200 AssertNotEqual(StartSSH(master["primary"],
201 utils.ShellQuoteArgs(cmd + i)).wait(), 0)
203 # Invalid RAPI certificate
204 cmd = ["gnt-cluster", "renew-crypto", "--force",
205 "--rapi-certificate=/dev/null"]
206 AssertNotEqual(StartSSH(master["primary"],
207 utils.ShellQuoteArgs(cmd)).wait(), 0)
209 rapi_cert_backup = qa_utils.BackupFile(master["primary"],
210 constants.RAPI_CERT_FILE)
212 # Custom RAPI certificate
213 fh = tempfile.NamedTemporaryFile()
215 # Ensure certificate doesn't cause "gnt-cluster verify" to complain
216 validity = constants.SSL_CERT_EXPIRATION_WARN * 3
218 utils.GenerateSelfSignedSslCert(fh.name, validity=validity)
220 tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
222 cmd = ["gnt-cluster", "renew-crypto", "--force",
223 "--rapi-certificate=%s" % tmpcert]
224 AssertEqual(StartSSH(master["primary"],
225 utils.ShellQuoteArgs(cmd)).wait(), 0)
227 cmd = ["rm", "-f", tmpcert]
228 AssertEqual(StartSSH(master["primary"],
229 utils.ShellQuoteArgs(cmd)).wait(), 0)
231 # Custom cluster domain secret
232 cds_fh = tempfile.NamedTemporaryFile()
233 cds_fh.write(utils.GenerateSecret())
237 tmpcds = qa_utils.UploadFile(master["primary"], cds_fh.name)
239 cmd = ["gnt-cluster", "renew-crypto", "--force",
240 "--cluster-domain-secret=%s" % tmpcds]
241 AssertEqual(StartSSH(master["primary"],
242 utils.ShellQuoteArgs(cmd)).wait(), 0)
244 cmd = ["rm", "-f", tmpcds]
245 AssertEqual(StartSSH(master["primary"],
246 utils.ShellQuoteArgs(cmd)).wait(), 0)
249 cmd = ["gnt-cluster", "renew-crypto", "--force",
250 "--new-cluster-certificate", "--new-confd-hmac-key",
251 "--new-rapi-certificate", "--new-cluster-domain-secret"]
252 AssertEqual(StartSSH(master["primary"],
253 utils.ShellQuoteArgs(cmd)).wait(), 0)
255 # Restore RAPI certificate
256 cmd = ["gnt-cluster", "renew-crypto", "--force",
257 "--rapi-certificate=%s" % rapi_cert_backup]
258 AssertEqual(StartSSH(master["primary"],
259 utils.ShellQuoteArgs(cmd)).wait(), 0)
261 cmd = ["rm", "-f", rapi_cert_backup]
262 AssertEqual(StartSSH(master["primary"],
263 utils.ShellQuoteArgs(cmd)).wait(), 0)
266 def TestClusterBurnin():
268 master = qa_config.GetMasterNode()
270 options = qa_config.get('options', {})
271 disk_template = options.get('burnin-disk-template', 'drbd')
272 parallel = options.get('burnin-in-parallel', False)
273 check_inst = options.get('burnin-check-instances', False)
274 do_rename = options.get('burnin-rename', '')
275 do_reboot = options.get('burnin-reboot', True)
276 reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
278 # Get as many instances as we need
282 num = qa_config.get('options', {}).get('burnin-instances', 1)
283 for _ in range(0, num):
284 instances.append(qa_config.AcquireInstance())
285 except qa_error.OutOfInstancesError:
286 print "Not enough instances, continuing anyway."
288 if len(instances) < 1:
289 raise qa_error.Error("Burnin needs at least one instance")
291 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
295 '--os=%s' % qa_config.get('os'),
296 '--disk-size=%s' % ",".join(qa_config.get('disk')),
297 '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
298 '--disk-template=%s' % disk_template]
300 cmd.append('--parallel')
301 cmd.append('--early-release')
303 cmd.append('--http-check')
305 cmd.append('--rename=%s' % do_rename)
307 cmd.append('--no-reboot')
309 cmd.append('--reboot-types=%s' % ",".join(reboot_types))
310 cmd += [inst['name'] for inst in instances]
311 AssertEqual(StartSSH(master['primary'],
312 utils.ShellQuoteArgs(cmd)).wait(), 0)
314 cmd = ['rm', '-f', script]
315 AssertEqual(StartSSH(master['primary'],
316 utils.ShellQuoteArgs(cmd)).wait(), 0)
318 for inst in instances:
319 qa_config.ReleaseInstance(inst)
322 def TestClusterMasterFailover():
323 """gnt-cluster master-failover"""
324 master = qa_config.GetMasterNode()
326 failovermaster = qa_config.AcquireNode(exclude=master)
328 cmd = ['gnt-cluster', 'master-failover']
329 AssertEqual(StartSSH(failovermaster['primary'],
330 utils.ShellQuoteArgs(cmd)).wait(), 0)
332 cmd = ['gnt-cluster', 'master-failover']
333 AssertEqual(StartSSH(master['primary'],
334 utils.ShellQuoteArgs(cmd)).wait(), 0)
336 qa_config.ReleaseNode(failovermaster)
339 def TestClusterCopyfile():
340 """gnt-cluster copyfile"""
341 master = qa_config.GetMasterNode()
343 uniqueid = utils.NewUUID()
345 # Create temporary file
346 f = tempfile.NamedTemporaryFile()
351 # Upload file to master node
352 testname = qa_utils.UploadFile(master['primary'], f.name)
354 # Copy file to all nodes
355 cmd = ['gnt-cluster', 'copyfile', testname]
356 AssertEqual(StartSSH(master['primary'],
357 utils.ShellQuoteArgs(cmd)).wait(), 0)
358 _CheckFileOnAllNodes(testname, uniqueid)
360 _RemoveFileFromAllNodes(testname)
363 def TestClusterCommand():
364 """gnt-cluster command"""
365 master = qa_config.GetMasterNode()
367 uniqueid = utils.NewUUID()
368 rfile = "/tmp/gnt%s" % utils.NewUUID()
369 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
370 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
371 "%s >%s" % (rcmd, rfile)])
374 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
375 _CheckFileOnAllNodes(rfile, uniqueid)
377 _RemoveFileFromAllNodes(rfile)
380 def TestClusterDestroy():
381 """gnt-cluster destroy"""
382 master = qa_config.GetMasterNode()
384 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
385 AssertEqual(StartSSH(master['primary'],
386 utils.ShellQuoteArgs(cmd)).wait(), 0)