4 # Copyright (C) 2007, 2010 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 cmd.append("--primary-ip-version=%d" %
84 qa_config.get("primary_ip_version", 4))
86 if master.get('secondary', None):
87 cmd.append('--secondary-ip=%s' % master['secondary'])
89 bridge = qa_config.get('bridge', None)
91 cmd.append('--bridge=%s' % bridge)
92 cmd.append('--master-netdev=%s' % bridge)
94 htype = qa_config.get('enabled-hypervisors', None)
96 cmd.append('--enabled-hypervisors=%s' % htype)
98 cmd.append(qa_config.get('name'))
100 AssertEqual(StartSSH(master['primary'],
101 utils.ShellQuoteArgs(cmd)).wait(), 0)
104 def TestClusterRename():
105 """gnt-cluster rename"""
106 master = qa_config.GetMasterNode()
108 cmd = ['gnt-cluster', 'rename', '-f']
110 original_name = qa_config.get('name')
111 rename_target = qa_config.get('rename', None)
112 if rename_target is None:
113 print qa_utils.FormatError('"rename" entry is missing')
116 cmd_1 = cmd + [rename_target]
117 cmd_2 = cmd + [original_name]
119 cmd_verify = ['gnt-cluster', 'verify']
121 AssertEqual(StartSSH(master['primary'],
122 utils.ShellQuoteArgs(cmd_1)).wait(), 0)
124 AssertEqual(StartSSH(master['primary'],
125 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
127 AssertEqual(StartSSH(master['primary'],
128 utils.ShellQuoteArgs(cmd_2)).wait(), 0)
130 AssertEqual(StartSSH(master['primary'],
131 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
134 def TestClusterVerify():
135 """gnt-cluster verify"""
136 master = qa_config.GetMasterNode()
138 cmd = ['gnt-cluster', 'verify']
139 AssertEqual(StartSSH(master['primary'],
140 utils.ShellQuoteArgs(cmd)).wait(), 0)
142 def TestClusterReservedLvs():
143 """gnt-cluster reserved lvs"""
144 master = qa_config.GetMasterNode()
145 CVERIFY = ['gnt-cluster', 'verify']
148 (0, ['gnt-cluster', 'modify', '--reserved-lvs', '']),
149 (0, ['lvcreate', '-L1G', '-nqa-test', 'xenvg']),
151 (0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-test,other-test']),
153 (0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-.*']),
155 (0, ['gnt-cluster', 'modify', '--reserved-lvs', '']),
157 (0, ['lvremove', '-f', 'xenvg/qa-test']),
160 AssertEqual(StartSSH(master['primary'],
161 utils.ShellQuoteArgs(cmd)).wait(), rcode)
164 def TestClusterInfo():
165 """gnt-cluster info"""
166 master = qa_config.GetMasterNode()
168 cmd = ['gnt-cluster', 'info']
169 AssertEqual(StartSSH(master['primary'],
170 utils.ShellQuoteArgs(cmd)).wait(), 0)
173 def TestClusterGetmaster():
174 """gnt-cluster getmaster"""
175 master = qa_config.GetMasterNode()
177 cmd = ['gnt-cluster', 'getmaster']
178 AssertEqual(StartSSH(master['primary'],
179 utils.ShellQuoteArgs(cmd)).wait(), 0)
182 def TestClusterVersion():
183 """gnt-cluster version"""
184 master = qa_config.GetMasterNode()
186 cmd = ['gnt-cluster', 'version']
187 AssertEqual(StartSSH(master['primary'],
188 utils.ShellQuoteArgs(cmd)).wait(), 0)
191 def TestClusterRenewCrypto():
192 """gnt-cluster renew-crypto"""
193 master = qa_config.GetMasterNode()
195 # Conflicting options
196 cmd = ["gnt-cluster", "renew-crypto", "--force",
197 "--new-cluster-certificate", "--new-confd-hmac-key"]
199 ["--new-rapi-certificate", "--rapi-certificate=/dev/null"],
200 ["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"],
202 for i in conflicting:
203 AssertNotEqual(StartSSH(master["primary"],
204 utils.ShellQuoteArgs(cmd + i)).wait(), 0)
206 # Invalid RAPI certificate
207 cmd = ["gnt-cluster", "renew-crypto", "--force",
208 "--rapi-certificate=/dev/null"]
209 AssertNotEqual(StartSSH(master["primary"],
210 utils.ShellQuoteArgs(cmd)).wait(), 0)
212 rapi_cert_backup = qa_utils.BackupFile(master["primary"],
213 constants.RAPI_CERT_FILE)
215 # Custom RAPI certificate
216 fh = tempfile.NamedTemporaryFile()
218 # Ensure certificate doesn't cause "gnt-cluster verify" to complain
219 validity = constants.SSL_CERT_EXPIRATION_WARN * 3
221 utils.GenerateSelfSignedSslCert(fh.name, validity=validity)
223 tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
225 cmd = ["gnt-cluster", "renew-crypto", "--force",
226 "--rapi-certificate=%s" % tmpcert]
227 AssertEqual(StartSSH(master["primary"],
228 utils.ShellQuoteArgs(cmd)).wait(), 0)
230 cmd = ["rm", "-f", tmpcert]
231 AssertEqual(StartSSH(master["primary"],
232 utils.ShellQuoteArgs(cmd)).wait(), 0)
234 # Custom cluster domain secret
235 cds_fh = tempfile.NamedTemporaryFile()
236 cds_fh.write(utils.GenerateSecret())
240 tmpcds = qa_utils.UploadFile(master["primary"], cds_fh.name)
242 cmd = ["gnt-cluster", "renew-crypto", "--force",
243 "--cluster-domain-secret=%s" % tmpcds]
244 AssertEqual(StartSSH(master["primary"],
245 utils.ShellQuoteArgs(cmd)).wait(), 0)
247 cmd = ["rm", "-f", tmpcds]
248 AssertEqual(StartSSH(master["primary"],
249 utils.ShellQuoteArgs(cmd)).wait(), 0)
252 cmd = ["gnt-cluster", "renew-crypto", "--force",
253 "--new-cluster-certificate", "--new-confd-hmac-key",
254 "--new-rapi-certificate", "--new-cluster-domain-secret"]
255 AssertEqual(StartSSH(master["primary"],
256 utils.ShellQuoteArgs(cmd)).wait(), 0)
258 # Restore RAPI certificate
259 cmd = ["gnt-cluster", "renew-crypto", "--force",
260 "--rapi-certificate=%s" % rapi_cert_backup]
261 AssertEqual(StartSSH(master["primary"],
262 utils.ShellQuoteArgs(cmd)).wait(), 0)
264 cmd = ["rm", "-f", rapi_cert_backup]
265 AssertEqual(StartSSH(master["primary"],
266 utils.ShellQuoteArgs(cmd)).wait(), 0)
269 def TestClusterBurnin():
271 master = qa_config.GetMasterNode()
273 options = qa_config.get('options', {})
274 disk_template = options.get('burnin-disk-template', 'drbd')
275 parallel = options.get('burnin-in-parallel', False)
276 check_inst = options.get('burnin-check-instances', False)
277 do_rename = options.get('burnin-rename', '')
278 do_reboot = options.get('burnin-reboot', True)
279 reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
281 # Get as many instances as we need
285 num = qa_config.get('options', {}).get('burnin-instances', 1)
286 for _ in range(0, num):
287 instances.append(qa_config.AcquireInstance())
288 except qa_error.OutOfInstancesError:
289 print "Not enough instances, continuing anyway."
291 if len(instances) < 1:
292 raise qa_error.Error("Burnin needs at least one instance")
294 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
298 '--os=%s' % qa_config.get('os'),
299 '--disk-size=%s' % ",".join(qa_config.get('disk')),
300 '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
301 '--disk-template=%s' % disk_template]
303 cmd.append('--parallel')
304 cmd.append('--early-release')
306 cmd.append('--http-check')
308 cmd.append('--rename=%s' % do_rename)
310 cmd.append('--no-reboot')
312 cmd.append('--reboot-types=%s' % ",".join(reboot_types))
313 cmd += [inst['name'] for inst in instances]
314 AssertEqual(StartSSH(master['primary'],
315 utils.ShellQuoteArgs(cmd)).wait(), 0)
317 cmd = ['rm', '-f', script]
318 AssertEqual(StartSSH(master['primary'],
319 utils.ShellQuoteArgs(cmd)).wait(), 0)
321 for inst in instances:
322 qa_config.ReleaseInstance(inst)
325 def TestClusterMasterFailover():
326 """gnt-cluster master-failover"""
327 master = qa_config.GetMasterNode()
329 failovermaster = qa_config.AcquireNode(exclude=master)
331 cmd = ['gnt-cluster', 'master-failover']
332 AssertEqual(StartSSH(failovermaster['primary'],
333 utils.ShellQuoteArgs(cmd)).wait(), 0)
335 cmd = ['gnt-cluster', 'master-failover']
336 AssertEqual(StartSSH(master['primary'],
337 utils.ShellQuoteArgs(cmd)).wait(), 0)
339 qa_config.ReleaseNode(failovermaster)
342 def TestClusterCopyfile():
343 """gnt-cluster copyfile"""
344 master = qa_config.GetMasterNode()
346 uniqueid = utils.NewUUID()
348 # Create temporary file
349 f = tempfile.NamedTemporaryFile()
354 # Upload file to master node
355 testname = qa_utils.UploadFile(master['primary'], f.name)
357 # Copy file to all nodes
358 cmd = ['gnt-cluster', 'copyfile', testname]
359 AssertEqual(StartSSH(master['primary'],
360 utils.ShellQuoteArgs(cmd)).wait(), 0)
361 _CheckFileOnAllNodes(testname, uniqueid)
363 _RemoveFileFromAllNodes(testname)
366 def TestClusterCommand():
367 """gnt-cluster command"""
368 master = qa_config.GetMasterNode()
370 uniqueid = utils.NewUUID()
371 rfile = "/tmp/gnt%s" % utils.NewUUID()
372 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
373 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
374 "%s >%s" % (rcmd, rfile)])
377 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
378 _CheckFileOnAllNodes(rfile, uniqueid)
380 _RemoveFileFromAllNodes(rfile)
383 def TestClusterDestroy():
384 """gnt-cluster destroy"""
385 master = qa_config.GetMasterNode()
387 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
388 AssertEqual(StartSSH(master['primary'],
389 utils.ShellQuoteArgs(cmd)).wait(), 0)