QA: add burnin parameters (parallel, http-check)
[ganeti-local] / qa / qa_cluster.py
1 #
2 #
3
4 # Copyright (C) 2007 Google Inc.
5 #
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.
10 #
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.
15 #
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
19 # 02110-1301, USA.
20
21
22 """Cluster related QA tests.
23
24 """
25
26 import tempfile
27
28 from ganeti import utils
29
30 import qa_config
31 import qa_utils
32 import qa_error
33
34 from qa_utils import AssertEqual, StartSSH
35
36
37 def _RemoveFileFromAllNodes(filename):
38   """Removes a file from all nodes.
39
40   """
41   for node in qa_config.get('nodes'):
42     cmd = ['rm', '-f', filename]
43     AssertEqual(StartSSH(node['primary'],
44                          utils.ShellQuoteArgs(cmd)).wait(), 0)
45
46
47 def _CheckFileOnAllNodes(filename, content):
48   """Verifies the content of the given file on all nodes.
49
50   """
51   cmd = utils.ShellQuoteArgs(["cat", filename])
52   for node in qa_config.get('nodes'):
53     AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
54                 content)
55
56
57 def TestClusterInit():
58   """gnt-cluster init"""
59   master = qa_config.GetMasterNode()
60
61   cmd = ['gnt-cluster', 'init']
62
63   if master.get('secondary', None):
64     cmd.append('--secondary-ip=%s' % master['secondary'])
65
66   bridge = qa_config.get('bridge', None)
67   if bridge:
68     cmd.append('--bridge=%s' % bridge)
69     cmd.append('--master-netdev=%s' % bridge)
70
71   htype = qa_config.get('default-hypervisor', None)
72   if htype:
73     cmd.append('--default-hypervisor=%s' % htype)
74
75   cmd.append(qa_config.get('name'))
76
77   AssertEqual(StartSSH(master['primary'],
78                        utils.ShellQuoteArgs(cmd)).wait(), 0)
79
80
81 def TestClusterRename():
82   """gnt-cluster rename"""
83   master = qa_config.GetMasterNode()
84
85   cmd = ['gnt-cluster', 'rename', '-f']
86
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')
91     return
92
93   cmd_1 = cmd + [rename_target]
94   cmd_2 = cmd + [original_name]
95
96   cmd_verify = ['gnt-cluster', 'verify']
97
98   AssertEqual(StartSSH(master['primary'],
99                        utils.ShellQuoteArgs(cmd_1)).wait(), 0)
100
101   AssertEqual(StartSSH(master['primary'],
102                        utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
103
104   AssertEqual(StartSSH(master['primary'],
105                        utils.ShellQuoteArgs(cmd_2)).wait(), 0)
106
107   AssertEqual(StartSSH(master['primary'],
108                        utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
109
110
111 def TestClusterVerify():
112   """gnt-cluster verify"""
113   master = qa_config.GetMasterNode()
114
115   cmd = ['gnt-cluster', 'verify']
116   AssertEqual(StartSSH(master['primary'],
117                        utils.ShellQuoteArgs(cmd)).wait(), 0)
118
119
120 def TestClusterInfo():
121   """gnt-cluster info"""
122   master = qa_config.GetMasterNode()
123
124   cmd = ['gnt-cluster', 'info']
125   AssertEqual(StartSSH(master['primary'],
126                        utils.ShellQuoteArgs(cmd)).wait(), 0)
127
128
129 def TestClusterGetmaster():
130   """gnt-cluster getmaster"""
131   master = qa_config.GetMasterNode()
132
133   cmd = ['gnt-cluster', 'getmaster']
134   AssertEqual(StartSSH(master['primary'],
135                        utils.ShellQuoteArgs(cmd)).wait(), 0)
136
137
138 def TestClusterVersion():
139   """gnt-cluster version"""
140   master = qa_config.GetMasterNode()
141
142   cmd = ['gnt-cluster', 'version']
143   AssertEqual(StartSSH(master['primary'],
144                        utils.ShellQuoteArgs(cmd)).wait(), 0)
145
146
147 def TestClusterBurnin():
148   """Burnin"""
149   master = qa_config.GetMasterNode()
150
151   options = qa_config.get('options', {})
152   disk_template = options.get('burnin-disk-template', 'drbd')
153   parallel = options.get('burnin-in-parallel', False)
154   check_inst = options.get('burnin-check-instances', False)
155
156   # Get as many instances as we need
157   instances = []
158   try:
159     try:
160       num = qa_config.get('options', {}).get('burnin-instances', 1)
161       for _ in xrange(0, num):
162         instances.append(qa_config.AcquireInstance())
163     except qa_error.OutOfInstancesError:
164       print "Not enough instances, continuing anyway."
165
166     if len(instances) < 1:
167       raise qa_error.Error("Burnin needs at least one instance")
168
169     script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
170     try:
171       # Run burnin
172       cmd = [script,
173              '-p',
174              '--os=%s' % qa_config.get('os'),
175              '--disk-size=%s' % ",".join(qa_config.get('disk')),
176              '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
177              '--disk-template=%s' % disk_template]
178       if parallel:
179         cmd.append('--parallel')
180       if check_inst:
181         cmd.append('--http-check')
182       cmd += [inst['name'] for inst in instances]
183       AssertEqual(StartSSH(master['primary'],
184                            utils.ShellQuoteArgs(cmd)).wait(), 0)
185     finally:
186       cmd = ['rm', '-f', script]
187       AssertEqual(StartSSH(master['primary'],
188                            utils.ShellQuoteArgs(cmd)).wait(), 0)
189   finally:
190     for inst in instances:
191       qa_config.ReleaseInstance(inst)
192
193
194 def TestClusterMasterFailover():
195   """gnt-cluster masterfailover"""
196   master = qa_config.GetMasterNode()
197
198   failovermaster = qa_config.AcquireNode(exclude=master)
199   try:
200     cmd = ['gnt-cluster', 'masterfailover']
201     AssertEqual(StartSSH(failovermaster['primary'],
202                          utils.ShellQuoteArgs(cmd)).wait(), 0)
203
204     cmd = ['gnt-cluster', 'masterfailover']
205     AssertEqual(StartSSH(master['primary'],
206                          utils.ShellQuoteArgs(cmd)).wait(), 0)
207   finally:
208     qa_config.ReleaseNode(failovermaster)
209
210
211 def TestClusterCopyfile():
212   """gnt-cluster copyfile"""
213   master = qa_config.GetMasterNode()
214
215   uniqueid = utils.NewUUID()
216
217   # Create temporary file
218   f = tempfile.NamedTemporaryFile()
219   f.write(uniqueid)
220   f.flush()
221   f.seek(0)
222
223   # Upload file to master node
224   testname = qa_utils.UploadFile(master['primary'], f.name)
225   try:
226     # Copy file to all nodes
227     cmd = ['gnt-cluster', 'copyfile', testname]
228     AssertEqual(StartSSH(master['primary'],
229                          utils.ShellQuoteArgs(cmd)).wait(), 0)
230     _CheckFileOnAllNodes(testname, uniqueid)
231   finally:
232     _RemoveFileFromAllNodes(testname)
233
234
235 def TestClusterCommand():
236   """gnt-cluster command"""
237   master = qa_config.GetMasterNode()
238
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)])
244
245   try:
246     AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
247     _CheckFileOnAllNodes(rfile, uniqueid)
248   finally:
249     _RemoveFileFromAllNodes(rfile)
250
251
252 def TestClusterDestroy():
253   """gnt-cluster destroy"""
254   master = qa_config.GetMasterNode()
255
256   cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
257   AssertEqual(StartSSH(master['primary'],
258                        utils.ShellQuoteArgs(cmd)).wait(), 0)