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 @qa_utils.DefineHook('cluster-init')
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('hypervisor-type', None)
74 cmd.append('--hypervisor-type=%s' % htype)
76 cmd.append(qa_config.get('name'))
78 AssertEqual(StartSSH(master['primary'],
79 utils.ShellQuoteArgs(cmd)).wait(), 0)
82 @qa_utils.DefineHook('cluster-rename')
83 def TestClusterRename():
84 """gnt-cluster rename"""
85 master = qa_config.GetMasterNode()
87 cmd = ['gnt-cluster', 'rename', '-f']
89 original_name = qa_config.get('name')
90 rename_target = qa_config.get('rename', None)
91 if rename_target is None:
92 print qa_utils.FormatError('"rename" entry is missing')
95 cmd_1 = cmd + [rename_target]
96 cmd_2 = cmd + [original_name]
98 cmd_verify = ['gnt-cluster', 'verify']
100 AssertEqual(StartSSH(master['primary'],
101 utils.ShellQuoteArgs(cmd_1)).wait(), 0)
103 AssertEqual(StartSSH(master['primary'],
104 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
106 AssertEqual(StartSSH(master['primary'],
107 utils.ShellQuoteArgs(cmd_2)).wait(), 0)
109 AssertEqual(StartSSH(master['primary'],
110 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
113 @qa_utils.DefineHook('cluster-verify')
114 def TestClusterVerify():
115 """gnt-cluster verify"""
116 master = qa_config.GetMasterNode()
118 cmd = ['gnt-cluster', 'verify']
119 AssertEqual(StartSSH(master['primary'],
120 utils.ShellQuoteArgs(cmd)).wait(), 0)
123 @qa_utils.DefineHook('cluster-info')
124 def TestClusterInfo():
125 """gnt-cluster info"""
126 master = qa_config.GetMasterNode()
128 cmd = ['gnt-cluster', 'info']
129 AssertEqual(StartSSH(master['primary'],
130 utils.ShellQuoteArgs(cmd)).wait(), 0)
133 @qa_utils.DefineHook('cluster-getmaster')
134 def TestClusterGetmaster():
135 """gnt-cluster getmaster"""
136 master = qa_config.GetMasterNode()
138 cmd = ['gnt-cluster', 'getmaster']
139 AssertEqual(StartSSH(master['primary'],
140 utils.ShellQuoteArgs(cmd)).wait(), 0)
143 @qa_utils.DefineHook('cluster-version')
144 def TestClusterVersion():
145 """gnt-cluster version"""
146 master = qa_config.GetMasterNode()
148 cmd = ['gnt-cluster', 'version']
149 AssertEqual(StartSSH(master['primary'],
150 utils.ShellQuoteArgs(cmd)).wait(), 0)
153 @qa_utils.DefineHook('cluster-burnin')
154 def TestClusterBurnin():
156 master = qa_config.GetMasterNode()
158 disk_template = (qa_config.get('options', {}).
159 get('burnin-disk-template', 'drbd'))
161 # Get as many instances as we need
165 num = qa_config.get('options', {}).get('burnin-instances', 1)
166 for _ in xrange(0, num):
167 instances.append(qa_config.AcquireInstance())
168 except qa_error.OutOfInstancesError:
169 print "Not enough instances, continuing anyway."
171 if len(instances) < 1:
172 raise qa_error.Error("Burnin needs at least one instance")
174 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
178 '--os=%s' % qa_config.get('os'),
179 '--os-size=%s' % qa_config.get('os-size'),
180 '--swap-size=%s' % qa_config.get('swap-size'),
181 '--disk-template=%s' % disk_template]
182 cmd += [inst['name'] for inst in instances]
183 AssertEqual(StartSSH(master['primary'],
184 utils.ShellQuoteArgs(cmd)).wait(), 0)
186 cmd = ['rm', '-f', script]
187 AssertEqual(StartSSH(master['primary'],
188 utils.ShellQuoteArgs(cmd)).wait(), 0)
190 for inst in instances:
191 qa_config.ReleaseInstance(inst)
194 @qa_utils.DefineHook('cluster-master-failover')
195 def TestClusterMasterFailover():
196 """gnt-cluster masterfailover"""
197 master = qa_config.GetMasterNode()
199 failovermaster = qa_config.AcquireNode(exclude=master)
201 cmd = ['gnt-cluster', 'masterfailover']
202 AssertEqual(StartSSH(failovermaster['primary'],
203 utils.ShellQuoteArgs(cmd)).wait(), 0)
205 cmd = ['gnt-cluster', 'masterfailover']
206 AssertEqual(StartSSH(master['primary'],
207 utils.ShellQuoteArgs(cmd)).wait(), 0)
209 qa_config.ReleaseNode(failovermaster)
212 @qa_utils.DefineHook('cluster-copyfile')
213 def TestClusterCopyfile():
214 """gnt-cluster copyfile"""
215 master = qa_config.GetMasterNode()
217 uniqueid = utils.NewUUID()
219 # Create temporary file
220 f = tempfile.NamedTemporaryFile()
225 # Upload file to master node
226 testname = qa_utils.UploadFile(master['primary'], f.name)
228 # Copy file to all nodes
229 cmd = ['gnt-cluster', 'copyfile', testname]
230 AssertEqual(StartSSH(master['primary'],
231 utils.ShellQuoteArgs(cmd)).wait(), 0)
232 _CheckFileOnAllNodes(testname, uniqueid)
234 _RemoveFileFromAllNodes(testname)
237 @qa_utils.DefineHook('cluster-command')
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 @qa_utils.DefineHook('cluster-destroy')
256 def TestClusterDestroy():
257 """gnt-cluster destroy"""
258 master = qa_config.GetMasterNode()
260 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
261 AssertEqual(StartSSH(master['primary'],
262 utils.ShellQuoteArgs(cmd)).wait(), 0)