root / test / py / ganeti.storage.drbd_unittest.py @ 14933c17
History | View | Annotate | Download (17.2 kB)
1 | 873878b9 | Thomas Thrainer | #!/usr/bin/python
|
---|---|---|---|
2 | 873878b9 | Thomas Thrainer | #
|
3 | 873878b9 | Thomas Thrainer | |
4 | 873878b9 | Thomas Thrainer | # Copyright (C) 2006, 2007, 2010, 2012, 2013 Google Inc.
|
5 | 873878b9 | Thomas Thrainer | #
|
6 | 873878b9 | Thomas Thrainer | # This program is free software; you can redistribute it and/or modify
|
7 | 873878b9 | Thomas Thrainer | # it under the terms of the GNU General Public License as published by
|
8 | 873878b9 | Thomas Thrainer | # the Free Software Foundation; either version 2 of the License, or
|
9 | 873878b9 | Thomas Thrainer | # (at your option) any later version.
|
10 | 873878b9 | Thomas Thrainer | #
|
11 | 873878b9 | Thomas Thrainer | # This program is distributed in the hope that it will be useful, but
|
12 | 873878b9 | Thomas Thrainer | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 873878b9 | Thomas Thrainer | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 873878b9 | Thomas Thrainer | # General Public License for more details.
|
15 | 873878b9 | Thomas Thrainer | #
|
16 | 873878b9 | Thomas Thrainer | # You should have received a copy of the GNU General Public License
|
17 | 873878b9 | Thomas Thrainer | # along with this program; if not, write to the Free Software
|
18 | 873878b9 | Thomas Thrainer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 873878b9 | Thomas Thrainer | # 02110-1301, USA.
|
20 | 873878b9 | Thomas Thrainer | |
21 | 873878b9 | Thomas Thrainer | |
22 | 873878b9 | Thomas Thrainer | """Script for unittesting the drbd module"""
|
23 | 873878b9 | Thomas Thrainer | |
24 | 873878b9 | Thomas Thrainer | |
25 | 873878b9 | Thomas Thrainer | import os |
26 | 873878b9 | Thomas Thrainer | |
27 | 873878b9 | Thomas Thrainer | from ganeti import constants |
28 | 873878b9 | Thomas Thrainer | from ganeti import errors |
29 | cde49218 | Helga Velroyen | from ganeti.storage import drbd |
30 | cde49218 | Helga Velroyen | from ganeti.storage import drbd_info |
31 | cde49218 | Helga Velroyen | from ganeti.storage import drbd_cmdgen |
32 | 873878b9 | Thomas Thrainer | |
33 | 873878b9 | Thomas Thrainer | import testutils |
34 | 873878b9 | Thomas Thrainer | |
35 | 873878b9 | Thomas Thrainer | |
36 | 873878b9 | Thomas Thrainer | class TestDRBD8(testutils.GanetiTestCase): |
37 | 873878b9 | Thomas Thrainer | def testGetVersion(self): |
38 | 873878b9 | Thomas Thrainer | data = [ |
39 | 5bb0a1cb | Thomas Thrainer | "version: 8.0.0 (api:76/proto:80)",
|
40 | 5bb0a1cb | Thomas Thrainer | "version: 8.0.12 (api:76/proto:86-91)",
|
41 | 5bb0a1cb | Thomas Thrainer | "version: 8.2.7 (api:88/proto:0-100)",
|
42 | 5bb0a1cb | Thomas Thrainer | "version: 8.3.7.49 (api:188/proto:13-191)",
|
43 | 873878b9 | Thomas Thrainer | ] |
44 | 873878b9 | Thomas Thrainer | result = [ |
45 | 873878b9 | Thomas Thrainer | { |
46 | 873878b9 | Thomas Thrainer | "k_major": 8, |
47 | 873878b9 | Thomas Thrainer | "k_minor": 0, |
48 | 5bb0a1cb | Thomas Thrainer | "k_point": 0, |
49 | 5bb0a1cb | Thomas Thrainer | "api": 76, |
50 | 5bb0a1cb | Thomas Thrainer | "proto": 80, |
51 | 5bb0a1cb | Thomas Thrainer | }, |
52 | 5bb0a1cb | Thomas Thrainer | { |
53 | 5bb0a1cb | Thomas Thrainer | "k_major": 8, |
54 | 5bb0a1cb | Thomas Thrainer | "k_minor": 0, |
55 | 873878b9 | Thomas Thrainer | "k_point": 12, |
56 | 873878b9 | Thomas Thrainer | "api": 76, |
57 | 873878b9 | Thomas Thrainer | "proto": 86, |
58 | 873878b9 | Thomas Thrainer | "proto2": "91", |
59 | 873878b9 | Thomas Thrainer | }, |
60 | 873878b9 | Thomas Thrainer | { |
61 | 873878b9 | Thomas Thrainer | "k_major": 8, |
62 | 873878b9 | Thomas Thrainer | "k_minor": 2, |
63 | 873878b9 | Thomas Thrainer | "k_point": 7, |
64 | 873878b9 | Thomas Thrainer | "api": 88, |
65 | 873878b9 | Thomas Thrainer | "proto": 0, |
66 | 873878b9 | Thomas Thrainer | "proto2": "100", |
67 | 873878b9 | Thomas Thrainer | }, |
68 | 873878b9 | Thomas Thrainer | { |
69 | 873878b9 | Thomas Thrainer | "k_major": 8, |
70 | 873878b9 | Thomas Thrainer | "k_minor": 3, |
71 | 873878b9 | Thomas Thrainer | "k_point": 7, |
72 | 5bb0a1cb | Thomas Thrainer | "k_fix": "49", |
73 | 873878b9 | Thomas Thrainer | "api": 188, |
74 | 873878b9 | Thomas Thrainer | "proto": 13, |
75 | 873878b9 | Thomas Thrainer | "proto2": "191", |
76 | 873878b9 | Thomas Thrainer | } |
77 | 873878b9 | Thomas Thrainer | ] |
78 | 873878b9 | Thomas Thrainer | for d, r in zip(data, result): |
79 | 5bb0a1cb | Thomas Thrainer | info = drbd.DRBD8Info.CreateFromLines([d]) |
80 | 873878b9 | Thomas Thrainer | self.assertEqual(info.GetVersion(), r)
|
81 | 5bb0a1cb | Thomas Thrainer | self.assertEqual(info.GetVersionString(), d.replace("version: ", "")) |
82 | 873878b9 | Thomas Thrainer | |
83 | 873878b9 | Thomas Thrainer | |
84 | 873878b9 | Thomas Thrainer | class TestDRBD8Runner(testutils.GanetiTestCase): |
85 | 239364d0 | Thomas Thrainer | """Testing case for drbd.DRBD8Dev"""
|
86 | 873878b9 | Thomas Thrainer | |
87 | 873878b9 | Thomas Thrainer | @staticmethod
|
88 | 8520f4b9 | Thomas Thrainer | def _has_disk(data, dname, mname, meta_index=0): |
89 | 873878b9 | Thomas Thrainer | """Check local disk corectness"""
|
90 | 873878b9 | Thomas Thrainer | retval = ( |
91 | 873878b9 | Thomas Thrainer | "local_dev" in data and |
92 | 873878b9 | Thomas Thrainer | data["local_dev"] == dname and |
93 | 873878b9 | Thomas Thrainer | "meta_dev" in data and |
94 | 873878b9 | Thomas Thrainer | data["meta_dev"] == mname and |
95 | 8520f4b9 | Thomas Thrainer | ((meta_index is None and |
96 | 8520f4b9 | Thomas Thrainer | "meta_index" not in data) or |
97 | 8520f4b9 | Thomas Thrainer | ("meta_index" in data and |
98 | 8520f4b9 | Thomas Thrainer | data["meta_index"] == meta_index)
|
99 | 8520f4b9 | Thomas Thrainer | ) |
100 | 873878b9 | Thomas Thrainer | ) |
101 | 873878b9 | Thomas Thrainer | return retval
|
102 | 873878b9 | Thomas Thrainer | |
103 | 873878b9 | Thomas Thrainer | @staticmethod
|
104 | 873878b9 | Thomas Thrainer | def _has_net(data, local, remote): |
105 | 873878b9 | Thomas Thrainer | """Check network connection parameters"""
|
106 | 873878b9 | Thomas Thrainer | retval = ( |
107 | 873878b9 | Thomas Thrainer | "local_addr" in data and |
108 | 873878b9 | Thomas Thrainer | data["local_addr"] == local and |
109 | 873878b9 | Thomas Thrainer | "remote_addr" in data and |
110 | 873878b9 | Thomas Thrainer | data["remote_addr"] == remote
|
111 | 873878b9 | Thomas Thrainer | ) |
112 | 873878b9 | Thomas Thrainer | return retval
|
113 | 873878b9 | Thomas Thrainer | |
114 | 873878b9 | Thomas Thrainer | def testParser83Creation(self): |
115 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser creation"""
|
116 | 873878b9 | Thomas Thrainer | drbd_info.DRBD83ShowInfo._GetShowParser() |
117 | 873878b9 | Thomas Thrainer | |
118 | 873878b9 | Thomas Thrainer | def testParser84Creation(self): |
119 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser creation"""
|
120 | 873878b9 | Thomas Thrainer | drbd_info.DRBD84ShowInfo._GetShowParser() |
121 | 873878b9 | Thomas Thrainer | |
122 | 873878b9 | Thomas Thrainer | def testParser80(self): |
123 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk and network version 8.0"""
|
124 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.0.txt")
|
125 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
126 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
127 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
128 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
129 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
130 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
131 | 873878b9 | Thomas Thrainer | "Wrong network info (8.0.x)")
|
132 | 873878b9 | Thomas Thrainer | |
133 | 873878b9 | Thomas Thrainer | def testParser83(self): |
134 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk and network version 8.3"""
|
135 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.3.txt")
|
136 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
137 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
138 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
139 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
140 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
141 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
142 | 873878b9 | Thomas Thrainer | "Wrong network info (8.3.x)")
|
143 | 873878b9 | Thomas Thrainer | |
144 | 873878b9 | Thomas Thrainer | def testParser84(self): |
145 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk and network version 8.4"""
|
146 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.4.txt")
|
147 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD84ShowInfo.GetDevInfo(data) |
148 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
149 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
150 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
151 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
152 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
153 | 873878b9 | Thomas Thrainer | "Wrong network info (8.4.x)")
|
154 | 873878b9 | Thomas Thrainer | |
155 | 8520f4b9 | Thomas Thrainer | def testParser84NoDiskParams(self): |
156 | 8520f4b9 | Thomas Thrainer | """Test drbdsetup show parser for 8.4 without disk params
|
157 | 8520f4b9 | Thomas Thrainer |
|
158 | 8520f4b9 | Thomas Thrainer | The missing disk parameters occur after re-attaching a local disk but
|
159 | 8520f4b9 | Thomas Thrainer | before setting the disk params.
|
160 | 8520f4b9 | Thomas Thrainer |
|
161 | 8520f4b9 | Thomas Thrainer | """
|
162 | 8520f4b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.4-no-disk-params.txt")
|
163 | 8520f4b9 | Thomas Thrainer | result = drbd_info.DRBD84ShowInfo.GetDevInfo(data) |
164 | 8520f4b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
165 | 8520f4b9 | Thomas Thrainer | "/dev/xenvg/test.meta", meta_index=None), |
166 | 8520f4b9 | Thomas Thrainer | "Wrong local disk info")
|
167 | 8520f4b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
168 | 8520f4b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
169 | 8520f4b9 | Thomas Thrainer | "Wrong network info (8.4.x)")
|
170 | 8520f4b9 | Thomas Thrainer | |
171 | 873878b9 | Thomas Thrainer | def testParserNetIP4(self): |
172 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for IPv4 network"""
|
173 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-net-ip4.txt")
|
174 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
175 | 873878b9 | Thomas Thrainer | self.failUnless(("local_dev" not in result and |
176 | 873878b9 | Thomas Thrainer | "meta_dev" not in result and |
177 | 873878b9 | Thomas Thrainer | "meta_index" not in result), |
178 | 873878b9 | Thomas Thrainer | "Should not find local disk info")
|
179 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11002), |
180 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11002)), |
181 | 873878b9 | Thomas Thrainer | "Wrong network info (IPv4)")
|
182 | 873878b9 | Thomas Thrainer | |
183 | 873878b9 | Thomas Thrainer | def testParserNetIP6(self): |
184 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for IPv6 network"""
|
185 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-net-ip6.txt")
|
186 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
187 | 873878b9 | Thomas Thrainer | self.failUnless(("local_dev" not in result and |
188 | 873878b9 | Thomas Thrainer | "meta_dev" not in result and |
189 | 873878b9 | Thomas Thrainer | "meta_index" not in result), |
190 | 873878b9 | Thomas Thrainer | "Should not find local disk info")
|
191 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("2001:db8:65::1", 11048), |
192 | 873878b9 | Thomas Thrainer | ("2001:db8:66::1", 11048)), |
193 | 873878b9 | Thomas Thrainer | "Wrong network info (IPv6)")
|
194 | 873878b9 | Thomas Thrainer | |
195 | 873878b9 | Thomas Thrainer | def testParserDisk(self): |
196 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk"""
|
197 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-disk.txt")
|
198 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
199 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
200 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
201 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
202 | 873878b9 | Thomas Thrainer | self.failUnless(("local_addr" not in result and |
203 | 873878b9 | Thomas Thrainer | "remote_addr" not in result), |
204 | 873878b9 | Thomas Thrainer | "Should not find network info")
|
205 | 873878b9 | Thomas Thrainer | |
206 | 873878b9 | Thomas Thrainer | def testBarriersOptions(self): |
207 | 873878b9 | Thomas Thrainer | """Test class method that generates drbdsetup options for disk barriers"""
|
208 | 873878b9 | Thomas Thrainer | # Tests that should fail because of wrong version/options combinations
|
209 | 873878b9 | Thomas Thrainer | should_fail = [ |
210 | 873878b9 | Thomas Thrainer | (8, 0, 12, "bfd", True), |
211 | 873878b9 | Thomas Thrainer | (8, 0, 12, "fd", False), |
212 | 873878b9 | Thomas Thrainer | (8, 0, 12, "b", True), |
213 | 873878b9 | Thomas Thrainer | (8, 2, 7, "bfd", True), |
214 | 873878b9 | Thomas Thrainer | (8, 2, 7, "b", True) |
215 | 873878b9 | Thomas Thrainer | ] |
216 | 873878b9 | Thomas Thrainer | |
217 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel, opts, meta in should_fail: |
218 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
219 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
220 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, opts, meta) |
221 | 873878b9 | Thomas Thrainer | |
222 | 873878b9 | Thomas Thrainer | # get the valid options from the frozenset(frozenset()) in constants.
|
223 | 873878b9 | Thomas Thrainer | valid_options = [list(x)[0] for x in constants.DRBD_VALID_BARRIER_OPT] |
224 | 873878b9 | Thomas Thrainer | |
225 | 873878b9 | Thomas Thrainer | # Versions that do not support anything
|
226 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel in ((8, 0, 0), (8, 0, 11), (8, 2, 6)): |
227 | 873878b9 | Thomas Thrainer | for opts in valid_options: |
228 | 873878b9 | Thomas Thrainer | self.assertRaises(
|
229 | 873878b9 | Thomas Thrainer | errors.BlockDeviceError, |
230 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
231 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, opts, True)
|
232 | 873878b9 | Thomas Thrainer | |
233 | 873878b9 | Thomas Thrainer | # Versions with partial support (testing only options that are supported)
|
234 | 873878b9 | Thomas Thrainer | tests = [ |
235 | 873878b9 | Thomas Thrainer | (8, 0, 12, "n", False, []), |
236 | 873878b9 | Thomas Thrainer | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
237 | 873878b9 | Thomas Thrainer | (8, 2, 7, "n", False, []), |
238 | 873878b9 | Thomas Thrainer | (8, 2, 7, "fd", False, ["--no-disk-flushes", "--no-disk-drain"]), |
239 | 873878b9 | Thomas Thrainer | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
240 | 873878b9 | Thomas Thrainer | ] |
241 | 873878b9 | Thomas Thrainer | |
242 | 873878b9 | Thomas Thrainer | # Versions that support everything
|
243 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel in ((8, 3, 0), (8, 3, 12)): |
244 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "bfd", True, |
245 | 873878b9 | Thomas Thrainer | ["--no-disk-barrier", "--no-disk-drain", |
246 | 873878b9 | Thomas Thrainer | "--no-disk-flushes", "--no-md-flushes"])) |
247 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "n", False, [])) |
248 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "b", True, |
249 | 873878b9 | Thomas Thrainer | ["--no-disk-barrier", "--no-md-flushes"])) |
250 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "fd", False, |
251 | 873878b9 | Thomas Thrainer | ["--no-disk-flushes", "--no-disk-drain"])) |
252 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "n", True, ["--no-md-flushes"])) |
253 | 873878b9 | Thomas Thrainer | |
254 | 873878b9 | Thomas Thrainer | # Test execution
|
255 | 873878b9 | Thomas Thrainer | for test in tests: |
256 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, disabled_barriers, disable_meta_flush, expected = test |
257 | 873878b9 | Thomas Thrainer | args = \ |
258 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs( |
259 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, |
260 | 873878b9 | Thomas Thrainer | disabled_barriers, |
261 | 873878b9 | Thomas Thrainer | disable_meta_flush) |
262 | 873878b9 | Thomas Thrainer | self.failUnless(set(args) == set(expected), |
263 | 873878b9 | Thomas Thrainer | "For test %s, got wrong results %s" % (test, args))
|
264 | 873878b9 | Thomas Thrainer | |
265 | 873878b9 | Thomas Thrainer | # Unsupported or invalid versions
|
266 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel in ((0, 7, 25), (9, 0, 0), (7, 0, 0), (8, 4, 0)): |
267 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
268 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
269 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, "n", True) |
270 | 873878b9 | Thomas Thrainer | |
271 | 873878b9 | Thomas Thrainer | # Invalid options
|
272 | 873878b9 | Thomas Thrainer | for option in ("", "c", "whatever", "nbdfc", "nf"): |
273 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
274 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
275 | 873878b9 | Thomas Thrainer | 8, 3, 11, option, True) |
276 | 873878b9 | Thomas Thrainer | |
277 | 873878b9 | Thomas Thrainer | |
278 | 873878b9 | Thomas Thrainer | class TestDRBD8Status(testutils.GanetiTestCase): |
279 | 239364d0 | Thomas Thrainer | """Testing case for DRBD8Dev /proc status"""
|
280 | 873878b9 | Thomas Thrainer | |
281 | 873878b9 | Thomas Thrainer | def setUp(self): |
282 | 873878b9 | Thomas Thrainer | """Read in txt data"""
|
283 | 873878b9 | Thomas Thrainer | testutils.GanetiTestCase.setUp(self)
|
284 | 873878b9 | Thomas Thrainer | proc_data = testutils.TestDataFilename("proc_drbd8.txt")
|
285 | 873878b9 | Thomas Thrainer | proc80e_data = testutils.TestDataFilename("proc_drbd80-emptyline.txt")
|
286 | 873878b9 | Thomas Thrainer | proc83_data = testutils.TestDataFilename("proc_drbd83.txt")
|
287 | 873878b9 | Thomas Thrainer | proc83_sync_data = testutils.TestDataFilename("proc_drbd83_sync.txt")
|
288 | 873878b9 | Thomas Thrainer | proc83_sync_krnl_data = \ |
289 | 873878b9 | Thomas Thrainer | testutils.TestDataFilename("proc_drbd83_sync_krnl2.6.39.txt")
|
290 | 873878b9 | Thomas Thrainer | proc84_data = testutils.TestDataFilename("proc_drbd84.txt")
|
291 | 873878b9 | Thomas Thrainer | proc84_sync_data = testutils.TestDataFilename("proc_drbd84_sync.txt")
|
292 | 873878b9 | Thomas Thrainer | |
293 | 873878b9 | Thomas Thrainer | self.proc80ev_data = \
|
294 | 873878b9 | Thomas Thrainer | testutils.TestDataFilename("proc_drbd80-emptyversion.txt")
|
295 | 873878b9 | Thomas Thrainer | |
296 | 873878b9 | Thomas Thrainer | self.drbd_info = drbd.DRBD8Info.CreateFromFile(filename=proc_data)
|
297 | 873878b9 | Thomas Thrainer | self.drbd_info80e = drbd.DRBD8Info.CreateFromFile(filename=proc80e_data)
|
298 | 873878b9 | Thomas Thrainer | self.drbd_info83 = drbd.DRBD8Info.CreateFromFile(filename=proc83_data)
|
299 | 873878b9 | Thomas Thrainer | self.drbd_info83_sync = \
|
300 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile(filename=proc83_sync_data) |
301 | 873878b9 | Thomas Thrainer | self.drbd_info83_sync_krnl = \
|
302 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile(filename=proc83_sync_krnl_data) |
303 | 873878b9 | Thomas Thrainer | self.drbd_info84 = drbd.DRBD8Info.CreateFromFile(filename=proc84_data)
|
304 | 873878b9 | Thomas Thrainer | self.drbd_info84_sync = \
|
305 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile(filename=proc84_sync_data) |
306 | 873878b9 | Thomas Thrainer | |
307 | 873878b9 | Thomas Thrainer | def testIOErrors(self): |
308 | 873878b9 | Thomas Thrainer | """Test handling of errors while reading the proc file."""
|
309 | 873878b9 | Thomas Thrainer | temp_file = self._CreateTempFile()
|
310 | 873878b9 | Thomas Thrainer | os.unlink(temp_file) |
311 | 873878b9 | Thomas Thrainer | self.failUnlessRaises(errors.BlockDeviceError,
|
312 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile, filename=temp_file) |
313 | 873878b9 | Thomas Thrainer | |
314 | 873878b9 | Thomas Thrainer | def testHelper(self): |
315 | 873878b9 | Thomas Thrainer | """Test reading usermode_helper in /sys."""
|
316 | 873878b9 | Thomas Thrainer | sys_drbd_helper = testutils.TestDataFilename("sys_drbd_usermode_helper.txt")
|
317 | 47e0abee | Thomas Thrainer | drbd_helper = drbd.DRBD8.GetUsermodeHelper(filename=sys_drbd_helper) |
318 | 873878b9 | Thomas Thrainer | self.failUnlessEqual(drbd_helper, "/bin/true") |
319 | 873878b9 | Thomas Thrainer | |
320 | 873878b9 | Thomas Thrainer | def testHelperIOErrors(self): |
321 | 873878b9 | Thomas Thrainer | """Test handling of errors while reading usermode_helper in /sys."""
|
322 | 873878b9 | Thomas Thrainer | temp_file = self._CreateTempFile()
|
323 | 873878b9 | Thomas Thrainer | os.unlink(temp_file) |
324 | 873878b9 | Thomas Thrainer | self.failUnlessRaises(errors.BlockDeviceError,
|
325 | 47e0abee | Thomas Thrainer | drbd.DRBD8.GetUsermodeHelper, filename=temp_file) |
326 | 873878b9 | Thomas Thrainer | |
327 | 873878b9 | Thomas Thrainer | def testMinorNotFound(self): |
328 | 873878b9 | Thomas Thrainer | """Test not-found-minor in /proc"""
|
329 | 873878b9 | Thomas Thrainer | self.failUnless(not self.drbd_info.HasMinorStatus(9)) |
330 | 873878b9 | Thomas Thrainer | self.failUnless(not self.drbd_info83.HasMinorStatus(9)) |
331 | 873878b9 | Thomas Thrainer | self.failUnless(not self.drbd_info80e.HasMinorStatus(3)) |
332 | 873878b9 | Thomas Thrainer | |
333 | 873878b9 | Thomas Thrainer | def testLineNotMatch(self): |
334 | 873878b9 | Thomas Thrainer | """Test wrong line passed to drbd_info.DRBD8Status"""
|
335 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError, drbd_info.DRBD8Status, "foo") |
336 | 873878b9 | Thomas Thrainer | |
337 | 873878b9 | Thomas Thrainer | def testMinor0(self): |
338 | 873878b9 | Thomas Thrainer | """Test connected, primary device"""
|
339 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
340 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(0)
|
341 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
342 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_connected and stats.is_primary and |
343 | 873878b9 | Thomas Thrainer | stats.peer_secondary and stats.is_disk_uptodate)
|
344 | 873878b9 | Thomas Thrainer | |
345 | 873878b9 | Thomas Thrainer | def testMinor1(self): |
346 | 873878b9 | Thomas Thrainer | """Test connected, secondary device"""
|
347 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
348 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(1)
|
349 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
350 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_connected and stats.is_secondary and |
351 | 873878b9 | Thomas Thrainer | stats.peer_primary and stats.is_disk_uptodate)
|
352 | 873878b9 | Thomas Thrainer | |
353 | 873878b9 | Thomas Thrainer | def testMinor2(self): |
354 | 873878b9 | Thomas Thrainer | """Test unconfigured device"""
|
355 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, |
356 | 873878b9 | Thomas Thrainer | self.drbd_info80e, self.drbd_info84]: |
357 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(2)
|
358 | 873878b9 | Thomas Thrainer | self.failIf(stats.is_in_use)
|
359 | 873878b9 | Thomas Thrainer | |
360 | 873878b9 | Thomas Thrainer | def testMinor4(self): |
361 | 873878b9 | Thomas Thrainer | """Test WFconn device"""
|
362 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
363 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(4)
|
364 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
365 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_wfconn and stats.is_primary and |
366 | 873878b9 | Thomas Thrainer | stats.rrole == "Unknown" and |
367 | 873878b9 | Thomas Thrainer | stats.is_disk_uptodate) |
368 | 873878b9 | Thomas Thrainer | |
369 | 873878b9 | Thomas Thrainer | def testMinor6(self): |
370 | 873878b9 | Thomas Thrainer | """Test diskless device"""
|
371 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
372 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(6)
|
373 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
374 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_connected and stats.is_secondary and |
375 | 873878b9 | Thomas Thrainer | stats.peer_primary and stats.is_diskless)
|
376 | 873878b9 | Thomas Thrainer | |
377 | 873878b9 | Thomas Thrainer | def testMinor8(self): |
378 | 873878b9 | Thomas Thrainer | """Test standalone device"""
|
379 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
380 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(8)
|
381 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
382 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_standalone and |
383 | 873878b9 | Thomas Thrainer | stats.rrole == "Unknown" and |
384 | 873878b9 | Thomas Thrainer | stats.is_disk_uptodate) |
385 | 873878b9 | Thomas Thrainer | |
386 | 873878b9 | Thomas Thrainer | def testDRBD83SyncFine(self): |
387 | 873878b9 | Thomas Thrainer | stats = self.drbd_info83_sync.GetMinorStatus(3) |
388 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_resync)
|
389 | 873878b9 | Thomas Thrainer | self.assertAlmostEqual(stats.sync_percent, 34.9) |
390 | 873878b9 | Thomas Thrainer | |
391 | 873878b9 | Thomas Thrainer | def testDRBD83SyncBroken(self): |
392 | 873878b9 | Thomas Thrainer | stats = self.drbd_info83_sync_krnl.GetMinorStatus(3) |
393 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_resync)
|
394 | 873878b9 | Thomas Thrainer | self.assertAlmostEqual(stats.sync_percent, 2.4) |
395 | 873878b9 | Thomas Thrainer | |
396 | 873878b9 | Thomas Thrainer | def testDRBD84Sync(self): |
397 | 873878b9 | Thomas Thrainer | stats = self.drbd_info84_sync.GetMinorStatus(5) |
398 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_resync)
|
399 | 873878b9 | Thomas Thrainer | self.assertAlmostEqual(stats.sync_percent, 68.5) |
400 | 873878b9 | Thomas Thrainer | |
401 | 873878b9 | Thomas Thrainer | def testDRBDEmptyVersion(self): |
402 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
403 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile, |
404 | 873878b9 | Thomas Thrainer | filename=self.proc80ev_data)
|
405 | 873878b9 | Thomas Thrainer | |
406 | 873878b9 | Thomas Thrainer | |
407 | 74db37c0 | Thomas Thrainer | class TestDRBD8Construction(testutils.GanetiTestCase): |
408 | 74db37c0 | Thomas Thrainer | def setUp(self): |
409 | 74db37c0 | Thomas Thrainer | """Read in txt data"""
|
410 | 74db37c0 | Thomas Thrainer | testutils.GanetiTestCase.setUp(self)
|
411 | 74db37c0 | Thomas Thrainer | self.proc80_info = \
|
412 | 74db37c0 | Thomas Thrainer | drbd_info.DRBD8Info.CreateFromFile( |
413 | 74db37c0 | Thomas Thrainer | filename=testutils.TestDataFilename("proc_drbd8.txt"))
|
414 | 74db37c0 | Thomas Thrainer | self.proc83_info = \
|
415 | 74db37c0 | Thomas Thrainer | drbd_info.DRBD8Info.CreateFromFile( |
416 | 74db37c0 | Thomas Thrainer | filename=testutils.TestDataFilename("proc_drbd83.txt"))
|
417 | 74db37c0 | Thomas Thrainer | self.proc84_info = \
|
418 | 74db37c0 | Thomas Thrainer | drbd_info.DRBD8Info.CreateFromFile( |
419 | 74db37c0 | Thomas Thrainer | filename=testutils.TestDataFilename("proc_drbd84.txt"))
|
420 | 74db37c0 | Thomas Thrainer | |
421 | 74db37c0 | Thomas Thrainer | self.test_unique_id = ("hosta.com", 123, "host2.com", 123, 0, "secret") |
422 | 3d835d1b | Thomas Thrainer | self.test_dyn_params = {
|
423 | 3d835d1b | Thomas Thrainer | constants.DDP_LOCAL_IP: "192.0.2.1",
|
424 | 3d835d1b | Thomas Thrainer | constants.DDP_LOCAL_MINOR: 0,
|
425 | 3d835d1b | Thomas Thrainer | constants.DDP_REMOTE_IP: "192.0.2.2",
|
426 | 3d835d1b | Thomas Thrainer | constants.DDP_REMOTE_MINOR: 0,
|
427 | 3d835d1b | Thomas Thrainer | } |
428 | 74db37c0 | Thomas Thrainer | |
429 | 47e0abee | Thomas Thrainer | @testutils.patch_object(drbd.DRBD8, "GetProcInfo") |
430 | 74db37c0 | Thomas Thrainer | def testConstructionWith80Data(self, mock_create_from_file): |
431 | 74db37c0 | Thomas Thrainer | mock_create_from_file.return_value = self.proc80_info
|
432 | 74db37c0 | Thomas Thrainer | |
433 | 3d835d1b | Thomas Thrainer | inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}, self.test_dyn_params) |
434 | 74db37c0 | Thomas Thrainer | self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
|
435 | 74db37c0 | Thomas Thrainer | self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD83CmdGenerator)) |
436 | 74db37c0 | Thomas Thrainer | |
437 | 47e0abee | Thomas Thrainer | @testutils.patch_object(drbd.DRBD8, "GetProcInfo") |
438 | 74db37c0 | Thomas Thrainer | def testConstructionWith83Data(self, mock_create_from_file): |
439 | 74db37c0 | Thomas Thrainer | mock_create_from_file.return_value = self.proc83_info
|
440 | 74db37c0 | Thomas Thrainer | |
441 | 3d835d1b | Thomas Thrainer | inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}, self.test_dyn_params) |
442 | 74db37c0 | Thomas Thrainer | self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
|
443 | 74db37c0 | Thomas Thrainer | self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD83CmdGenerator)) |
444 | 74db37c0 | Thomas Thrainer | |
445 | 47e0abee | Thomas Thrainer | @testutils.patch_object(drbd.DRBD8, "GetProcInfo") |
446 | 74db37c0 | Thomas Thrainer | def testConstructionWith84Data(self, mock_create_from_file): |
447 | 74db37c0 | Thomas Thrainer | mock_create_from_file.return_value = self.proc84_info
|
448 | 74db37c0 | Thomas Thrainer | |
449 | 3d835d1b | Thomas Thrainer | inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}, self.test_dyn_params) |
450 | 74db37c0 | Thomas Thrainer | self.assertEqual(inst._show_info_cls, drbd_info.DRBD84ShowInfo)
|
451 | daec28a7 | Thomas Thrainer | self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD84CmdGenerator)) |
452 | 74db37c0 | Thomas Thrainer | |
453 | 74db37c0 | Thomas Thrainer | |
454 | 873878b9 | Thomas Thrainer | if __name__ == "__main__": |
455 | 873878b9 | Thomas Thrainer | testutils.GanetiTestProgram() |