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():
59 """gnt-cluster init"""
60 master = qa_config.GetMasterNode()
62 cmd = ['gnt-cluster', 'init']
64 if master.get('secondary', None):
65 cmd.append('--secondary-ip=%s' % master['secondary'])
67 bridge = qa_config.get('bridge', None)
69 cmd.append('--bridge=%s' % bridge)
70 cmd.append('--master-netdev=%s' % bridge)
72 htype = qa_config.get('enabled-hypervisors', None)
74 cmd.append('--enabled-hypervisors=%s' % htype)
76 cmd.append(qa_config.get('name'))
78 AssertEqual(StartSSH(master['primary'],
79 utils.ShellQuoteArgs(cmd)).wait(), 0)
82 def TestClusterRename():
83 """gnt-cluster rename"""
84 master = qa_config.GetMasterNode()
86 cmd = ['gnt-cluster', 'rename', '-f']
88 original_name = qa_config.get('name')
89 rename_target = qa_config.get('rename', None)
90 if rename_target is None:
91 print qa_utils.FormatError('"rename" entry is missing')
94 cmd_1 = cmd + [rename_target]
95 cmd_2 = cmd + [original_name]
97 cmd_verify = ['gnt-cluster', 'verify']
99 AssertEqual(StartSSH(master['primary'],
100 utils.ShellQuoteArgs(cmd_1)).wait(), 0)
102 AssertEqual(StartSSH(master['primary'],
103 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
105 AssertEqual(StartSSH(master['primary'],
106 utils.ShellQuoteArgs(cmd_2)).wait(), 0)
108 AssertEqual(StartSSH(master['primary'],
109 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
112 def TestClusterVerify():
113 """gnt-cluster verify"""
114 master = qa_config.GetMasterNode()
116 cmd = ['gnt-cluster', 'verify']
117 AssertEqual(StartSSH(master['primary'],
118 utils.ShellQuoteArgs(cmd)).wait(), 0)
121 def TestClusterInfo():
122 """gnt-cluster info"""
123 master = qa_config.GetMasterNode()
125 cmd = ['gnt-cluster', 'info']
126 AssertEqual(StartSSH(master['primary'],
127 utils.ShellQuoteArgs(cmd)).wait(), 0)
130 def TestClusterGetmaster():
131 """gnt-cluster getmaster"""
132 master = qa_config.GetMasterNode()
134 cmd = ['gnt-cluster', 'getmaster']
135 AssertEqual(StartSSH(master['primary'],
136 utils.ShellQuoteArgs(cmd)).wait(), 0)
139 def TestClusterVersion():
140 """gnt-cluster version"""
141 master = qa_config.GetMasterNode()
143 cmd = ['gnt-cluster', 'version']
144 AssertEqual(StartSSH(master['primary'],
145 utils.ShellQuoteArgs(cmd)).wait(), 0)
148 def TestClusterRenewCrypto():
149 """gnt-cluster renew-crypto"""
150 master = qa_config.GetMasterNode()
152 # Conflicting options
153 cmd = ["gnt-cluster", "renew-crypto", "--force",
154 "--new-cluster-certificate", "--new-confd-hmac-key"]
156 ["--new-rapi-certificate", "--rapi-certificate=/dev/null"],
157 ["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"],
159 for i in conflicting:
160 AssertNotEqual(StartSSH(master["primary"],
161 utils.ShellQuoteArgs(cmd + i)).wait(), 0)
163 # Invalid RAPI certificate
164 cmd = ["gnt-cluster", "renew-crypto", "--force",
165 "--rapi-certificate=/dev/null"]
166 AssertNotEqual(StartSSH(master["primary"],
167 utils.ShellQuoteArgs(cmd)).wait(), 0)
169 # Custom RAPI certificate
170 fh = tempfile.NamedTemporaryFile()
172 # Ensure certificate doesn't cause "gnt-cluster verify" to complain
173 validity = constants.SSL_CERT_EXPIRATION_WARN * 3
175 utils.GenerateSelfSignedSslCert(fh.name, validity=validity)
177 tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
179 cmd = ["gnt-cluster", "renew-crypto", "--force",
180 "--rapi-certificate=%s" % tmpcert]
181 AssertEqual(StartSSH(master["primary"],
182 utils.ShellQuoteArgs(cmd)).wait(), 0)
184 cmd = ["rm", "-f", tmpcert]
185 AssertEqual(StartSSH(master["primary"],
186 utils.ShellQuoteArgs(cmd)).wait(), 0)
188 # Custom cluster domain secret
189 cds_fh = tempfile.NamedTemporaryFile()
190 cds_fh.write(utils.GenerateSecret())
194 tmpcds = qa_utils.UploadFile(master["primary"], cds_fh.name)
196 cmd = ["gnt-cluster", "renew-crypto", "--force",
197 "--cluster-domain-secret=%s" % tmpcds]
198 AssertEqual(StartSSH(master["primary"],
199 utils.ShellQuoteArgs(cmd)).wait(), 0)
201 cmd = ["rm", "-f", tmpcds]
202 AssertEqual(StartSSH(master["primary"],
203 utils.ShellQuoteArgs(cmd)).wait(), 0)
206 cmd = ["gnt-cluster", "renew-crypto", "--force",
207 "--new-cluster-certificate", "--new-confd-hmac-key",
208 "--new-rapi-certificate", "--new-cluster-domain-secret"]
209 AssertEqual(StartSSH(master["primary"],
210 utils.ShellQuoteArgs(cmd)).wait(), 0)
213 def TestClusterBurnin():
215 master = qa_config.GetMasterNode()
217 options = qa_config.get('options', {})
218 disk_template = options.get('burnin-disk-template', 'drbd')
219 parallel = options.get('burnin-in-parallel', False)
220 check_inst = options.get('burnin-check-instances', False)
221 do_rename = options.get('burnin-rename', '')
223 # Get as many instances as we need
227 num = qa_config.get('options', {}).get('burnin-instances', 1)
228 for _ in range(0, num):
229 instances.append(qa_config.AcquireInstance())
230 except qa_error.OutOfInstancesError:
231 print "Not enough instances, continuing anyway."
233 if len(instances) < 1:
234 raise qa_error.Error("Burnin needs at least one instance")
236 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
241 '--os=%s' % qa_config.get('os'),
242 '--disk-size=%s' % ",".join(qa_config.get('disk')),
243 '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
244 '--disk-template=%s' % disk_template]
246 cmd.append('--parallel')
248 cmd.append('--http-check')
250 cmd.append('--rename=%s' % do_rename)
251 cmd += [inst['name'] for inst in instances]
252 AssertEqual(StartSSH(master['primary'],
253 utils.ShellQuoteArgs(cmd)).wait(), 0)
255 cmd = ['rm', '-f', script]
256 AssertEqual(StartSSH(master['primary'],
257 utils.ShellQuoteArgs(cmd)).wait(), 0)
259 for inst in instances:
260 qa_config.ReleaseInstance(inst)
263 def TestClusterMasterFailover():
264 """gnt-cluster masterfailover"""
265 master = qa_config.GetMasterNode()
267 failovermaster = qa_config.AcquireNode(exclude=master)
269 cmd = ['gnt-cluster', 'masterfailover']
270 AssertEqual(StartSSH(failovermaster['primary'],
271 utils.ShellQuoteArgs(cmd)).wait(), 0)
273 cmd = ['gnt-cluster', 'masterfailover']
274 AssertEqual(StartSSH(master['primary'],
275 utils.ShellQuoteArgs(cmd)).wait(), 0)
277 qa_config.ReleaseNode(failovermaster)
280 def TestClusterCopyfile():
281 """gnt-cluster copyfile"""
282 master = qa_config.GetMasterNode()
284 uniqueid = utils.NewUUID()
286 # Create temporary file
287 f = tempfile.NamedTemporaryFile()
292 # Upload file to master node
293 testname = qa_utils.UploadFile(master['primary'], f.name)
295 # Copy file to all nodes
296 cmd = ['gnt-cluster', 'copyfile', testname]
297 AssertEqual(StartSSH(master['primary'],
298 utils.ShellQuoteArgs(cmd)).wait(), 0)
299 _CheckFileOnAllNodes(testname, uniqueid)
301 _RemoveFileFromAllNodes(testname)
304 def TestClusterCommand():
305 """gnt-cluster command"""
306 master = qa_config.GetMasterNode()
308 uniqueid = utils.NewUUID()
309 rfile = "/tmp/gnt%s" % utils.NewUUID()
310 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
311 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
312 "%s >%s" % (rcmd, rfile)])
315 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
316 _CheckFileOnAllNodes(rfile, uniqueid)
318 _RemoveFileFromAllNodes(rfile)
321 def TestClusterDestroy():
322 """gnt-cluster destroy"""
323 master = qa_config.GetMasterNode()
325 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
326 AssertEqual(StartSSH(master['primary'],
327 utils.ShellQuoteArgs(cmd)).wait(), 0)