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 utils
34 from qa_utils import AssertEqual, StartSSH
37 def _RemoveFileFromAllNodes(filename):
38 """Removes a file from all nodes.
41 for node in qa_config.get('nodes'):
42 cmd = ['rm', '-f', filename]
43 AssertEqual(StartSSH(node['primary'],
44 utils.ShellQuoteArgs(cmd)).wait(), 0)
47 def _CheckFileOnAllNodes(filename, content):
48 """Verifies the content of the given file on all nodes.
51 cmd = utils.ShellQuoteArgs(["cat", filename])
52 for node in qa_config.get('nodes'):
53 AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
57 def TestClusterInit():
58 """gnt-cluster init"""
59 master = qa_config.GetMasterNode()
61 cmd = ['gnt-cluster', 'init']
63 if master.get('secondary', None):
64 cmd.append('--secondary-ip=%s' % master['secondary'])
66 bridge = qa_config.get('bridge', None)
68 cmd.append('--bridge=%s' % bridge)
69 cmd.append('--master-netdev=%s' % bridge)
71 htype = qa_config.get('enabled-hypervisors', None)
73 cmd.append('--enabled-hypervisors=%s' % htype)
75 cmd.append(qa_config.get('name'))
77 AssertEqual(StartSSH(master['primary'],
78 utils.ShellQuoteArgs(cmd)).wait(), 0)
81 def TestClusterRename():
82 """gnt-cluster rename"""
83 master = qa_config.GetMasterNode()
85 cmd = ['gnt-cluster', 'rename', '-f']
87 original_name = qa_config.get('name')
88 rename_target = qa_config.get('rename', None)
89 if rename_target is None:
90 print qa_utils.FormatError('"rename" entry is missing')
93 cmd_1 = cmd + [rename_target]
94 cmd_2 = cmd + [original_name]
96 cmd_verify = ['gnt-cluster', 'verify']
98 AssertEqual(StartSSH(master['primary'],
99 utils.ShellQuoteArgs(cmd_1)).wait(), 0)
101 AssertEqual(StartSSH(master['primary'],
102 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
104 AssertEqual(StartSSH(master['primary'],
105 utils.ShellQuoteArgs(cmd_2)).wait(), 0)
107 AssertEqual(StartSSH(master['primary'],
108 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
111 def TestClusterVerify():
112 """gnt-cluster verify"""
113 master = qa_config.GetMasterNode()
115 cmd = ['gnt-cluster', 'verify']
116 AssertEqual(StartSSH(master['primary'],
117 utils.ShellQuoteArgs(cmd)).wait(), 0)
120 def TestClusterInfo():
121 """gnt-cluster info"""
122 master = qa_config.GetMasterNode()
124 cmd = ['gnt-cluster', 'info']
125 AssertEqual(StartSSH(master['primary'],
126 utils.ShellQuoteArgs(cmd)).wait(), 0)
129 def TestClusterGetmaster():
130 """gnt-cluster getmaster"""
131 master = qa_config.GetMasterNode()
133 cmd = ['gnt-cluster', 'getmaster']
134 AssertEqual(StartSSH(master['primary'],
135 utils.ShellQuoteArgs(cmd)).wait(), 0)
138 def TestClusterVersion():
139 """gnt-cluster version"""
140 master = qa_config.GetMasterNode()
142 cmd = ['gnt-cluster', 'version']
143 AssertEqual(StartSSH(master['primary'],
144 utils.ShellQuoteArgs(cmd)).wait(), 0)
147 def TestClusterBurnin():
149 master = qa_config.GetMasterNode()
151 options = qa_config.get('options', {})
152 disk_template = options.get('burnin-disk-template', 'drbd')
153 parallel = options.get('burnin-in-parallel', False)
154 check_inst = options.get('burnin-check-instances', False)
155 do_rename = options.get('burnin-rename', '')
157 # Get as many instances as we need
161 num = qa_config.get('options', {}).get('burnin-instances', 1)
162 for _ in range(0, num):
163 instances.append(qa_config.AcquireInstance())
164 except qa_error.OutOfInstancesError:
165 print "Not enough instances, continuing anyway."
167 if len(instances) < 1:
168 raise qa_error.Error("Burnin needs at least one instance")
170 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
175 '--os=%s' % qa_config.get('os'),
176 '--disk-size=%s' % ",".join(qa_config.get('disk')),
177 '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
178 '--disk-template=%s' % disk_template]
180 cmd.append('--parallel')
182 cmd.append('--http-check')
184 cmd.append('--rename=%s' % do_rename)
185 cmd += [inst['name'] for inst in instances]
186 AssertEqual(StartSSH(master['primary'],
187 utils.ShellQuoteArgs(cmd)).wait(), 0)
189 cmd = ['rm', '-f', script]
190 AssertEqual(StartSSH(master['primary'],
191 utils.ShellQuoteArgs(cmd)).wait(), 0)
193 for inst in instances:
194 qa_config.ReleaseInstance(inst)
197 def TestClusterMasterFailover():
198 """gnt-cluster masterfailover"""
199 master = qa_config.GetMasterNode()
201 failovermaster = qa_config.AcquireNode(exclude=master)
203 cmd = ['gnt-cluster', 'masterfailover']
204 AssertEqual(StartSSH(failovermaster['primary'],
205 utils.ShellQuoteArgs(cmd)).wait(), 0)
207 cmd = ['gnt-cluster', 'masterfailover']
208 AssertEqual(StartSSH(master['primary'],
209 utils.ShellQuoteArgs(cmd)).wait(), 0)
211 qa_config.ReleaseNode(failovermaster)
214 def TestClusterCopyfile():
215 """gnt-cluster copyfile"""
216 master = qa_config.GetMasterNode()
218 uniqueid = utils.NewUUID()
220 # Create temporary file
221 f = tempfile.NamedTemporaryFile()
226 # Upload file to master node
227 testname = qa_utils.UploadFile(master['primary'], f.name)
229 # Copy file to all nodes
230 cmd = ['gnt-cluster', 'copyfile', testname]
231 AssertEqual(StartSSH(master['primary'],
232 utils.ShellQuoteArgs(cmd)).wait(), 0)
233 _CheckFileOnAllNodes(testname, uniqueid)
235 _RemoveFileFromAllNodes(testname)
238 def TestClusterCommand():
239 """gnt-cluster command"""
240 master = qa_config.GetMasterNode()
242 uniqueid = utils.NewUUID()
243 rfile = "/tmp/gnt%s" % utils.NewUUID()
244 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
245 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
246 "%s >%s" % (rcmd, rfile)])
249 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
250 _CheckFileOnAllNodes(rfile, uniqueid)
252 _RemoveFileFromAllNodes(rfile)
255 def TestClusterDestroy():
256 """gnt-cluster destroy"""
257 master = qa_config.GetMasterNode()
259 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
260 AssertEqual(StartSSH(master['primary'],
261 utils.ShellQuoteArgs(cmd)).wait(), 0)