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-hmac-key",
155 "--new-rapi-certificate", "--rapi-certificate=/dev/null"]
156 AssertNotEqual(StartSSH(master["primary"],
157 utils.ShellQuoteArgs(cmd)).wait(), 0)
159 # Invalid RAPI certificate
160 cmd = ["gnt-cluster", "renew-crypto", "--force",
161 "--rapi-certificate=/dev/null"]
162 AssertNotEqual(StartSSH(master["primary"],
163 utils.ShellQuoteArgs(cmd)).wait(), 0)
165 # Custom RAPI certificate
166 fh = tempfile.NamedTemporaryFile()
168 # Ensure certificate doesn't cause "gnt-cluster verify" to complain
169 validity = constants.SSL_CERT_EXPIRATION_WARN * 3
171 utils.GenerateSelfSignedSslCert(fh.name, validity=validity)
173 tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
175 cmd = ["gnt-cluster", "renew-crypto", "--force",
176 "--rapi-certificate=%s" % tmpcert]
177 AssertEqual(StartSSH(master["primary"],
178 utils.ShellQuoteArgs(cmd)).wait(), 0)
180 cmd = ["rm", "-f", tmpcert]
181 AssertEqual(StartSSH(master["primary"],
182 utils.ShellQuoteArgs(cmd)).wait(), 0)
185 cmd = ["gnt-cluster", "renew-crypto", "--force",
186 "--new-cluster-certificate", "--new-hmac-key",
187 "--new-rapi-certificate"]
188 AssertEqual(StartSSH(master["primary"],
189 utils.ShellQuoteArgs(cmd)).wait(), 0)
192 def TestClusterBurnin():
194 master = qa_config.GetMasterNode()
196 options = qa_config.get('options', {})
197 disk_template = options.get('burnin-disk-template', 'drbd')
198 parallel = options.get('burnin-in-parallel', False)
199 check_inst = options.get('burnin-check-instances', False)
200 do_rename = options.get('burnin-rename', '')
202 # Get as many instances as we need
206 num = qa_config.get('options', {}).get('burnin-instances', 1)
207 for _ in range(0, num):
208 instances.append(qa_config.AcquireInstance())
209 except qa_error.OutOfInstancesError:
210 print "Not enough instances, continuing anyway."
212 if len(instances) < 1:
213 raise qa_error.Error("Burnin needs at least one instance")
215 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
220 '--os=%s' % qa_config.get('os'),
221 '--disk-size=%s' % ",".join(qa_config.get('disk')),
222 '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
223 '--disk-template=%s' % disk_template]
225 cmd.append('--parallel')
227 cmd.append('--http-check')
229 cmd.append('--rename=%s' % do_rename)
230 cmd += [inst['name'] for inst in instances]
231 AssertEqual(StartSSH(master['primary'],
232 utils.ShellQuoteArgs(cmd)).wait(), 0)
234 cmd = ['rm', '-f', script]
235 AssertEqual(StartSSH(master['primary'],
236 utils.ShellQuoteArgs(cmd)).wait(), 0)
238 for inst in instances:
239 qa_config.ReleaseInstance(inst)
242 def TestClusterMasterFailover():
243 """gnt-cluster masterfailover"""
244 master = qa_config.GetMasterNode()
246 failovermaster = qa_config.AcquireNode(exclude=master)
248 cmd = ['gnt-cluster', 'masterfailover']
249 AssertEqual(StartSSH(failovermaster['primary'],
250 utils.ShellQuoteArgs(cmd)).wait(), 0)
252 cmd = ['gnt-cluster', 'masterfailover']
253 AssertEqual(StartSSH(master['primary'],
254 utils.ShellQuoteArgs(cmd)).wait(), 0)
256 qa_config.ReleaseNode(failovermaster)
259 def TestClusterCopyfile():
260 """gnt-cluster copyfile"""
261 master = qa_config.GetMasterNode()
263 uniqueid = utils.NewUUID()
265 # Create temporary file
266 f = tempfile.NamedTemporaryFile()
271 # Upload file to master node
272 testname = qa_utils.UploadFile(master['primary'], f.name)
274 # Copy file to all nodes
275 cmd = ['gnt-cluster', 'copyfile', testname]
276 AssertEqual(StartSSH(master['primary'],
277 utils.ShellQuoteArgs(cmd)).wait(), 0)
278 _CheckFileOnAllNodes(testname, uniqueid)
280 _RemoveFileFromAllNodes(testname)
283 def TestClusterCommand():
284 """gnt-cluster command"""
285 master = qa_config.GetMasterNode()
287 uniqueid = utils.NewUUID()
288 rfile = "/tmp/gnt%s" % utils.NewUUID()
289 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
290 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
291 "%s >%s" % (rcmd, rfile)])
294 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
295 _CheckFileOnAllNodes(rfile, uniqueid)
297 _RemoveFileFromAllNodes(rfile)
300 def TestClusterDestroy():
301 """gnt-cluster destroy"""
302 master = qa_config.GetMasterNode()
304 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
305 AssertEqual(StartSSH(master['primary'],
306 utils.ShellQuoteArgs(cmd)).wait(), 0)