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 cmd.append(qa_config.get('name'))
71 AssertEqual(StartSSH(master['primary'],
72 utils.ShellQuoteArgs(cmd)).wait(), 0)
75 @qa_utils.DefineHook('cluster-verify')
76 def TestClusterVerify():
77 """gnt-cluster verify"""
78 master = qa_config.GetMasterNode()
80 cmd = ['gnt-cluster', 'verify']
81 AssertEqual(StartSSH(master['primary'],
82 utils.ShellQuoteArgs(cmd)).wait(), 0)
85 @qa_utils.DefineHook('cluster-info')
86 def TestClusterInfo():
87 """gnt-cluster info"""
88 master = qa_config.GetMasterNode()
90 cmd = ['gnt-cluster', 'info']
91 AssertEqual(StartSSH(master['primary'],
92 utils.ShellQuoteArgs(cmd)).wait(), 0)
95 @qa_utils.DefineHook('cluster-getmaster')
96 def TestClusterGetmaster():
97 """gnt-cluster getmaster"""
98 master = qa_config.GetMasterNode()
100 cmd = ['gnt-cluster', 'getmaster']
101 AssertEqual(StartSSH(master['primary'],
102 utils.ShellQuoteArgs(cmd)).wait(), 0)
105 @qa_utils.DefineHook('cluster-version')
106 def TestClusterVersion():
107 """gnt-cluster version"""
108 master = qa_config.GetMasterNode()
110 cmd = ['gnt-cluster', 'version']
111 AssertEqual(StartSSH(master['primary'],
112 utils.ShellQuoteArgs(cmd)).wait(), 0)
115 @qa_utils.DefineHook('cluster-burnin')
116 def TestClusterBurnin():
118 master = qa_config.GetMasterNode()
120 disk_template = (qa_config.get('options', {}).
121 get('burnin-disk-template', 'remote_raid1'))
123 # Get as many instances as we need
127 num = qa_config.get('options', {}).get('burnin-instances', 1)
128 for _ in xrange(0, num):
129 instances.append(qa_config.AcquireInstance())
130 except qa_error.OutOfInstancesError:
131 print "Not enough instances, continuing anyway."
133 if len(instances) < 1:
134 raise qa_error.Error("Burnin needs at least one instance")
136 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
140 '--os=%s' % qa_config.get('os'),
141 '--os-size=%s' % qa_config.get('os-size'),
142 '--swap-size=%s' % qa_config.get('swap-size'),
143 '--disk-template=%s' % disk_template]
144 cmd += [inst['name'] for inst in instances]
145 AssertEqual(StartSSH(master['primary'],
146 utils.ShellQuoteArgs(cmd)).wait(), 0)
148 cmd = ['rm', '-f', script]
149 AssertEqual(StartSSH(master['primary'],
150 utils.ShellQuoteArgs(cmd)).wait(), 0)
152 for inst in instances:
153 qa_config.ReleaseInstance(inst)
156 @qa_utils.DefineHook('cluster-master-failover')
157 def TestClusterMasterFailover():
158 """gnt-cluster masterfailover"""
159 master = qa_config.GetMasterNode()
161 failovermaster = qa_config.AcquireNode(exclude=master)
163 cmd = ['gnt-cluster', 'masterfailover']
164 AssertEqual(StartSSH(failovermaster['primary'],
165 utils.ShellQuoteArgs(cmd)).wait(), 0)
167 cmd = ['gnt-cluster', 'masterfailover']
168 AssertEqual(StartSSH(master['primary'],
169 utils.ShellQuoteArgs(cmd)).wait(), 0)
171 qa_config.ReleaseNode(failovermaster)
174 @qa_utils.DefineHook('cluster-copyfile')
175 def TestClusterCopyfile():
176 """gnt-cluster copyfile"""
177 master = qa_config.GetMasterNode()
179 uniqueid = utils.NewUUID()
181 # Create temporary file
182 f = tempfile.NamedTemporaryFile()
187 # Upload file to master node
188 testname = qa_utils.UploadFile(master['primary'], f.name)
190 # Copy file to all nodes
191 cmd = ['gnt-cluster', 'copyfile', testname]
192 AssertEqual(StartSSH(master['primary'],
193 utils.ShellQuoteArgs(cmd)).wait(), 0)
194 _CheckFileOnAllNodes(testname, uniqueid)
196 _RemoveFileFromAllNodes(testname)
199 @qa_utils.DefineHook('cluster-command')
200 def TestClusterCommand():
201 """gnt-cluster command"""
202 master = qa_config.GetMasterNode()
204 uniqueid = utils.NewUUID()
205 rfile = "/tmp/gnt%s" % utils.NewUUID()
206 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
207 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
208 "%s >%s" % (rcmd, rfile)])
211 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
212 _CheckFileOnAllNodes(rfile, uniqueid)
214 _RemoveFileFromAllNodes(rfile)
217 @qa_utils.DefineHook('cluster-destroy')
218 def TestClusterDestroy():
219 """gnt-cluster destroy"""
220 master = qa_config.GetMasterNode()
222 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
223 AssertEqual(StartSSH(master['primary'],
224 utils.ShellQuoteArgs(cmd)).wait(), 0)