root / qa / qa_cluster.py @ 231db3a5
History | View | Annotate | Download (7.3 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | cec9845c | Michael Hanselmann | # Copyright (C) 2007 Google Inc.
|
5 | cec9845c | Michael Hanselmann | #
|
6 | cec9845c | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | cec9845c | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | cec9845c | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | cec9845c | Michael Hanselmann | # (at your option) any later version.
|
10 | cec9845c | Michael Hanselmann | #
|
11 | cec9845c | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | cec9845c | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | cec9845c | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | cec9845c | Michael Hanselmann | # General Public License for more details.
|
15 | cec9845c | Michael Hanselmann | #
|
16 | cec9845c | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | cec9845c | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | cec9845c | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | cec9845c | Michael Hanselmann | # 02110-1301, USA.
|
20 | cec9845c | Michael Hanselmann | |
21 | cec9845c | Michael Hanselmann | |
22 | cec9845c | Michael Hanselmann | """Cluster related QA tests.
|
23 | cec9845c | Michael Hanselmann |
|
24 | cec9845c | Michael Hanselmann | """
|
25 | cec9845c | Michael Hanselmann | |
26 | cec9845c | Michael Hanselmann | import tempfile |
27 | cec9845c | Michael Hanselmann | |
28 | cec9845c | Michael Hanselmann | from ganeti import utils |
29 | cec9845c | Michael Hanselmann | |
30 | cec9845c | Michael Hanselmann | import qa_config |
31 | cec9845c | Michael Hanselmann | import qa_utils |
32 | cec9845c | Michael Hanselmann | import qa_error |
33 | cec9845c | Michael Hanselmann | |
34 | cec9845c | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
35 | cec9845c | Michael Hanselmann | |
36 | cec9845c | Michael Hanselmann | |
37 | 830da270 | Michael Hanselmann | def _RemoveFileFromAllNodes(filename): |
38 | 830da270 | Michael Hanselmann | """Removes a file from all nodes.
|
39 | 830da270 | Michael Hanselmann |
|
40 | 830da270 | Michael Hanselmann | """
|
41 | 830da270 | Michael Hanselmann | for node in qa_config.get('nodes'): |
42 | 830da270 | Michael Hanselmann | cmd = ['rm', '-f', filename] |
43 | 830da270 | Michael Hanselmann | AssertEqual(StartSSH(node['primary'],
|
44 | 830da270 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
45 | 830da270 | Michael Hanselmann | |
46 | 830da270 | Michael Hanselmann | |
47 | 830da270 | Michael Hanselmann | def _CheckFileOnAllNodes(filename, content): |
48 | 830da270 | Michael Hanselmann | """Verifies the content of the given file on all nodes.
|
49 | 830da270 | Michael Hanselmann |
|
50 | 830da270 | Michael Hanselmann | """
|
51 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(["cat", filename])
|
52 | 830da270 | Michael Hanselmann | for node in qa_config.get('nodes'): |
53 | 830da270 | Michael Hanselmann | AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
|
54 | 830da270 | Michael Hanselmann | content) |
55 | 830da270 | Michael Hanselmann | |
56 | 830da270 | Michael Hanselmann | |
57 | cec9845c | Michael Hanselmann | def TestClusterInit(): |
58 | cec9845c | Michael Hanselmann | """gnt-cluster init"""
|
59 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
60 | cec9845c | Michael Hanselmann | |
61 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'init'] |
62 | cec9845c | Michael Hanselmann | |
63 | cec9845c | Michael Hanselmann | if master.get('secondary', None): |
64 | cec9845c | Michael Hanselmann | cmd.append('--secondary-ip=%s' % master['secondary']) |
65 | cec9845c | Michael Hanselmann | |
66 | cec9845c | Michael Hanselmann | bridge = qa_config.get('bridge', None) |
67 | cec9845c | Michael Hanselmann | if bridge:
|
68 | cec9845c | Michael Hanselmann | cmd.append('--bridge=%s' % bridge)
|
69 | cec9845c | Michael Hanselmann | cmd.append('--master-netdev=%s' % bridge)
|
70 | cec9845c | Michael Hanselmann | |
71 | 2d6db53a | Guido Trotter | htype = qa_config.get('enabled-hypervisors', None) |
72 | b32f9859 | Iustin Pop | if htype:
|
73 | 2d6db53a | Guido Trotter | cmd.append('--enabled-hypervisors=%s' % htype)
|
74 | b32f9859 | Iustin Pop | |
75 | cec9845c | Michael Hanselmann | cmd.append(qa_config.get('name'))
|
76 | cec9845c | Michael Hanselmann | |
77 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
78 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
79 | cec9845c | Michael Hanselmann | |
80 | cec9845c | Michael Hanselmann | |
81 | caea3b32 | Iustin Pop | def TestClusterRename(): |
82 | caea3b32 | Iustin Pop | """gnt-cluster rename"""
|
83 | caea3b32 | Iustin Pop | master = qa_config.GetMasterNode() |
84 | caea3b32 | Iustin Pop | |
85 | caea3b32 | Iustin Pop | cmd = ['gnt-cluster', 'rename', '-f'] |
86 | caea3b32 | Iustin Pop | |
87 | caea3b32 | Iustin Pop | original_name = qa_config.get('name')
|
88 | caea3b32 | Iustin Pop | rename_target = qa_config.get('rename', None) |
89 | caea3b32 | Iustin Pop | if rename_target is None: |
90 | caea3b32 | Iustin Pop | print qa_utils.FormatError('"rename" entry is missing') |
91 | caea3b32 | Iustin Pop | return
|
92 | caea3b32 | Iustin Pop | |
93 | caea3b32 | Iustin Pop | cmd_1 = cmd + [rename_target] |
94 | caea3b32 | Iustin Pop | cmd_2 = cmd + [original_name] |
95 | caea3b32 | Iustin Pop | |
96 | caea3b32 | Iustin Pop | cmd_verify = ['gnt-cluster', 'verify'] |
97 | caea3b32 | Iustin Pop | |
98 | caea3b32 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
99 | caea3b32 | Iustin Pop | utils.ShellQuoteArgs(cmd_1)).wait(), 0)
|
100 | caea3b32 | Iustin Pop | |
101 | caea3b32 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
102 | caea3b32 | Iustin Pop | utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
|
103 | caea3b32 | Iustin Pop | |
104 | caea3b32 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
105 | caea3b32 | Iustin Pop | utils.ShellQuoteArgs(cmd_2)).wait(), 0)
|
106 | caea3b32 | Iustin Pop | |
107 | caea3b32 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
108 | caea3b32 | Iustin Pop | utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
|
109 | caea3b32 | Iustin Pop | |
110 | caea3b32 | Iustin Pop | |
111 | cec9845c | Michael Hanselmann | def TestClusterVerify(): |
112 | cec9845c | Michael Hanselmann | """gnt-cluster verify"""
|
113 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
114 | cec9845c | Michael Hanselmann | |
115 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'verify'] |
116 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
117 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
118 | cec9845c | Michael Hanselmann | |
119 | cec9845c | Michael Hanselmann | |
120 | cec9845c | Michael Hanselmann | def TestClusterInfo(): |
121 | cec9845c | Michael Hanselmann | """gnt-cluster info"""
|
122 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
123 | 283f9d4c | Michael Hanselmann | |
124 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'info'] |
125 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
126 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
127 | 283f9d4c | Michael Hanselmann | |
128 | 283f9d4c | Michael Hanselmann | |
129 | 283f9d4c | Michael Hanselmann | def TestClusterGetmaster(): |
130 | 283f9d4c | Michael Hanselmann | """gnt-cluster getmaster"""
|
131 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
132 | cec9845c | Michael Hanselmann | |
133 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'getmaster'] |
134 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
135 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
136 | 283f9d4c | Michael Hanselmann | |
137 | 283f9d4c | Michael Hanselmann | |
138 | 283f9d4c | Michael Hanselmann | def TestClusterVersion(): |
139 | 283f9d4c | Michael Hanselmann | """gnt-cluster version"""
|
140 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
141 | 283f9d4c | Michael Hanselmann | |
142 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'version'] |
143 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
144 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
145 | cec9845c | Michael Hanselmann | |
146 | cec9845c | Michael Hanselmann | |
147 | cec9845c | Michael Hanselmann | def TestClusterBurnin(): |
148 | cec9845c | Michael Hanselmann | """Burnin"""
|
149 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
150 | cec9845c | Michael Hanselmann | |
151 | 0b0a150a | Iustin Pop | options = qa_config.get('options', {})
|
152 | 0b0a150a | Iustin Pop | disk_template = options.get('burnin-disk-template', 'drbd') |
153 | 0b0a150a | Iustin Pop | parallel = options.get('burnin-in-parallel', False) |
154 | 0b0a150a | Iustin Pop | check_inst = options.get('burnin-check-instances', False) |
155 | 4dc76b24 | Iustin Pop | do_rename = options.get('burnin-rename', '') |
156 | 23103544 | Michael Hanselmann | |
157 | cec9845c | Michael Hanselmann | # Get as many instances as we need
|
158 | cec9845c | Michael Hanselmann | instances = [] |
159 | cec9845c | Michael Hanselmann | try:
|
160 | 23103544 | Michael Hanselmann | try:
|
161 | 23103544 | Michael Hanselmann | num = qa_config.get('options', {}).get('burnin-instances', 1) |
162 | f1501b3f | Michael Hanselmann | for _ in range(0, num): |
163 | 23103544 | Michael Hanselmann | instances.append(qa_config.AcquireInstance()) |
164 | 23103544 | Michael Hanselmann | except qa_error.OutOfInstancesError:
|
165 | 23103544 | Michael Hanselmann | print "Not enough instances, continuing anyway." |
166 | cec9845c | Michael Hanselmann | |
167 | 23103544 | Michael Hanselmann | if len(instances) < 1: |
168 | 23103544 | Michael Hanselmann | raise qa_error.Error("Burnin needs at least one instance") |
169 | cec9845c | Michael Hanselmann | |
170 | cec9845c | Michael Hanselmann | script = qa_utils.UploadFile(master['primary'], '../tools/burnin') |
171 | cec9845c | Michael Hanselmann | try:
|
172 | 23103544 | Michael Hanselmann | # Run burnin
|
173 | cec9845c | Michael Hanselmann | cmd = [script, |
174 | 0b0a150a | Iustin Pop | '-p',
|
175 | cec9845c | Michael Hanselmann | '--os=%s' % qa_config.get('os'), |
176 | 1d693311 | Michael Hanselmann | '--disk-size=%s' % ",".join(qa_config.get('disk')), |
177 | 1d693311 | Michael Hanselmann | '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')), |
178 | 23103544 | Michael Hanselmann | '--disk-template=%s' % disk_template]
|
179 | 0b0a150a | Iustin Pop | if parallel:
|
180 | 0b0a150a | Iustin Pop | cmd.append('--parallel')
|
181 | 0b0a150a | Iustin Pop | if check_inst:
|
182 | 0b0a150a | Iustin Pop | cmd.append('--http-check')
|
183 | 4dc76b24 | Iustin Pop | if do_rename:
|
184 | 4dc76b24 | Iustin Pop | cmd.append('--rename=%s' % do_rename)
|
185 | cec9845c | Michael Hanselmann | cmd += [inst['name'] for inst in instances] |
186 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
187 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
188 | cec9845c | Michael Hanselmann | finally:
|
189 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', script] |
190 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
191 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
192 | cec9845c | Michael Hanselmann | finally:
|
193 | cec9845c | Michael Hanselmann | for inst in instances: |
194 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(inst) |
195 | cec9845c | Michael Hanselmann | |
196 | cec9845c | Michael Hanselmann | |
197 | cec9845c | Michael Hanselmann | def TestClusterMasterFailover(): |
198 | cec9845c | Michael Hanselmann | """gnt-cluster masterfailover"""
|
199 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
200 | cec9845c | Michael Hanselmann | |
201 | cec9845c | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
202 | cec9845c | Michael Hanselmann | try:
|
203 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
204 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(failovermaster['primary'],
|
205 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
206 | cec9845c | Michael Hanselmann | |
207 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
208 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
209 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
210 | cec9845c | Michael Hanselmann | finally:
|
211 | cec9845c | Michael Hanselmann | qa_config.ReleaseNode(failovermaster) |
212 | cec9845c | Michael Hanselmann | |
213 | cec9845c | Michael Hanselmann | |
214 | cec9845c | Michael Hanselmann | def TestClusterCopyfile(): |
215 | cec9845c | Michael Hanselmann | """gnt-cluster copyfile"""
|
216 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
217 | cec9845c | Michael Hanselmann | |
218 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
219 | 830da270 | Michael Hanselmann | |
220 | cec9845c | Michael Hanselmann | # Create temporary file
|
221 | cec9845c | Michael Hanselmann | f = tempfile.NamedTemporaryFile() |
222 | 830da270 | Michael Hanselmann | f.write(uniqueid) |
223 | cec9845c | Michael Hanselmann | f.flush() |
224 | cec9845c | Michael Hanselmann | f.seek(0)
|
225 | cec9845c | Michael Hanselmann | |
226 | cec9845c | Michael Hanselmann | # Upload file to master node
|
227 | cec9845c | Michael Hanselmann | testname = qa_utils.UploadFile(master['primary'], f.name)
|
228 | cec9845c | Michael Hanselmann | try:
|
229 | cec9845c | Michael Hanselmann | # Copy file to all nodes
|
230 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'copyfile', testname] |
231 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
232 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
233 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(testname, uniqueid) |
234 | cec9845c | Michael Hanselmann | finally:
|
235 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(testname) |
236 | 830da270 | Michael Hanselmann | |
237 | 830da270 | Michael Hanselmann | |
238 | 830da270 | Michael Hanselmann | def TestClusterCommand(): |
239 | 830da270 | Michael Hanselmann | """gnt-cluster command"""
|
240 | 830da270 | Michael Hanselmann | master = qa_config.GetMasterNode() |
241 | 830da270 | Michael Hanselmann | |
242 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
243 | 24818e8f | Michael Hanselmann | rfile = "/tmp/gnt%s" % utils.NewUUID()
|
244 | 830da270 | Michael Hanselmann | rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid]) |
245 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command', |
246 | 830da270 | Michael Hanselmann | "%s >%s" % (rcmd, rfile)])
|
247 | 830da270 | Michael Hanselmann | |
248 | 830da270 | Michael Hanselmann | try:
|
249 | 830da270 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], cmd).wait(), 0) |
250 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(rfile, uniqueid) |
251 | 830da270 | Michael Hanselmann | finally:
|
252 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(rfile) |
253 | cec9845c | Michael Hanselmann | |
254 | cec9845c | Michael Hanselmann | |
255 | cec9845c | Michael Hanselmann | def TestClusterDestroy(): |
256 | cec9845c | Michael Hanselmann | """gnt-cluster destroy"""
|
257 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
258 | cec9845c | Michael Hanselmann | |
259 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
260 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
261 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0) |