1 # Copyright (C) 2007 Google Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 """Cluster related QA tests.
25 from ganeti import utils
31 from qa_utils import AssertEqual, StartSSH
34 def _RemoveFileFromAllNodes(filename):
35 """Removes a file from all nodes.
38 for node in qa_config.get('nodes'):
39 cmd = ['rm', '-f', filename]
40 AssertEqual(StartSSH(node['primary'],
41 utils.ShellQuoteArgs(cmd)).wait(), 0)
44 def _CheckFileOnAllNodes(filename, content):
45 """Verifies the content of the given file on all nodes.
48 cmd = utils.ShellQuoteArgs(["cat", filename])
49 for node in qa_config.get('nodes'):
50 AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
54 @qa_utils.DefineHook('cluster-init')
55 def TestClusterInit():
56 """gnt-cluster init"""
57 master = qa_config.GetMasterNode()
59 cmd = ['gnt-cluster', 'init']
61 if master.get('secondary', None):
62 cmd.append('--secondary-ip=%s' % master['secondary'])
64 bridge = qa_config.get('bridge', None)
66 cmd.append('--bridge=%s' % bridge)
67 cmd.append('--master-netdev=%s' % bridge)
69 htype = qa_config.get('hypervisor-type', None)
71 cmd.append('--hypervisor-type=%s' % htype)
73 cmd.append(qa_config.get('name'))
75 AssertEqual(StartSSH(master['primary'],
76 utils.ShellQuoteArgs(cmd)).wait(), 0)
79 @qa_utils.DefineHook('cluster-rename')
80 def TestClusterRename():
81 """gnt-cluster rename"""
82 master = qa_config.GetMasterNode()
84 cmd = ['gnt-cluster', 'rename', '-f']
86 original_name = qa_config.get('name')
87 rename_target = qa_config.get('rename', None)
88 if rename_target is None:
89 print qa_utils.FormatError('"rename" entry is missing')
92 cmd_1 = cmd + [rename_target]
93 cmd_2 = cmd + [original_name]
95 cmd_verify = ['gnt-cluster', 'verify']
97 AssertEqual(StartSSH(master['primary'],
98 utils.ShellQuoteArgs(cmd_1)).wait(), 0)
100 AssertEqual(StartSSH(master['primary'],
101 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
103 AssertEqual(StartSSH(master['primary'],
104 utils.ShellQuoteArgs(cmd_2)).wait(), 0)
106 AssertEqual(StartSSH(master['primary'],
107 utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
110 @qa_utils.DefineHook('cluster-verify')
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 @qa_utils.DefineHook('cluster-info')
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 @qa_utils.DefineHook('cluster-getmaster')
131 def TestClusterGetmaster():
132 """gnt-cluster getmaster"""
133 master = qa_config.GetMasterNode()
135 cmd = ['gnt-cluster', 'getmaster']
136 AssertEqual(StartSSH(master['primary'],
137 utils.ShellQuoteArgs(cmd)).wait(), 0)
140 @qa_utils.DefineHook('cluster-version')
141 def TestClusterVersion():
142 """gnt-cluster version"""
143 master = qa_config.GetMasterNode()
145 cmd = ['gnt-cluster', 'version']
146 AssertEqual(StartSSH(master['primary'],
147 utils.ShellQuoteArgs(cmd)).wait(), 0)
150 @qa_utils.DefineHook('cluster-burnin')
151 def TestClusterBurnin():
153 master = qa_config.GetMasterNode()
155 disk_template = (qa_config.get('options', {}).
156 get('burnin-disk-template', 'remote_raid1'))
158 # Get as many instances as we need
162 num = qa_config.get('options', {}).get('burnin-instances', 1)
163 for _ in xrange(0, num):
164 instances.append(qa_config.AcquireInstance())
165 except qa_error.OutOfInstancesError:
166 print "Not enough instances, continuing anyway."
168 if len(instances) < 1:
169 raise qa_error.Error("Burnin needs at least one instance")
171 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
175 '--os=%s' % qa_config.get('os'),
176 '--os-size=%s' % qa_config.get('os-size'),
177 '--swap-size=%s' % qa_config.get('swap-size'),
178 '--disk-template=%s' % disk_template]
179 cmd += [inst['name'] for inst in instances]
180 AssertEqual(StartSSH(master['primary'],
181 utils.ShellQuoteArgs(cmd)).wait(), 0)
183 cmd = ['rm', '-f', script]
184 AssertEqual(StartSSH(master['primary'],
185 utils.ShellQuoteArgs(cmd)).wait(), 0)
187 for inst in instances:
188 qa_config.ReleaseInstance(inst)
191 @qa_utils.DefineHook('cluster-master-failover')
192 def TestClusterMasterFailover():
193 """gnt-cluster masterfailover"""
194 master = qa_config.GetMasterNode()
196 failovermaster = qa_config.AcquireNode(exclude=master)
198 cmd = ['gnt-cluster', 'masterfailover']
199 AssertEqual(StartSSH(failovermaster['primary'],
200 utils.ShellQuoteArgs(cmd)).wait(), 0)
202 cmd = ['gnt-cluster', 'masterfailover']
203 AssertEqual(StartSSH(master['primary'],
204 utils.ShellQuoteArgs(cmd)).wait(), 0)
206 qa_config.ReleaseNode(failovermaster)
209 @qa_utils.DefineHook('cluster-copyfile')
210 def TestClusterCopyfile():
211 """gnt-cluster copyfile"""
212 master = qa_config.GetMasterNode()
214 uniqueid = utils.NewUUID()
216 # Create temporary file
217 f = tempfile.NamedTemporaryFile()
222 # Upload file to master node
223 testname = qa_utils.UploadFile(master['primary'], f.name)
225 # Copy file to all nodes
226 cmd = ['gnt-cluster', 'copyfile', testname]
227 AssertEqual(StartSSH(master['primary'],
228 utils.ShellQuoteArgs(cmd)).wait(), 0)
229 _CheckFileOnAllNodes(testname, uniqueid)
231 _RemoveFileFromAllNodes(testname)
234 @qa_utils.DefineHook('cluster-command')
235 def TestClusterCommand():
236 """gnt-cluster command"""
237 master = qa_config.GetMasterNode()
239 uniqueid = utils.NewUUID()
240 rfile = "/tmp/gnt%s" % utils.NewUUID()
241 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
242 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
243 "%s >%s" % (rcmd, rfile)])
246 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
247 _CheckFileOnAllNodes(rfile, uniqueid)
249 _RemoveFileFromAllNodes(rfile)
252 @qa_utils.DefineHook('cluster-destroy')
253 def TestClusterDestroy():
254 """gnt-cluster destroy"""
255 master = qa_config.GetMasterNode()
257 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
258 AssertEqual(StartSSH(master['primary'],
259 utils.ShellQuoteArgs(cmd)).wait(), 0)