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 def TestClusterInit():
55 """gnt-cluster init"""
56 master = qa_config.GetMasterNode()
58 cmd = ['gnt-cluster', 'init']
60 if master.get('secondary', None):
61 cmd.append('--secondary-ip=%s' % master['secondary'])
63 bridge = qa_config.get('bridge', None)
65 cmd.append('--bridge=%s' % bridge)
66 cmd.append('--master-netdev=%s' % bridge)
68 cmd.append(qa_config.get('name'))
70 AssertEqual(StartSSH(master['primary'],
71 utils.ShellQuoteArgs(cmd)).wait(), 0)
74 def TestClusterVerify():
75 """gnt-cluster verify"""
76 master = qa_config.GetMasterNode()
78 cmd = ['gnt-cluster', 'verify']
79 AssertEqual(StartSSH(master['primary'],
80 utils.ShellQuoteArgs(cmd)).wait(), 0)
83 def TestClusterInfo():
84 """gnt-cluster info"""
85 master = qa_config.GetMasterNode()
87 cmd = ['gnt-cluster', 'info']
88 AssertEqual(StartSSH(master['primary'],
89 utils.ShellQuoteArgs(cmd)).wait(), 0)
92 def TestClusterGetmaster():
93 """gnt-cluster getmaster"""
94 master = qa_config.GetMasterNode()
96 cmd = ['gnt-cluster', 'getmaster']
97 AssertEqual(StartSSH(master['primary'],
98 utils.ShellQuoteArgs(cmd)).wait(), 0)
101 def TestClusterVersion():
102 """gnt-cluster version"""
103 master = qa_config.GetMasterNode()
105 cmd = ['gnt-cluster', 'version']
106 AssertEqual(StartSSH(master['primary'],
107 utils.ShellQuoteArgs(cmd)).wait(), 0)
110 def TestClusterBurnin():
112 master = qa_config.GetMasterNode()
114 # Get as many instances as we need
117 num = qa_config.get('options', {}).get('burnin-instances', 1)
118 for _ in xrange(0, num):
119 instances.append(qa_config.AcquireInstance())
120 except qa_error.OutOfInstancesError:
121 print "Not enough instances, continuing anyway."
123 if len(instances) < 1:
124 raise qa_error.Error("Burnin needs at least one instance")
128 script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
131 '--os=%s' % qa_config.get('os'),
132 '--os-size=%s' % qa_config.get('os-size'),
133 '--swap-size=%s' % qa_config.get('swap-size')]
134 cmd += [inst['name'] for inst in instances]
135 AssertEqual(StartSSH(master['primary'],
136 utils.ShellQuoteArgs(cmd)).wait(), 0)
138 cmd = ['rm', '-f', script]
139 AssertEqual(StartSSH(master['primary'],
140 utils.ShellQuoteArgs(cmd)).wait(), 0)
142 for inst in instances:
143 qa_config.ReleaseInstance(inst)
146 def TestClusterMasterFailover():
147 """gnt-cluster masterfailover"""
148 master = qa_config.GetMasterNode()
150 failovermaster = qa_config.AcquireNode(exclude=master)
152 cmd = ['gnt-cluster', 'masterfailover']
153 AssertEqual(StartSSH(failovermaster['primary'],
154 utils.ShellQuoteArgs(cmd)).wait(), 0)
156 cmd = ['gnt-cluster', 'masterfailover']
157 AssertEqual(StartSSH(master['primary'],
158 utils.ShellQuoteArgs(cmd)).wait(), 0)
160 qa_config.ReleaseNode(failovermaster)
163 def TestClusterCopyfile():
164 """gnt-cluster copyfile"""
165 master = qa_config.GetMasterNode()
167 uniqueid = utils.GetUUID()
169 # Create temporary file
170 f = tempfile.NamedTemporaryFile()
175 # Upload file to master node
176 testname = qa_utils.UploadFile(master['primary'], f.name)
178 # Copy file to all nodes
179 cmd = ['gnt-cluster', 'copyfile', testname]
180 AssertEqual(StartSSH(master['primary'],
181 utils.ShellQuoteArgs(cmd)).wait(), 0)
182 _CheckFileOnAllNodes(testname, uniqueid)
184 _RemoveFileFromAllNodes(testname)
187 def TestClusterCommand():
188 """gnt-cluster command"""
189 master = qa_config.GetMasterNode()
191 uniqueid = utils.GetUUID()
192 rfile = "/tmp/gnt%s" % utils.GetUUID()
193 rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
194 cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
195 "%s >%s" % (rcmd, rfile)])
198 AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
199 _CheckFileOnAllNodes(rfile, uniqueid)
201 _RemoveFileFromAllNodes(rfile)
204 def TestClusterDestroy():
205 """gnt-cluster destroy"""
206 master = qa_config.GetMasterNode()
208 cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
209 AssertEqual(StartSSH(master['primary'],
210 utils.ShellQuoteArgs(cmd)).wait(), 0)