root / qa / qa_cluster.py @ c2b05d85
History | View | Annotate | Download (6.9 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 | b32f9859 | Iustin Pop | htype = qa_config.get('hypervisor-type', None) |
72 | b32f9859 | Iustin Pop | if htype:
|
73 | b32f9859 | Iustin Pop | cmd.append('--hypervisor-type=%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 | 23103544 | Michael Hanselmann | disk_template = (qa_config.get('options', {}).
|
152 | f9193417 | Iustin Pop | get('burnin-disk-template', 'drbd')) |
153 | 23103544 | Michael Hanselmann | |
154 | cec9845c | Michael Hanselmann | # Get as many instances as we need
|
155 | cec9845c | Michael Hanselmann | instances = [] |
156 | cec9845c | Michael Hanselmann | try:
|
157 | 23103544 | Michael Hanselmann | try:
|
158 | 23103544 | Michael Hanselmann | num = qa_config.get('options', {}).get('burnin-instances', 1) |
159 | 23103544 | Michael Hanselmann | for _ in xrange(0, num): |
160 | 23103544 | Michael Hanselmann | instances.append(qa_config.AcquireInstance()) |
161 | 23103544 | Michael Hanselmann | except qa_error.OutOfInstancesError:
|
162 | 23103544 | Michael Hanselmann | print "Not enough instances, continuing anyway." |
163 | cec9845c | Michael Hanselmann | |
164 | 23103544 | Michael Hanselmann | if len(instances) < 1: |
165 | 23103544 | Michael Hanselmann | raise qa_error.Error("Burnin needs at least one instance") |
166 | cec9845c | Michael Hanselmann | |
167 | cec9845c | Michael Hanselmann | script = qa_utils.UploadFile(master['primary'], '../tools/burnin') |
168 | cec9845c | Michael Hanselmann | try:
|
169 | 23103544 | Michael Hanselmann | # Run burnin
|
170 | cec9845c | Michael Hanselmann | cmd = [script, |
171 | cec9845c | Michael Hanselmann | '--os=%s' % qa_config.get('os'), |
172 | cec9845c | Michael Hanselmann | '--os-size=%s' % qa_config.get('os-size'), |
173 | 23103544 | Michael Hanselmann | '--swap-size=%s' % qa_config.get('swap-size'), |
174 | 23103544 | Michael Hanselmann | '--disk-template=%s' % disk_template]
|
175 | cec9845c | Michael Hanselmann | cmd += [inst['name'] for inst in instances] |
176 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
177 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
178 | cec9845c | Michael Hanselmann | finally:
|
179 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', script] |
180 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
181 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
182 | cec9845c | Michael Hanselmann | finally:
|
183 | cec9845c | Michael Hanselmann | for inst in instances: |
184 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(inst) |
185 | cec9845c | Michael Hanselmann | |
186 | cec9845c | Michael Hanselmann | |
187 | cec9845c | Michael Hanselmann | def TestClusterMasterFailover(): |
188 | cec9845c | Michael Hanselmann | """gnt-cluster masterfailover"""
|
189 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
190 | cec9845c | Michael Hanselmann | |
191 | cec9845c | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
192 | cec9845c | Michael Hanselmann | try:
|
193 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
194 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(failovermaster['primary'],
|
195 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
196 | cec9845c | Michael Hanselmann | |
197 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
198 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
199 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
200 | cec9845c | Michael Hanselmann | finally:
|
201 | cec9845c | Michael Hanselmann | qa_config.ReleaseNode(failovermaster) |
202 | cec9845c | Michael Hanselmann | |
203 | cec9845c | Michael Hanselmann | |
204 | cec9845c | Michael Hanselmann | def TestClusterCopyfile(): |
205 | cec9845c | Michael Hanselmann | """gnt-cluster copyfile"""
|
206 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
207 | cec9845c | Michael Hanselmann | |
208 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
209 | 830da270 | Michael Hanselmann | |
210 | cec9845c | Michael Hanselmann | # Create temporary file
|
211 | cec9845c | Michael Hanselmann | f = tempfile.NamedTemporaryFile() |
212 | 830da270 | Michael Hanselmann | f.write(uniqueid) |
213 | cec9845c | Michael Hanselmann | f.flush() |
214 | cec9845c | Michael Hanselmann | f.seek(0)
|
215 | cec9845c | Michael Hanselmann | |
216 | cec9845c | Michael Hanselmann | # Upload file to master node
|
217 | cec9845c | Michael Hanselmann | testname = qa_utils.UploadFile(master['primary'], f.name)
|
218 | cec9845c | Michael Hanselmann | try:
|
219 | cec9845c | Michael Hanselmann | # Copy file to all nodes
|
220 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'copyfile', testname] |
221 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
222 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
223 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(testname, uniqueid) |
224 | cec9845c | Michael Hanselmann | finally:
|
225 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(testname) |
226 | 830da270 | Michael Hanselmann | |
227 | 830da270 | Michael Hanselmann | |
228 | 830da270 | Michael Hanselmann | def TestClusterCommand(): |
229 | 830da270 | Michael Hanselmann | """gnt-cluster command"""
|
230 | 830da270 | Michael Hanselmann | master = qa_config.GetMasterNode() |
231 | 830da270 | Michael Hanselmann | |
232 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
233 | 24818e8f | Michael Hanselmann | rfile = "/tmp/gnt%s" % utils.NewUUID()
|
234 | 830da270 | Michael Hanselmann | rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid]) |
235 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command', |
236 | 830da270 | Michael Hanselmann | "%s >%s" % (rcmd, rfile)])
|
237 | 830da270 | Michael Hanselmann | |
238 | 830da270 | Michael Hanselmann | try:
|
239 | 830da270 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], cmd).wait(), 0) |
240 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(rfile, uniqueid) |
241 | 830da270 | Michael Hanselmann | finally:
|
242 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(rfile) |
243 | cec9845c | Michael Hanselmann | |
244 | cec9845c | Michael Hanselmann | |
245 | cec9845c | Michael Hanselmann | def TestClusterDestroy(): |
246 | cec9845c | Michael Hanselmann | """gnt-cluster destroy"""
|
247 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
248 | cec9845c | Michael Hanselmann | |
249 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
250 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
251 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0) |