root / qa / qa_instance.py @ 3d914585
History | View | Annotate | Download (15.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 | """Instance related QA tests.
|
23 | cec9845c | Michael Hanselmann |
|
24 | cec9845c | Michael Hanselmann | """
|
25 | cec9845c | Michael Hanselmann | |
26 | e8ae0c20 | Michael Hanselmann | import re |
27 | e8ae0c20 | Michael Hanselmann | import time |
28 | e8ae0c20 | Michael Hanselmann | |
29 | cec9845c | Michael Hanselmann | from ganeti import utils |
30 | 5d640672 | Michael Hanselmann | from ganeti import constants |
31 | cec9845c | Michael Hanselmann | |
32 | cec9845c | Michael Hanselmann | import qa_config |
33 | 5d640672 | Michael Hanselmann | import qa_utils |
34 | e8ae0c20 | Michael Hanselmann | import qa_error |
35 | e8ae0c20 | Michael Hanselmann | |
36 | e8ae0c20 | Michael Hanselmann | from qa_utils import AssertEqual, AssertNotEqual, StartSSH |
37 | cec9845c | Michael Hanselmann | |
38 | e8ae0c20 | Michael Hanselmann | |
39 | e8ae0c20 | Michael Hanselmann | def _GetDiskStatePath(disk): |
40 | e8ae0c20 | Michael Hanselmann | return "/sys/block/%s/device/state" % disk |
41 | cec9845c | Michael Hanselmann | |
42 | cec9845c | Michael Hanselmann | |
43 | 5d640672 | Michael Hanselmann | def _GetGenericAddParameters(): |
44 | 1d693311 | Michael Hanselmann | params = ['-B', '%s=%s' % (constants.BE_MEMORY, qa_config.get('mem'))] |
45 | 1d693311 | Michael Hanselmann | for idx, size in enumerate(qa_config.get('disk')): |
46 | 1d693311 | Michael Hanselmann | params.extend(["--disk", "%s:size=%s" % (idx, size)]) |
47 | 1d693311 | Michael Hanselmann | return params
|
48 | 5d640672 | Michael Hanselmann | |
49 | 5d640672 | Michael Hanselmann | |
50 | 113b8d89 | Michael Hanselmann | def _DiskTest(node, disk_template): |
51 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
52 | cec9845c | Michael Hanselmann | |
53 | cec9845c | Michael Hanselmann | instance = qa_config.AcquireInstance() |
54 | cec9845c | Michael Hanselmann | try:
|
55 | 5d640672 | Michael Hanselmann | cmd = (['gnt-instance', 'add', |
56 | 5d640672 | Michael Hanselmann | '--os-type=%s' % qa_config.get('os'), |
57 | 113b8d89 | Michael Hanselmann | '--disk-template=%s' % disk_template,
|
58 | 113b8d89 | Michael Hanselmann | '--node=%s' % node] +
|
59 | 5d640672 | Michael Hanselmann | _GetGenericAddParameters()) |
60 | cec9845c | Michael Hanselmann | cmd.append(instance['name'])
|
61 | cec9845c | Michael Hanselmann | |
62 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
63 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
64 | cec9845c | Michael Hanselmann | return instance
|
65 | cec9845c | Michael Hanselmann | except:
|
66 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(instance) |
67 | cec9845c | Michael Hanselmann | raise
|
68 | cec9845c | Michael Hanselmann | |
69 | cec9845c | Michael Hanselmann | |
70 | cec9845c | Michael Hanselmann | def TestInstanceAddWithPlainDisk(node): |
71 | cec9845c | Michael Hanselmann | """gnt-instance add -t plain"""
|
72 | 113b8d89 | Michael Hanselmann | return _DiskTest(node['primary'], 'plain') |
73 | cec9845c | Michael Hanselmann | |
74 | cec9845c | Michael Hanselmann | |
75 | 7d7609a3 | Michael Hanselmann | def TestInstanceAddWithDrbdDisk(node, node2): |
76 | 7d7609a3 | Michael Hanselmann | """gnt-instance add -t drbd"""
|
77 | 7d7609a3 | Michael Hanselmann | return _DiskTest("%s:%s" % (node['primary'], node2['primary']), |
78 | 7d7609a3 | Michael Hanselmann | 'drbd')
|
79 | 7d7609a3 | Michael Hanselmann | |
80 | 7d7609a3 | Michael Hanselmann | |
81 | cec9845c | Michael Hanselmann | def TestInstanceRemove(instance): |
82 | cec9845c | Michael Hanselmann | """gnt-instance remove"""
|
83 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
84 | cec9845c | Michael Hanselmann | |
85 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'remove', '-f', instance['name']] |
86 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
87 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
88 | cec9845c | Michael Hanselmann | |
89 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(instance) |
90 | cec9845c | Michael Hanselmann | |
91 | cec9845c | Michael Hanselmann | |
92 | cec9845c | Michael Hanselmann | def TestInstanceStartup(instance): |
93 | cec9845c | Michael Hanselmann | """gnt-instance startup"""
|
94 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
95 | cec9845c | Michael Hanselmann | |
96 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'startup', instance['name']] |
97 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
98 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
99 | cec9845c | Michael Hanselmann | |
100 | cec9845c | Michael Hanselmann | |
101 | cec9845c | Michael Hanselmann | def TestInstanceShutdown(instance): |
102 | cec9845c | Michael Hanselmann | """gnt-instance shutdown"""
|
103 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
104 | cec9845c | Michael Hanselmann | |
105 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'shutdown', instance['name']] |
106 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
107 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
108 | cec9845c | Michael Hanselmann | |
109 | cec9845c | Michael Hanselmann | |
110 | 8a4e8898 | Michael Hanselmann | def TestInstanceReboot(instance): |
111 | 8a4e8898 | Michael Hanselmann | """gnt-instance reboot"""
|
112 | 8a4e8898 | Michael Hanselmann | master = qa_config.GetMasterNode() |
113 | 8a4e8898 | Michael Hanselmann | |
114 | 1d103c02 | Iustin Pop | options = qa_config.get('options', {})
|
115 | 1d103c02 | Iustin Pop | reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
|
116 | 1d103c02 | Iustin Pop | |
117 | 1d103c02 | Iustin Pop | for rtype in reboot_types: |
118 | 1d103c02 | Iustin Pop | cmd = ['gnt-instance', 'reboot', '--type=%s' % rtype, instance['name']] |
119 | 8a4e8898 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
120 | 8a4e8898 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
121 | 8a4e8898 | Michael Hanselmann | |
122 | 8a4e8898 | Michael Hanselmann | |
123 | 283f9d4c | Michael Hanselmann | def TestInstanceReinstall(instance): |
124 | 283f9d4c | Michael Hanselmann | """gnt-instance reinstall"""
|
125 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
126 | 283f9d4c | Michael Hanselmann | |
127 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-instance', 'reinstall', '-f', instance['name']] |
128 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
129 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
130 | 283f9d4c | Michael Hanselmann | |
131 | 283f9d4c | Michael Hanselmann | |
132 | 7fb50870 | Michael Hanselmann | def TestInstanceRename(instance, rename_target): |
133 | 18337ca9 | Iustin Pop | """gnt-instance rename"""
|
134 | 18337ca9 | Iustin Pop | master = qa_config.GetMasterNode() |
135 | 18337ca9 | Iustin Pop | |
136 | 18337ca9 | Iustin Pop | rename_source = instance['name']
|
137 | 18337ca9 | Iustin Pop | |
138 | 18337ca9 | Iustin Pop | for name1, name2 in [(rename_source, rename_target), |
139 | 18337ca9 | Iustin Pop | (rename_target, rename_source)]: |
140 | 18337ca9 | Iustin Pop | cmd = ['gnt-instance', 'rename', name1, name2] |
141 | 18337ca9 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
142 | 18337ca9 | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
143 | 18337ca9 | Iustin Pop | |
144 | 18337ca9 | Iustin Pop | |
145 | cec9845c | Michael Hanselmann | def TestInstanceFailover(instance): |
146 | cec9845c | Michael Hanselmann | """gnt-instance failover"""
|
147 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
148 | cec9845c | Michael Hanselmann | |
149 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'failover', '--force', instance['name']] |
150 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
151 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
152 | cec9845c | Michael Hanselmann | |
153 | 76f59a32 | Michael Hanselmann | # ... and back
|
154 | 76f59a32 | Michael Hanselmann | cmd = ['gnt-instance', 'failover', '--force', instance['name']] |
155 | 76f59a32 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
156 | 76f59a32 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
157 | 76f59a32 | Michael Hanselmann | |
158 | cec9845c | Michael Hanselmann | |
159 | 938bde86 | Michael Hanselmann | def TestInstanceMigrate(instance): |
160 | 938bde86 | Michael Hanselmann | """gnt-instance migrate"""
|
161 | 938bde86 | Michael Hanselmann | master = qa_config.GetMasterNode() |
162 | 938bde86 | Michael Hanselmann | |
163 | 938bde86 | Michael Hanselmann | cmd = ["gnt-instance", "migrate", "--force", instance["name"]] |
164 | 938bde86 | Michael Hanselmann | AssertEqual(StartSSH(master["primary"],
|
165 | 938bde86 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
166 | 938bde86 | Michael Hanselmann | |
167 | 938bde86 | Michael Hanselmann | # ... and back
|
168 | 938bde86 | Michael Hanselmann | cmd = ["gnt-instance", "migrate", "--force", instance["name"]] |
169 | 938bde86 | Michael Hanselmann | AssertEqual(StartSSH(master["primary"],
|
170 | 938bde86 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
171 | 938bde86 | Michael Hanselmann | |
172 | 938bde86 | Michael Hanselmann | |
173 | cec9845c | Michael Hanselmann | def TestInstanceInfo(instance): |
174 | cec9845c | Michael Hanselmann | """gnt-instance info"""
|
175 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
176 | cec9845c | Michael Hanselmann | |
177 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'info', instance['name']] |
178 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
179 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
180 | 5d640672 | Michael Hanselmann | |
181 | 5d640672 | Michael Hanselmann | |
182 | c0f74c55 | Iustin Pop | def TestInstanceModify(instance): |
183 | c0f74c55 | Iustin Pop | """gnt-instance modify"""
|
184 | c0f74c55 | Iustin Pop | master = qa_config.GetMasterNode() |
185 | c0f74c55 | Iustin Pop | |
186 | 1d693311 | Michael Hanselmann | # Assume /sbin/init exists on all systems
|
187 | 1d693311 | Michael Hanselmann | test_kernel = "/sbin/init"
|
188 | 1d693311 | Michael Hanselmann | test_initrd = test_kernel |
189 | 1d693311 | Michael Hanselmann | |
190 | c0f74c55 | Iustin Pop | orig_memory = qa_config.get('mem')
|
191 | c0f74c55 | Iustin Pop | orig_bridge = qa_config.get('bridge', 'xen-br0') |
192 | c0f74c55 | Iustin Pop | args = [ |
193 | 1d693311 | Michael Hanselmann | ["-B", "%s=128" % constants.BE_MEMORY], |
194 | 1d693311 | Michael Hanselmann | ["-B", "%s=%s" % (constants.BE_MEMORY, orig_memory)], |
195 | 1d693311 | Michael Hanselmann | ["-B", "%s=2" % constants.BE_VCPUS], |
196 | 1d693311 | Michael Hanselmann | ["-B", "%s=1" % constants.BE_VCPUS], |
197 | 1d693311 | Michael Hanselmann | ["-B", "%s=%s" % (constants.BE_VCPUS, constants.VALUE_DEFAULT)], |
198 | 1d693311 | Michael Hanselmann | |
199 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_KERNEL_PATH, test_kernel)], |
200 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_KERNEL_PATH, constants.VALUE_DEFAULT)], |
201 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_INITRD_PATH, test_initrd)], |
202 | 5645d16b | Iustin Pop | ["-H", "no_%s" % (constants.HV_INITRD_PATH, )], |
203 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_INITRD_PATH, constants.VALUE_DEFAULT)], |
204 | 1d693311 | Michael Hanselmann | |
205 | 1d693311 | Michael Hanselmann | # TODO: bridge tests
|
206 | 1d693311 | Michael Hanselmann | #["--bridge", "xen-br1"],
|
207 | 1d693311 | Michael Hanselmann | #["--bridge", orig_bridge],
|
208 | 1d693311 | Michael Hanselmann | |
209 | 1d693311 | Michael Hanselmann | # TODO: Do these tests only with xen-hvm
|
210 | 1d693311 | Michael Hanselmann | #["-H", "%s=acn" % constants.HV_BOOT_ORDER],
|
211 | 1d693311 | Michael Hanselmann | #["-H", "%s=%s" % (constants.HV_BOOT_ORDER, constants.VALUE_DEFAULT)],
|
212 | c0f74c55 | Iustin Pop | ] |
213 | c0f74c55 | Iustin Pop | for alist in args: |
214 | c0f74c55 | Iustin Pop | cmd = ['gnt-instance', 'modify'] + alist + [instance['name']] |
215 | c0f74c55 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
216 | c0f74c55 | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
217 | c0f74c55 | Iustin Pop | |
218 | c0f74c55 | Iustin Pop | # check no-modify
|
219 | c0f74c55 | Iustin Pop | cmd = ['gnt-instance', 'modify', instance['name']] |
220 | c0f74c55 | Iustin Pop | AssertNotEqual(StartSSH(master['primary'],
|
221 | c0f74c55 | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
222 | c0f74c55 | Iustin Pop | |
223 | c0f74c55 | Iustin Pop | |
224 | 7f69aabb | Iustin Pop | def TestInstanceConvertDisk(instance, snode): |
225 | 7f69aabb | Iustin Pop | """gnt-instance modify -t"""
|
226 | 7f69aabb | Iustin Pop | master = qa_config.GetMasterNode() |
227 | 7f69aabb | Iustin Pop | cmd = ['gnt-instance', 'modify', '-t', 'plain', instance['name']] |
228 | 7f69aabb | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
229 | 7f69aabb | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
230 | b73302c4 | Guido Trotter | cmd = ['gnt-instance', 'modify', '-t', 'drbd', '-n', snode['primary'], |
231 | b73302c4 | Guido Trotter | instance['name']]
|
232 | 7f69aabb | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
233 | 7f69aabb | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
234 | 7f69aabb | Iustin Pop | |
235 | 7f69aabb | Iustin Pop | |
236 | 283f9d4c | Michael Hanselmann | def TestInstanceList(): |
237 | 283f9d4c | Michael Hanselmann | """gnt-instance list"""
|
238 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
239 | 283f9d4c | Michael Hanselmann | |
240 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-instance', 'list'] |
241 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
242 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
243 | 283f9d4c | Michael Hanselmann | |
244 | 283f9d4c | Michael Hanselmann | |
245 | 4379b1fa | Michael Hanselmann | def TestInstanceConsole(instance): |
246 | 4379b1fa | Michael Hanselmann | """gnt-instance console"""
|
247 | 4379b1fa | Michael Hanselmann | master = qa_config.GetMasterNode() |
248 | 4379b1fa | Michael Hanselmann | |
249 | 4379b1fa | Michael Hanselmann | cmd = ['gnt-instance', 'console', '--show-cmd', instance['name']] |
250 | 4379b1fa | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
251 | 4379b1fa | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
252 | 4379b1fa | Michael Hanselmann | |
253 | 4379b1fa | Michael Hanselmann | |
254 | 7910e7a5 | Michael Hanselmann | def TestReplaceDisks(instance, pnode, snode, othernode): |
255 | 7910e7a5 | Michael Hanselmann | """gnt-instance replace-disks"""
|
256 | 7910e7a5 | Michael Hanselmann | master = qa_config.GetMasterNode() |
257 | 7910e7a5 | Michael Hanselmann | |
258 | 7910e7a5 | Michael Hanselmann | def buildcmd(args): |
259 | 7910e7a5 | Michael Hanselmann | cmd = ['gnt-instance', 'replace-disks'] |
260 | 7910e7a5 | Michael Hanselmann | cmd.extend(args) |
261 | 7910e7a5 | Michael Hanselmann | cmd.append(instance["name"])
|
262 | 7910e7a5 | Michael Hanselmann | return cmd
|
263 | 7910e7a5 | Michael Hanselmann | |
264 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["-p"])
|
265 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
266 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
267 | 7910e7a5 | Michael Hanselmann | |
268 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["-s"])
|
269 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
270 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
271 | 7910e7a5 | Michael Hanselmann | |
272 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["--new-secondary=%s" % othernode["primary"]]) |
273 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
274 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
275 | 7910e7a5 | Michael Hanselmann | |
276 | 7910e7a5 | Michael Hanselmann | # Restore
|
277 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["--new-secondary=%s" % snode["primary"]]) |
278 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
279 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
280 | 7910e7a5 | Michael Hanselmann | |
281 | 7910e7a5 | Michael Hanselmann | |
282 | 5d640672 | Michael Hanselmann | def TestInstanceExport(instance, node): |
283 | bc696589 | Michael Hanselmann | """gnt-backup export -n ..."""
|
284 | 5d640672 | Michael Hanselmann | master = qa_config.GetMasterNode() |
285 | 5d640672 | Michael Hanselmann | |
286 | 5d640672 | Michael Hanselmann | cmd = ['gnt-backup', 'export', '-n', node['primary'], instance['name']] |
287 | 5d640672 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
288 | 5d640672 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
289 | 5d640672 | Michael Hanselmann | |
290 | 5d640672 | Michael Hanselmann | return qa_utils.ResolveInstanceName(instance)
|
291 | 5d640672 | Michael Hanselmann | |
292 | 5d640672 | Michael Hanselmann | |
293 | 8d8d650c | Michael Hanselmann | def TestInstanceExportWithRemove(instance, node): |
294 | 8d8d650c | Michael Hanselmann | """gnt-backup export --remove-instance"""
|
295 | 8d8d650c | Michael Hanselmann | master = qa_config.GetMasterNode() |
296 | 8d8d650c | Michael Hanselmann | |
297 | 8d8d650c | Michael Hanselmann | cmd = ['gnt-backup', 'export', '-n', node['primary'], "--remove-instance", |
298 | 8d8d650c | Michael Hanselmann | instance['name']]
|
299 | 8d8d650c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
300 | 8d8d650c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
301 | 8d8d650c | Michael Hanselmann | |
302 | 8d8d650c | Michael Hanselmann | |
303 | bc696589 | Michael Hanselmann | def TestInstanceExportNoTarget(instance): |
304 | bc696589 | Michael Hanselmann | """gnt-backup export (without target node, should fail)"""
|
305 | bc696589 | Michael Hanselmann | master = qa_config.GetMasterNode() |
306 | bc696589 | Michael Hanselmann | |
307 | bc696589 | Michael Hanselmann | cmd = ["gnt-backup", "export", instance["name"]] |
308 | bc696589 | Michael Hanselmann | AssertNotEqual(StartSSH(master['primary'],
|
309 | bc696589 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
310 | bc696589 | Michael Hanselmann | |
311 | bc696589 | Michael Hanselmann | |
312 | 5d640672 | Michael Hanselmann | def TestInstanceImport(node, newinst, expnode, name): |
313 | 5d640672 | Michael Hanselmann | """gnt-backup import"""
|
314 | 5d640672 | Michael Hanselmann | master = qa_config.GetMasterNode() |
315 | 5d640672 | Michael Hanselmann | |
316 | 5d640672 | Michael Hanselmann | cmd = (['gnt-backup', 'import', |
317 | 5d640672 | Michael Hanselmann | '--disk-template=plain',
|
318 | 5d640672 | Michael Hanselmann | '--no-ip-check',
|
319 | 53a8da8e | Iustin Pop | '--net', '0:mac=generate', |
320 | 5d640672 | Michael Hanselmann | '--src-node=%s' % expnode['primary'], |
321 | 5d640672 | Michael Hanselmann | '--src-dir=%s/%s' % (constants.EXPORT_DIR, name),
|
322 | 5d640672 | Michael Hanselmann | '--node=%s' % node['primary']] + |
323 | 5d640672 | Michael Hanselmann | _GetGenericAddParameters()) |
324 | 5d640672 | Michael Hanselmann | cmd.append(newinst['name'])
|
325 | 5d640672 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
326 | 5d640672 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
327 | 283f9d4c | Michael Hanselmann | |
328 | 283f9d4c | Michael Hanselmann | |
329 | 283f9d4c | Michael Hanselmann | def TestBackupList(expnode): |
330 | 283f9d4c | Michael Hanselmann | """gnt-backup list"""
|
331 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
332 | 283f9d4c | Michael Hanselmann | |
333 | 1e020d1b | Michael Hanselmann | cmd = ['gnt-backup', 'list', '--node=%s' % expnode['primary']] |
334 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
335 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
336 | e8ae0c20 | Michael Hanselmann | |
337 | e8ae0c20 | Michael Hanselmann | |
338 | e8ae0c20 | Michael Hanselmann | def _TestInstanceDiskFailure(instance, node, node2, onmaster): |
339 | e8ae0c20 | Michael Hanselmann | """Testing disk failure."""
|
340 | e8ae0c20 | Michael Hanselmann | master = qa_config.GetMasterNode() |
341 | e8ae0c20 | Michael Hanselmann | sq = utils.ShellQuoteArgs |
342 | e8ae0c20 | Michael Hanselmann | |
343 | e8ae0c20 | Michael Hanselmann | instance_full = qa_utils.ResolveInstanceName(instance) |
344 | e8ae0c20 | Michael Hanselmann | node_full = qa_utils.ResolveNodeName(node) |
345 | e8ae0c20 | Michael Hanselmann | node2_full = qa_utils.ResolveNodeName(node2) |
346 | e8ae0c20 | Michael Hanselmann | |
347 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Getting physical disk names") |
348 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-node', 'volumes', '--separator=|', '--no-headers', |
349 | e8ae0c20 | Michael Hanselmann | '--output=node,phys,instance',
|
350 | e8ae0c20 | Michael Hanselmann | node['primary'], node2['primary']] |
351 | e8ae0c20 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master['primary'], sq(cmd))
|
352 | e8ae0c20 | Michael Hanselmann | |
353 | e8ae0c20 | Michael Hanselmann | # Get physical disk names
|
354 | e8ae0c20 | Michael Hanselmann | re_disk = re.compile(r'^/dev/([a-z]+)\d+$')
|
355 | e8ae0c20 | Michael Hanselmann | node2disk = {} |
356 | e8ae0c20 | Michael Hanselmann | for line in output.splitlines(): |
357 | e8ae0c20 | Michael Hanselmann | (node_name, phys, inst) = line.split('|')
|
358 | e8ae0c20 | Michael Hanselmann | if inst == instance_full:
|
359 | e8ae0c20 | Michael Hanselmann | if node_name not in node2disk: |
360 | e8ae0c20 | Michael Hanselmann | node2disk[node_name] = [] |
361 | e8ae0c20 | Michael Hanselmann | |
362 | e8ae0c20 | Michael Hanselmann | m = re_disk.match(phys) |
363 | e8ae0c20 | Michael Hanselmann | if not m: |
364 | e8ae0c20 | Michael Hanselmann | raise qa_error.Error("Unknown disk name format: %s" % disk) |
365 | e8ae0c20 | Michael Hanselmann | |
366 | e8ae0c20 | Michael Hanselmann | name = m.group(1)
|
367 | e8ae0c20 | Michael Hanselmann | if name not in node2disk[node_name]: |
368 | e8ae0c20 | Michael Hanselmann | node2disk[node_name].append(name) |
369 | e8ae0c20 | Michael Hanselmann | |
370 | e8ae0c20 | Michael Hanselmann | if [node2_full, node_full][int(onmaster)] not in node2disk: |
371 | f4bc1f2c | Michael Hanselmann | raise qa_error.Error("Couldn't find physical disks used on" |
372 | f4bc1f2c | Michael Hanselmann | " %s node" % ["secondary", "master"][int(onmaster)]) |
373 | e8ae0c20 | Michael Hanselmann | |
374 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Checking whether nodes have ability to stop" |
375 | 29df1f02 | Michael Hanselmann | " disks")
|
376 | e8ae0c20 | Michael Hanselmann | for node_name, disks in node2disk.iteritems(): |
377 | e8ae0c20 | Michael Hanselmann | cmds = [] |
378 | e8ae0c20 | Michael Hanselmann | for disk in disks: |
379 | e8ae0c20 | Michael Hanselmann | cmds.append(sq(["test", "-f", _GetDiskStatePath(disk)])) |
380 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(node_name, ' && '.join(cmds)).wait(), 0) |
381 | e8ae0c20 | Michael Hanselmann | |
382 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Getting device paths") |
383 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'activate-disks', instance['name']] |
384 | e8ae0c20 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master['primary'], sq(cmd))
|
385 | e8ae0c20 | Michael Hanselmann | devpath = [] |
386 | e8ae0c20 | Michael Hanselmann | for line in output.splitlines(): |
387 | e8ae0c20 | Michael Hanselmann | (_, _, tmpdevpath) = line.split(':')
|
388 | e8ae0c20 | Michael Hanselmann | devpath.append(tmpdevpath) |
389 | 29df1f02 | Michael Hanselmann | print devpath
|
390 | e8ae0c20 | Michael Hanselmann | |
391 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Getting drbd device paths") |
392 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'info', instance['name']] |
393 | e8ae0c20 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master['primary'], sq(cmd))
|
394 | 29df1f02 | Michael Hanselmann | pattern = (r'\s+-\s+sd[a-z]+,\s+type:\s+drbd8?,\s+.*$'
|
395 | e8ae0c20 | Michael Hanselmann | r'\s+primary:\s+(/dev/drbd\d+)\s+')
|
396 | e8ae0c20 | Michael Hanselmann | drbddevs = re.findall(pattern, output, re.M) |
397 | 29df1f02 | Michael Hanselmann | print drbddevs
|
398 | e8ae0c20 | Michael Hanselmann | |
399 | e8ae0c20 | Michael Hanselmann | halted_disks = [] |
400 | e8ae0c20 | Michael Hanselmann | try:
|
401 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Deactivating disks") |
402 | b1ffe1eb | Michael Hanselmann | cmds = [] |
403 | b1ffe1eb | Michael Hanselmann | for name in node2disk[[node2_full, node_full][int(onmaster)]]: |
404 | b1ffe1eb | Michael Hanselmann | halted_disks.append(name) |
405 | b1ffe1eb | Michael Hanselmann | cmds.append(sq(["echo", "offline"]) + " >%s" % _GetDiskStatePath(name)) |
406 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH([node2, node][int(onmaster)]['primary'], |
407 | b1ffe1eb | Michael Hanselmann | ' && '.join(cmds)).wait(), 0) |
408 | b1ffe1eb | Michael Hanselmann | |
409 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Write to disks and give some time to notice" |
410 | 29df1f02 | Michael Hanselmann | " to notice the problem")
|
411 | e8ae0c20 | Michael Hanselmann | cmds = [] |
412 | e8ae0c20 | Michael Hanselmann | for disk in devpath: |
413 | e8ae0c20 | Michael Hanselmann | cmds.append(sq(["dd", "count=1", "bs=512", "conv=notrunc", |
414 | e8ae0c20 | Michael Hanselmann | "if=%s" % disk, "of=%s" % disk])) |
415 | e8ae0c20 | Michael Hanselmann | for _ in (0, 1, 2): |
416 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], ' && '.join(cmds)).wait(), 0) |
417 | e8ae0c20 | Michael Hanselmann | time.sleep(3)
|
418 | e8ae0c20 | Michael Hanselmann | |
419 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Debugging info") |
420 | b1ffe1eb | Michael Hanselmann | for name in drbddevs: |
421 | b1ffe1eb | Michael Hanselmann | cmd = ['drbdsetup', name, 'show'] |
422 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], sq(cmd)).wait(), 0) |
423 | b1ffe1eb | Michael Hanselmann | |
424 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'info', instance['name']] |
425 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
426 | e8ae0c20 | Michael Hanselmann | |
427 | e8ae0c20 | Michael Hanselmann | finally:
|
428 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Activating disks again") |
429 | e8ae0c20 | Michael Hanselmann | cmds = [] |
430 | e8ae0c20 | Michael Hanselmann | for name in halted_disks: |
431 | e8ae0c20 | Michael Hanselmann | cmds.append(sq(["echo", "running"]) + " >%s" % _GetDiskStatePath(name)) |
432 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH([node2, node][int(onmaster)]['primary'], |
433 | e8ae0c20 | Michael Hanselmann | '; '.join(cmds)).wait(), 0) |
434 | e8ae0c20 | Michael Hanselmann | |
435 | b1ffe1eb | Michael Hanselmann | if onmaster:
|
436 | b1ffe1eb | Michael Hanselmann | for name in drbddevs: |
437 | b1ffe1eb | Michael Hanselmann | cmd = ['drbdsetup', name, 'detach'] |
438 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], sq(cmd)).wait(), 0) |
439 | b1ffe1eb | Michael Hanselmann | else:
|
440 | b1ffe1eb | Michael Hanselmann | for name in drbddevs: |
441 | b1ffe1eb | Michael Hanselmann | cmd = ['drbdsetup', name, 'disconnect'] |
442 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH(node2['primary'], sq(cmd)).wait(), 0) |
443 | b1ffe1eb | Michael Hanselmann | |
444 | 29df1f02 | Michael Hanselmann | # TODO
|
445 | 29df1f02 | Michael Hanselmann | #cmd = ['vgs']
|
446 | 29df1f02 | Michael Hanselmann | #AssertEqual(StartSSH([node2, node][int(onmaster)]['primary'],
|
447 | 29df1f02 | Michael Hanselmann | # sq(cmd)).wait(), 0)
|
448 | b1ffe1eb | Michael Hanselmann | |
449 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Making sure disks are up again") |
450 | 29df1f02 | Michael Hanselmann | cmd = ['gnt-instance', 'replace-disks', instance['name']] |
451 | 29df1f02 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
452 | 29df1f02 | Michael Hanselmann | |
453 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Restarting instance") |
454 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'shutdown', instance['name']] |
455 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
456 | e8ae0c20 | Michael Hanselmann | |
457 | b1ffe1eb | Michael Hanselmann | cmd = ['gnt-instance', 'startup', instance['name']] |
458 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
459 | e8ae0c20 | Michael Hanselmann | |
460 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-cluster', 'verify'] |
461 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
462 | e8ae0c20 | Michael Hanselmann | |
463 | e8ae0c20 | Michael Hanselmann | |
464 | e8ae0c20 | Michael Hanselmann | def TestInstanceMasterDiskFailure(instance, node, node2): |
465 | e8ae0c20 | Michael Hanselmann | """Testing disk failure on master node."""
|
466 | f4bc1f2c | Michael Hanselmann | print qa_utils.FormatError("Disk failure on primary node cannot be" |
467 | f4bc1f2c | Michael Hanselmann | " tested due to potential crashes.")
|
468 | e8ae0c20 | Michael Hanselmann | # The following can cause crashes, thus it's disabled until fixed
|
469 | dfe11bad | Michael Hanselmann | #return _TestInstanceDiskFailure(instance, node, node2, True)
|
470 | e8ae0c20 | Michael Hanselmann | |
471 | e8ae0c20 | Michael Hanselmann | |
472 | e8ae0c20 | Michael Hanselmann | def TestInstanceSecondaryDiskFailure(instance, node, node2): |
473 | e8ae0c20 | Michael Hanselmann | """Testing disk failure on secondary node."""
|
474 | e8ae0c20 | Michael Hanselmann | return _TestInstanceDiskFailure(instance, node, node2, False) |