root / qa / qa_instance.py @ 936f3c59
History | View | Annotate | Download (13.2 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 | 8a4e8898 | Michael Hanselmann | for reboottype in ["soft", "hard", "full"]: |
115 | 8a4e8898 | Michael Hanselmann | cmd = ['gnt-instance', 'reboot', '--type=%s' % reboottype, |
116 | 8a4e8898 | Michael Hanselmann | instance['name']]
|
117 | 8a4e8898 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
118 | 8a4e8898 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
119 | 8a4e8898 | Michael Hanselmann | |
120 | 8a4e8898 | Michael Hanselmann | |
121 | 283f9d4c | Michael Hanselmann | def TestInstanceReinstall(instance): |
122 | 283f9d4c | Michael Hanselmann | """gnt-instance reinstall"""
|
123 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
124 | 283f9d4c | Michael Hanselmann | |
125 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-instance', 'reinstall', '-f', instance['name']] |
126 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
127 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
128 | 283f9d4c | Michael Hanselmann | |
129 | 283f9d4c | Michael Hanselmann | |
130 | cec9845c | Michael Hanselmann | def TestInstanceFailover(instance): |
131 | cec9845c | Michael Hanselmann | """gnt-instance failover"""
|
132 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
133 | cec9845c | Michael Hanselmann | |
134 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'failover', '--force', instance['name']] |
135 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
136 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
137 | cec9845c | Michael Hanselmann | |
138 | 76f59a32 | Michael Hanselmann | # ... and back
|
139 | 76f59a32 | Michael Hanselmann | cmd = ['gnt-instance', 'failover', '--force', instance['name']] |
140 | 76f59a32 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
141 | 76f59a32 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
142 | 76f59a32 | Michael Hanselmann | |
143 | cec9845c | Michael Hanselmann | |
144 | cec9845c | Michael Hanselmann | def TestInstanceInfo(instance): |
145 | cec9845c | Michael Hanselmann | """gnt-instance info"""
|
146 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
147 | cec9845c | Michael Hanselmann | |
148 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'info', instance['name']] |
149 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
150 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
151 | 5d640672 | Michael Hanselmann | |
152 | 5d640672 | Michael Hanselmann | |
153 | c0f74c55 | Iustin Pop | def TestInstanceModify(instance): |
154 | c0f74c55 | Iustin Pop | """gnt-instance modify"""
|
155 | c0f74c55 | Iustin Pop | master = qa_config.GetMasterNode() |
156 | c0f74c55 | Iustin Pop | |
157 | 1d693311 | Michael Hanselmann | # Assume /sbin/init exists on all systems
|
158 | 1d693311 | Michael Hanselmann | test_kernel = "/sbin/init"
|
159 | 1d693311 | Michael Hanselmann | test_initrd = test_kernel |
160 | 1d693311 | Michael Hanselmann | |
161 | c0f74c55 | Iustin Pop | orig_memory = qa_config.get('mem')
|
162 | c0f74c55 | Iustin Pop | orig_bridge = qa_config.get('bridge', 'xen-br0') |
163 | c0f74c55 | Iustin Pop | args = [ |
164 | 1d693311 | Michael Hanselmann | ["-B", "%s=128" % constants.BE_MEMORY], |
165 | 1d693311 | Michael Hanselmann | ["-B", "%s=%s" % (constants.BE_MEMORY, orig_memory)], |
166 | 1d693311 | Michael Hanselmann | ["-B", "%s=2" % constants.BE_VCPUS], |
167 | 1d693311 | Michael Hanselmann | ["-B", "%s=1" % constants.BE_VCPUS], |
168 | 1d693311 | Michael Hanselmann | ["-B", "%s=%s" % (constants.BE_VCPUS, constants.VALUE_DEFAULT)], |
169 | 1d693311 | Michael Hanselmann | |
170 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_KERNEL_PATH, test_kernel)], |
171 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_KERNEL_PATH, constants.VALUE_DEFAULT)], |
172 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_INITRD_PATH, test_initrd)], |
173 | 5645d16b | Iustin Pop | ["-H", "no_%s" % (constants.HV_INITRD_PATH, )], |
174 | 1d693311 | Michael Hanselmann | ["-H", "%s=%s" % (constants.HV_INITRD_PATH, constants.VALUE_DEFAULT)], |
175 | 1d693311 | Michael Hanselmann | |
176 | 1d693311 | Michael Hanselmann | # TODO: bridge tests
|
177 | 1d693311 | Michael Hanselmann | #["--bridge", "xen-br1"],
|
178 | 1d693311 | Michael Hanselmann | #["--bridge", orig_bridge],
|
179 | 1d693311 | Michael Hanselmann | |
180 | 1d693311 | Michael Hanselmann | # TODO: Do these tests only with xen-hvm
|
181 | 1d693311 | Michael Hanselmann | #["-H", "%s=acn" % constants.HV_BOOT_ORDER],
|
182 | 1d693311 | Michael Hanselmann | #["-H", "%s=%s" % (constants.HV_BOOT_ORDER, constants.VALUE_DEFAULT)],
|
183 | c0f74c55 | Iustin Pop | ] |
184 | c0f74c55 | Iustin Pop | for alist in args: |
185 | c0f74c55 | Iustin Pop | cmd = ['gnt-instance', 'modify'] + alist + [instance['name']] |
186 | c0f74c55 | Iustin Pop | AssertEqual(StartSSH(master['primary'],
|
187 | c0f74c55 | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
188 | c0f74c55 | Iustin Pop | |
189 | c0f74c55 | Iustin Pop | # check no-modify
|
190 | c0f74c55 | Iustin Pop | cmd = ['gnt-instance', 'modify', instance['name']] |
191 | c0f74c55 | Iustin Pop | AssertNotEqual(StartSSH(master['primary'],
|
192 | c0f74c55 | Iustin Pop | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
193 | c0f74c55 | Iustin Pop | |
194 | c0f74c55 | Iustin Pop | |
195 | 283f9d4c | Michael Hanselmann | def TestInstanceList(): |
196 | 283f9d4c | Michael Hanselmann | """gnt-instance list"""
|
197 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
198 | 283f9d4c | Michael Hanselmann | |
199 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-instance', 'list'] |
200 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
201 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
202 | 283f9d4c | Michael Hanselmann | |
203 | 283f9d4c | Michael Hanselmann | |
204 | 4379b1fa | Michael Hanselmann | def TestInstanceConsole(instance): |
205 | 4379b1fa | Michael Hanselmann | """gnt-instance console"""
|
206 | 4379b1fa | Michael Hanselmann | master = qa_config.GetMasterNode() |
207 | 4379b1fa | Michael Hanselmann | |
208 | 4379b1fa | Michael Hanselmann | cmd = ['gnt-instance', 'console', '--show-cmd', instance['name']] |
209 | 4379b1fa | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
210 | 4379b1fa | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
211 | 4379b1fa | Michael Hanselmann | |
212 | 4379b1fa | Michael Hanselmann | |
213 | 7910e7a5 | Michael Hanselmann | def TestReplaceDisks(instance, pnode, snode, othernode): |
214 | 7910e7a5 | Michael Hanselmann | """gnt-instance replace-disks"""
|
215 | 7910e7a5 | Michael Hanselmann | master = qa_config.GetMasterNode() |
216 | 7910e7a5 | Michael Hanselmann | |
217 | 7910e7a5 | Michael Hanselmann | def buildcmd(args): |
218 | 7910e7a5 | Michael Hanselmann | cmd = ['gnt-instance', 'replace-disks'] |
219 | 7910e7a5 | Michael Hanselmann | cmd.extend(args) |
220 | 7910e7a5 | Michael Hanselmann | cmd.append(instance["name"])
|
221 | 7910e7a5 | Michael Hanselmann | return cmd
|
222 | 7910e7a5 | Michael Hanselmann | |
223 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["-p"])
|
224 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
225 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
226 | 7910e7a5 | Michael Hanselmann | |
227 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["-s"])
|
228 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
229 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
230 | 7910e7a5 | Michael Hanselmann | |
231 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["--new-secondary=%s" % othernode["primary"]]) |
232 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
233 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
234 | 7910e7a5 | Michael Hanselmann | |
235 | 7910e7a5 | Michael Hanselmann | # Restore
|
236 | 7910e7a5 | Michael Hanselmann | cmd = buildcmd(["--new-secondary=%s" % snode["primary"]]) |
237 | 7910e7a5 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
238 | 7910e7a5 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
239 | 7910e7a5 | Michael Hanselmann | |
240 | 7910e7a5 | Michael Hanselmann | |
241 | 5d640672 | Michael Hanselmann | def TestInstanceExport(instance, node): |
242 | 5d640672 | Michael Hanselmann | """gnt-backup export"""
|
243 | 5d640672 | Michael Hanselmann | master = qa_config.GetMasterNode() |
244 | 5d640672 | Michael Hanselmann | |
245 | 5d640672 | Michael Hanselmann | cmd = ['gnt-backup', 'export', '-n', node['primary'], instance['name']] |
246 | 5d640672 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
247 | 5d640672 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
248 | 5d640672 | Michael Hanselmann | |
249 | 5d640672 | Michael Hanselmann | return qa_utils.ResolveInstanceName(instance)
|
250 | 5d640672 | Michael Hanselmann | |
251 | 5d640672 | Michael Hanselmann | |
252 | 5d640672 | Michael Hanselmann | def TestInstanceImport(node, newinst, expnode, name): |
253 | 5d640672 | Michael Hanselmann | """gnt-backup import"""
|
254 | 5d640672 | Michael Hanselmann | master = qa_config.GetMasterNode() |
255 | 5d640672 | Michael Hanselmann | |
256 | 5d640672 | Michael Hanselmann | cmd = (['gnt-backup', 'import', |
257 | 5d640672 | Michael Hanselmann | '--disk-template=plain',
|
258 | 5d640672 | Michael Hanselmann | '--no-ip-check',
|
259 | 5d640672 | Michael Hanselmann | '--src-node=%s' % expnode['primary'], |
260 | 5d640672 | Michael Hanselmann | '--src-dir=%s/%s' % (constants.EXPORT_DIR, name),
|
261 | 5d640672 | Michael Hanselmann | '--node=%s' % node['primary']] + |
262 | 5d640672 | Michael Hanselmann | _GetGenericAddParameters()) |
263 | 5d640672 | Michael Hanselmann | cmd.append(newinst['name'])
|
264 | 5d640672 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
265 | 5d640672 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
266 | 283f9d4c | Michael Hanselmann | |
267 | 283f9d4c | Michael Hanselmann | |
268 | 283f9d4c | Michael Hanselmann | def TestBackupList(expnode): |
269 | 283f9d4c | Michael Hanselmann | """gnt-backup list"""
|
270 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
271 | 283f9d4c | Michael Hanselmann | |
272 | 1e020d1b | Michael Hanselmann | cmd = ['gnt-backup', 'list', '--node=%s' % expnode['primary']] |
273 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
274 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
275 | e8ae0c20 | Michael Hanselmann | |
276 | e8ae0c20 | Michael Hanselmann | |
277 | e8ae0c20 | Michael Hanselmann | def _TestInstanceDiskFailure(instance, node, node2, onmaster): |
278 | e8ae0c20 | Michael Hanselmann | """Testing disk failure."""
|
279 | e8ae0c20 | Michael Hanselmann | master = qa_config.GetMasterNode() |
280 | e8ae0c20 | Michael Hanselmann | sq = utils.ShellQuoteArgs |
281 | e8ae0c20 | Michael Hanselmann | |
282 | e8ae0c20 | Michael Hanselmann | instance_full = qa_utils.ResolveInstanceName(instance) |
283 | e8ae0c20 | Michael Hanselmann | node_full = qa_utils.ResolveNodeName(node) |
284 | e8ae0c20 | Michael Hanselmann | node2_full = qa_utils.ResolveNodeName(node2) |
285 | e8ae0c20 | Michael Hanselmann | |
286 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Getting physical disk names") |
287 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-node', 'volumes', '--separator=|', '--no-headers', |
288 | e8ae0c20 | Michael Hanselmann | '--output=node,phys,instance',
|
289 | e8ae0c20 | Michael Hanselmann | node['primary'], node2['primary']] |
290 | e8ae0c20 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master['primary'], sq(cmd))
|
291 | e8ae0c20 | Michael Hanselmann | |
292 | e8ae0c20 | Michael Hanselmann | # Get physical disk names
|
293 | e8ae0c20 | Michael Hanselmann | re_disk = re.compile(r'^/dev/([a-z]+)\d+$')
|
294 | e8ae0c20 | Michael Hanselmann | node2disk = {} |
295 | e8ae0c20 | Michael Hanselmann | for line in output.splitlines(): |
296 | e8ae0c20 | Michael Hanselmann | (node_name, phys, inst) = line.split('|')
|
297 | e8ae0c20 | Michael Hanselmann | if inst == instance_full:
|
298 | e8ae0c20 | Michael Hanselmann | if node_name not in node2disk: |
299 | e8ae0c20 | Michael Hanselmann | node2disk[node_name] = [] |
300 | e8ae0c20 | Michael Hanselmann | |
301 | e8ae0c20 | Michael Hanselmann | m = re_disk.match(phys) |
302 | e8ae0c20 | Michael Hanselmann | if not m: |
303 | e8ae0c20 | Michael Hanselmann | raise qa_error.Error("Unknown disk name format: %s" % disk) |
304 | e8ae0c20 | Michael Hanselmann | |
305 | e8ae0c20 | Michael Hanselmann | name = m.group(1)
|
306 | e8ae0c20 | Michael Hanselmann | if name not in node2disk[node_name]: |
307 | e8ae0c20 | Michael Hanselmann | node2disk[node_name].append(name) |
308 | e8ae0c20 | Michael Hanselmann | |
309 | e8ae0c20 | Michael Hanselmann | if [node2_full, node_full][int(onmaster)] not in node2disk: |
310 | f4bc1f2c | Michael Hanselmann | raise qa_error.Error("Couldn't find physical disks used on" |
311 | f4bc1f2c | Michael Hanselmann | " %s node" % ["secondary", "master"][int(onmaster)]) |
312 | e8ae0c20 | Michael Hanselmann | |
313 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Checking whether nodes have ability to stop" |
314 | 29df1f02 | Michael Hanselmann | " disks")
|
315 | e8ae0c20 | Michael Hanselmann | for node_name, disks in node2disk.iteritems(): |
316 | e8ae0c20 | Michael Hanselmann | cmds = [] |
317 | e8ae0c20 | Michael Hanselmann | for disk in disks: |
318 | e8ae0c20 | Michael Hanselmann | cmds.append(sq(["test", "-f", _GetDiskStatePath(disk)])) |
319 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(node_name, ' && '.join(cmds)).wait(), 0) |
320 | e8ae0c20 | Michael Hanselmann | |
321 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Getting device paths") |
322 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'activate-disks', instance['name']] |
323 | e8ae0c20 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master['primary'], sq(cmd))
|
324 | e8ae0c20 | Michael Hanselmann | devpath = [] |
325 | e8ae0c20 | Michael Hanselmann | for line in output.splitlines(): |
326 | e8ae0c20 | Michael Hanselmann | (_, _, tmpdevpath) = line.split(':')
|
327 | e8ae0c20 | Michael Hanselmann | devpath.append(tmpdevpath) |
328 | 29df1f02 | Michael Hanselmann | print devpath
|
329 | e8ae0c20 | Michael Hanselmann | |
330 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Getting drbd device paths") |
331 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'info', instance['name']] |
332 | e8ae0c20 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master['primary'], sq(cmd))
|
333 | 29df1f02 | Michael Hanselmann | pattern = (r'\s+-\s+sd[a-z]+,\s+type:\s+drbd8?,\s+.*$'
|
334 | e8ae0c20 | Michael Hanselmann | r'\s+primary:\s+(/dev/drbd\d+)\s+')
|
335 | e8ae0c20 | Michael Hanselmann | drbddevs = re.findall(pattern, output, re.M) |
336 | 29df1f02 | Michael Hanselmann | print drbddevs
|
337 | e8ae0c20 | Michael Hanselmann | |
338 | e8ae0c20 | Michael Hanselmann | halted_disks = [] |
339 | e8ae0c20 | Michael Hanselmann | try:
|
340 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Deactivating disks") |
341 | b1ffe1eb | Michael Hanselmann | cmds = [] |
342 | b1ffe1eb | Michael Hanselmann | for name in node2disk[[node2_full, node_full][int(onmaster)]]: |
343 | b1ffe1eb | Michael Hanselmann | halted_disks.append(name) |
344 | b1ffe1eb | Michael Hanselmann | cmds.append(sq(["echo", "offline"]) + " >%s" % _GetDiskStatePath(name)) |
345 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH([node2, node][int(onmaster)]['primary'], |
346 | b1ffe1eb | Michael Hanselmann | ' && '.join(cmds)).wait(), 0) |
347 | b1ffe1eb | Michael Hanselmann | |
348 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Write to disks and give some time to notice" |
349 | 29df1f02 | Michael Hanselmann | " to notice the problem")
|
350 | e8ae0c20 | Michael Hanselmann | cmds = [] |
351 | e8ae0c20 | Michael Hanselmann | for disk in devpath: |
352 | e8ae0c20 | Michael Hanselmann | cmds.append(sq(["dd", "count=1", "bs=512", "conv=notrunc", |
353 | e8ae0c20 | Michael Hanselmann | "if=%s" % disk, "of=%s" % disk])) |
354 | e8ae0c20 | Michael Hanselmann | for _ in (0, 1, 2): |
355 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], ' && '.join(cmds)).wait(), 0) |
356 | e8ae0c20 | Michael Hanselmann | time.sleep(3)
|
357 | e8ae0c20 | Michael Hanselmann | |
358 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Debugging info") |
359 | b1ffe1eb | Michael Hanselmann | for name in drbddevs: |
360 | b1ffe1eb | Michael Hanselmann | cmd = ['drbdsetup', name, 'show'] |
361 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], sq(cmd)).wait(), 0) |
362 | b1ffe1eb | Michael Hanselmann | |
363 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'info', instance['name']] |
364 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
365 | e8ae0c20 | Michael Hanselmann | |
366 | e8ae0c20 | Michael Hanselmann | finally:
|
367 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Activating disks again") |
368 | e8ae0c20 | Michael Hanselmann | cmds = [] |
369 | e8ae0c20 | Michael Hanselmann | for name in halted_disks: |
370 | e8ae0c20 | Michael Hanselmann | cmds.append(sq(["echo", "running"]) + " >%s" % _GetDiskStatePath(name)) |
371 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH([node2, node][int(onmaster)]['primary'], |
372 | e8ae0c20 | Michael Hanselmann | '; '.join(cmds)).wait(), 0) |
373 | e8ae0c20 | Michael Hanselmann | |
374 | b1ffe1eb | Michael Hanselmann | if onmaster:
|
375 | b1ffe1eb | Michael Hanselmann | for name in drbddevs: |
376 | b1ffe1eb | Michael Hanselmann | cmd = ['drbdsetup', name, 'detach'] |
377 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], sq(cmd)).wait(), 0) |
378 | b1ffe1eb | Michael Hanselmann | else:
|
379 | b1ffe1eb | Michael Hanselmann | for name in drbddevs: |
380 | b1ffe1eb | Michael Hanselmann | cmd = ['drbdsetup', name, 'disconnect'] |
381 | b1ffe1eb | Michael Hanselmann | AssertEqual(StartSSH(node2['primary'], sq(cmd)).wait(), 0) |
382 | b1ffe1eb | Michael Hanselmann | |
383 | 29df1f02 | Michael Hanselmann | # TODO
|
384 | 29df1f02 | Michael Hanselmann | #cmd = ['vgs']
|
385 | 29df1f02 | Michael Hanselmann | #AssertEqual(StartSSH([node2, node][int(onmaster)]['primary'],
|
386 | 29df1f02 | Michael Hanselmann | # sq(cmd)).wait(), 0)
|
387 | b1ffe1eb | Michael Hanselmann | |
388 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Making sure disks are up again") |
389 | 29df1f02 | Michael Hanselmann | cmd = ['gnt-instance', 'replace-disks', instance['name']] |
390 | 29df1f02 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
391 | 29df1f02 | Michael Hanselmann | |
392 | 29df1f02 | Michael Hanselmann | print qa_utils.FormatInfo("Restarting instance") |
393 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-instance', 'shutdown', instance['name']] |
394 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
395 | e8ae0c20 | Michael Hanselmann | |
396 | b1ffe1eb | Michael Hanselmann | cmd = ['gnt-instance', 'startup', instance['name']] |
397 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
398 | e8ae0c20 | Michael Hanselmann | |
399 | e8ae0c20 | Michael Hanselmann | cmd = ['gnt-cluster', 'verify'] |
400 | e8ae0c20 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], sq(cmd)).wait(), 0) |
401 | e8ae0c20 | Michael Hanselmann | |
402 | e8ae0c20 | Michael Hanselmann | |
403 | e8ae0c20 | Michael Hanselmann | def TestInstanceMasterDiskFailure(instance, node, node2): |
404 | e8ae0c20 | Michael Hanselmann | """Testing disk failure on master node."""
|
405 | f4bc1f2c | Michael Hanselmann | print qa_utils.FormatError("Disk failure on primary node cannot be" |
406 | f4bc1f2c | Michael Hanselmann | " tested due to potential crashes.")
|
407 | e8ae0c20 | Michael Hanselmann | # The following can cause crashes, thus it's disabled until fixed
|
408 | dfe11bad | Michael Hanselmann | #return _TestInstanceDiskFailure(instance, node, node2, True)
|
409 | e8ae0c20 | Michael Hanselmann | |
410 | e8ae0c20 | Michael Hanselmann | |
411 | e8ae0c20 | Michael Hanselmann | def TestInstanceSecondaryDiskFailure(instance, node, node2): |
412 | e8ae0c20 | Michael Hanselmann | """Testing disk failure on secondary node."""
|
413 | e8ae0c20 | Michael Hanselmann | return _TestInstanceDiskFailure(instance, node, node2, False) |