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('hypervisor-type', None)
73 cmd.append('--hypervisor-type=%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 disk_template = (qa_config.get('options', {}).
152 get('burnin-disk-template', 'drbd'))
154 # Get as many instances as we need
158 num = qa_config.get('options', {}).get('burnin-instances', 1)
159 for _ in xrange(0, num):
160 instances.append(qa_config.AcquireInstance())
161 except qa_error.OutOfInstancesError:
162 print "Not enough instances, continuing anyway."
164 if len(instances) < 1:
165 raise qa_error.Error("Burnin needs at least one instance")
167 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
171 '--os=%s' % qa_config.get('os'),
172 '--os-size=%s' % qa_config.get('os-size'),
173 '--swap-size=%s' % qa_config.get('swap-size'),
174 '--disk-template=%s' % disk_template]
175 cmd += [inst['name'] for inst in instances]
176 AssertEqual(StartSSH(master['primary'],
177 utils.ShellQuoteArgs(cmd)).wait(), 0)
179 cmd = ['rm', '-f', script]
180 AssertEqual(StartSSH(master['primary'],
181 utils.ShellQuoteArgs(cmd)).wait(), 0)
183 for inst in instances:
184 qa_config.ReleaseInstance(inst)
187 def TestClusterMasterFailover():
188 """gnt-cluster masterfailover"""
189 master = qa_config.GetMasterNode()
191 failovermaster = qa_config.AcquireNode(exclude=master)
193 cmd = ['gnt-cluster', 'masterfailover']
194 AssertEqual(StartSSH(failovermaster['primary'],
195 utils.ShellQuoteArgs(cmd)).wait(), 0)
197 cmd = ['gnt-cluster', 'masterfailover']
198 AssertEqual(StartSSH(master['primary'],
199 utils.ShellQuoteArgs(cmd)).wait(), 0)
201 qa_config.ReleaseNode(failovermaster)
204 def TestClusterCopyfile():
205 """gnt-cluster copyfile"""
206 master = qa_config.GetMasterNode()
208 uniqueid = utils.NewUUID()
210 # Create temporary file
211 f = tempfile.NamedTemporaryFile()
216 # Upload file to master node
217 testname = qa_utils.UploadFile(master['primary'], f.name)
219 # Copy file to all nodes
220 cmd = ['gnt-cluster', 'copyfile', testname]
221 AssertEqual(StartSSH(master['primary'],
222 utils.ShellQuoteArgs(cmd)).wait(), 0)
223 _CheckFileOnAllNodes(testname, uniqueid)
225 _RemoveFileFromAllNodes(testname)
228 def TestClusterCommand():
229 """gnt-cluster command"""
230 master = qa_config.GetMasterNode()
232 uniqueid = utils.NewUUID()
233 rfile = "/tmp/gnt%s" % utils.NewUUID()
234 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
235 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
236 "%s >%s" % (rcmd, rfile)])
239 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
240 _CheckFileOnAllNodes(rfile, uniqueid)
242 _RemoveFileFromAllNodes(rfile)
245 def TestClusterDestroy():
246 """gnt-cluster destroy"""
247 master = qa_config.GetMasterNode()
249 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
250 AssertEqual(StartSSH(master['primary'],
251 utils.ShellQuoteArgs(cmd)).wait(), 0)