root / test / py / ganeti.storage.drbd_unittest.py @ 32389d91
History | View | Annotate | Download (16.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 | 873878b9 | Thomas Thrainer | def _has_disk(data, dname, mname): |
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 | 873878b9 | Thomas Thrainer | "meta_index" in data and |
96 | 873878b9 | Thomas Thrainer | data["meta_index"] == 0 |
97 | 873878b9 | Thomas Thrainer | ) |
98 | 873878b9 | Thomas Thrainer | return retval
|
99 | 873878b9 | Thomas Thrainer | |
100 | 873878b9 | Thomas Thrainer | @staticmethod
|
101 | 873878b9 | Thomas Thrainer | def _has_net(data, local, remote): |
102 | 873878b9 | Thomas Thrainer | """Check network connection parameters"""
|
103 | 873878b9 | Thomas Thrainer | retval = ( |
104 | 873878b9 | Thomas Thrainer | "local_addr" in data and |
105 | 873878b9 | Thomas Thrainer | data["local_addr"] == local and |
106 | 873878b9 | Thomas Thrainer | "remote_addr" in data and |
107 | 873878b9 | Thomas Thrainer | data["remote_addr"] == remote
|
108 | 873878b9 | Thomas Thrainer | ) |
109 | 873878b9 | Thomas Thrainer | return retval
|
110 | 873878b9 | Thomas Thrainer | |
111 | 873878b9 | Thomas Thrainer | def testParser83Creation(self): |
112 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser creation"""
|
113 | 873878b9 | Thomas Thrainer | drbd_info.DRBD83ShowInfo._GetShowParser() |
114 | 873878b9 | Thomas Thrainer | |
115 | 873878b9 | Thomas Thrainer | def testParser84Creation(self): |
116 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser creation"""
|
117 | 873878b9 | Thomas Thrainer | drbd_info.DRBD84ShowInfo._GetShowParser() |
118 | 873878b9 | Thomas Thrainer | |
119 | 873878b9 | Thomas Thrainer | def testParser80(self): |
120 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk and network version 8.0"""
|
121 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.0.txt")
|
122 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
123 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
124 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
125 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
126 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
127 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
128 | 873878b9 | Thomas Thrainer | "Wrong network info (8.0.x)")
|
129 | 873878b9 | Thomas Thrainer | |
130 | 873878b9 | Thomas Thrainer | def testParser83(self): |
131 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk and network version 8.3"""
|
132 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.3.txt")
|
133 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
134 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
135 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
136 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
137 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
138 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
139 | 873878b9 | Thomas Thrainer | "Wrong network info (8.3.x)")
|
140 | 873878b9 | Thomas Thrainer | |
141 | 873878b9 | Thomas Thrainer | def testParser84(self): |
142 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk and network version 8.4"""
|
143 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-8.4.txt")
|
144 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD84ShowInfo.GetDevInfo(data) |
145 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
146 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
147 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
148 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
149 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11000)), |
150 | 873878b9 | Thomas Thrainer | "Wrong network info (8.4.x)")
|
151 | 873878b9 | Thomas Thrainer | |
152 | 873878b9 | Thomas Thrainer | def testParserNetIP4(self): |
153 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for IPv4 network"""
|
154 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-net-ip4.txt")
|
155 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
156 | 873878b9 | Thomas Thrainer | self.failUnless(("local_dev" not in result and |
157 | 873878b9 | Thomas Thrainer | "meta_dev" not in result and |
158 | 873878b9 | Thomas Thrainer | "meta_index" not in result), |
159 | 873878b9 | Thomas Thrainer | "Should not find local disk info")
|
160 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("192.0.2.1", 11002), |
161 | 873878b9 | Thomas Thrainer | ("192.0.2.2", 11002)), |
162 | 873878b9 | Thomas Thrainer | "Wrong network info (IPv4)")
|
163 | 873878b9 | Thomas Thrainer | |
164 | 873878b9 | Thomas Thrainer | def testParserNetIP6(self): |
165 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for IPv6 network"""
|
166 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-net-ip6.txt")
|
167 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
168 | 873878b9 | Thomas Thrainer | self.failUnless(("local_dev" not in result and |
169 | 873878b9 | Thomas Thrainer | "meta_dev" not in result and |
170 | 873878b9 | Thomas Thrainer | "meta_index" not in result), |
171 | 873878b9 | Thomas Thrainer | "Should not find local disk info")
|
172 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_net(result, ("2001:db8:65::1", 11048), |
173 | 873878b9 | Thomas Thrainer | ("2001:db8:66::1", 11048)), |
174 | 873878b9 | Thomas Thrainer | "Wrong network info (IPv6)")
|
175 | 873878b9 | Thomas Thrainer | |
176 | 873878b9 | Thomas Thrainer | def testParserDisk(self): |
177 | 873878b9 | Thomas Thrainer | """Test drbdsetup show parser for disk"""
|
178 | 873878b9 | Thomas Thrainer | data = testutils.ReadTestData("bdev-drbd-disk.txt")
|
179 | 873878b9 | Thomas Thrainer | result = drbd_info.DRBD83ShowInfo.GetDevInfo(data) |
180 | 873878b9 | Thomas Thrainer | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
181 | 873878b9 | Thomas Thrainer | "/dev/xenvg/test.meta"),
|
182 | 873878b9 | Thomas Thrainer | "Wrong local disk info")
|
183 | 873878b9 | Thomas Thrainer | self.failUnless(("local_addr" not in result and |
184 | 873878b9 | Thomas Thrainer | "remote_addr" not in result), |
185 | 873878b9 | Thomas Thrainer | "Should not find network info")
|
186 | 873878b9 | Thomas Thrainer | |
187 | 873878b9 | Thomas Thrainer | def testBarriersOptions(self): |
188 | 873878b9 | Thomas Thrainer | """Test class method that generates drbdsetup options for disk barriers"""
|
189 | 873878b9 | Thomas Thrainer | # Tests that should fail because of wrong version/options combinations
|
190 | 873878b9 | Thomas Thrainer | should_fail = [ |
191 | 873878b9 | Thomas Thrainer | (8, 0, 12, "bfd", True), |
192 | 873878b9 | Thomas Thrainer | (8, 0, 12, "fd", False), |
193 | 873878b9 | Thomas Thrainer | (8, 0, 12, "b", True), |
194 | 873878b9 | Thomas Thrainer | (8, 2, 7, "bfd", True), |
195 | 873878b9 | Thomas Thrainer | (8, 2, 7, "b", True) |
196 | 873878b9 | Thomas Thrainer | ] |
197 | 873878b9 | Thomas Thrainer | |
198 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel, opts, meta in should_fail: |
199 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
200 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
201 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, opts, meta) |
202 | 873878b9 | Thomas Thrainer | |
203 | 873878b9 | Thomas Thrainer | # get the valid options from the frozenset(frozenset()) in constants.
|
204 | 873878b9 | Thomas Thrainer | valid_options = [list(x)[0] for x in constants.DRBD_VALID_BARRIER_OPT] |
205 | 873878b9 | Thomas Thrainer | |
206 | 873878b9 | Thomas Thrainer | # Versions that do not support anything
|
207 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel in ((8, 0, 0), (8, 0, 11), (8, 2, 6)): |
208 | 873878b9 | Thomas Thrainer | for opts in valid_options: |
209 | 873878b9 | Thomas Thrainer | self.assertRaises(
|
210 | 873878b9 | Thomas Thrainer | errors.BlockDeviceError, |
211 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
212 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, opts, True)
|
213 | 873878b9 | Thomas Thrainer | |
214 | 873878b9 | Thomas Thrainer | # Versions with partial support (testing only options that are supported)
|
215 | 873878b9 | Thomas Thrainer | tests = [ |
216 | 873878b9 | Thomas Thrainer | (8, 0, 12, "n", False, []), |
217 | 873878b9 | Thomas Thrainer | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
218 | 873878b9 | Thomas Thrainer | (8, 2, 7, "n", False, []), |
219 | 873878b9 | Thomas Thrainer | (8, 2, 7, "fd", False, ["--no-disk-flushes", "--no-disk-drain"]), |
220 | 873878b9 | Thomas Thrainer | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
221 | 873878b9 | Thomas Thrainer | ] |
222 | 873878b9 | Thomas Thrainer | |
223 | 873878b9 | Thomas Thrainer | # Versions that support everything
|
224 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel in ((8, 3, 0), (8, 3, 12)): |
225 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "bfd", True, |
226 | 873878b9 | Thomas Thrainer | ["--no-disk-barrier", "--no-disk-drain", |
227 | 873878b9 | Thomas Thrainer | "--no-disk-flushes", "--no-md-flushes"])) |
228 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "n", False, [])) |
229 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "b", True, |
230 | 873878b9 | Thomas Thrainer | ["--no-disk-barrier", "--no-md-flushes"])) |
231 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "fd", False, |
232 | 873878b9 | Thomas Thrainer | ["--no-disk-flushes", "--no-disk-drain"])) |
233 | 873878b9 | Thomas Thrainer | tests.append((vmaj, vmin, vrel, "n", True, ["--no-md-flushes"])) |
234 | 873878b9 | Thomas Thrainer | |
235 | 873878b9 | Thomas Thrainer | # Test execution
|
236 | 873878b9 | Thomas Thrainer | for test in tests: |
237 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, disabled_barriers, disable_meta_flush, expected = test |
238 | 873878b9 | Thomas Thrainer | args = \ |
239 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs( |
240 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, |
241 | 873878b9 | Thomas Thrainer | disabled_barriers, |
242 | 873878b9 | Thomas Thrainer | disable_meta_flush) |
243 | 873878b9 | Thomas Thrainer | self.failUnless(set(args) == set(expected), |
244 | 873878b9 | Thomas Thrainer | "For test %s, got wrong results %s" % (test, args))
|
245 | 873878b9 | Thomas Thrainer | |
246 | 873878b9 | Thomas Thrainer | # Unsupported or invalid versions
|
247 | 873878b9 | Thomas Thrainer | for vmaj, vmin, vrel in ((0, 7, 25), (9, 0, 0), (7, 0, 0), (8, 4, 0)): |
248 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
249 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
250 | 873878b9 | Thomas Thrainer | vmaj, vmin, vrel, "n", True) |
251 | 873878b9 | Thomas Thrainer | |
252 | 873878b9 | Thomas Thrainer | # Invalid options
|
253 | 873878b9 | Thomas Thrainer | for option in ("", "c", "whatever", "nbdfc", "nf"): |
254 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
255 | 873878b9 | Thomas Thrainer | drbd_cmdgen.DRBD83CmdGenerator._ComputeDiskBarrierArgs, |
256 | 873878b9 | Thomas Thrainer | 8, 3, 11, option, True) |
257 | 873878b9 | Thomas Thrainer | |
258 | 873878b9 | Thomas Thrainer | |
259 | 873878b9 | Thomas Thrainer | class TestDRBD8Status(testutils.GanetiTestCase): |
260 | 239364d0 | Thomas Thrainer | """Testing case for DRBD8Dev /proc status"""
|
261 | 873878b9 | Thomas Thrainer | |
262 | 873878b9 | Thomas Thrainer | def setUp(self): |
263 | 873878b9 | Thomas Thrainer | """Read in txt data"""
|
264 | 873878b9 | Thomas Thrainer | testutils.GanetiTestCase.setUp(self)
|
265 | 873878b9 | Thomas Thrainer | proc_data = testutils.TestDataFilename("proc_drbd8.txt")
|
266 | 873878b9 | Thomas Thrainer | proc80e_data = testutils.TestDataFilename("proc_drbd80-emptyline.txt")
|
267 | 873878b9 | Thomas Thrainer | proc83_data = testutils.TestDataFilename("proc_drbd83.txt")
|
268 | 873878b9 | Thomas Thrainer | proc83_sync_data = testutils.TestDataFilename("proc_drbd83_sync.txt")
|
269 | 873878b9 | Thomas Thrainer | proc83_sync_krnl_data = \ |
270 | 873878b9 | Thomas Thrainer | testutils.TestDataFilename("proc_drbd83_sync_krnl2.6.39.txt")
|
271 | 873878b9 | Thomas Thrainer | proc84_data = testutils.TestDataFilename("proc_drbd84.txt")
|
272 | 873878b9 | Thomas Thrainer | proc84_sync_data = testutils.TestDataFilename("proc_drbd84_sync.txt")
|
273 | 873878b9 | Thomas Thrainer | |
274 | 873878b9 | Thomas Thrainer | self.proc80ev_data = \
|
275 | 873878b9 | Thomas Thrainer | testutils.TestDataFilename("proc_drbd80-emptyversion.txt")
|
276 | 873878b9 | Thomas Thrainer | |
277 | 873878b9 | Thomas Thrainer | self.drbd_info = drbd.DRBD8Info.CreateFromFile(filename=proc_data)
|
278 | 873878b9 | Thomas Thrainer | self.drbd_info80e = drbd.DRBD8Info.CreateFromFile(filename=proc80e_data)
|
279 | 873878b9 | Thomas Thrainer | self.drbd_info83 = drbd.DRBD8Info.CreateFromFile(filename=proc83_data)
|
280 | 873878b9 | Thomas Thrainer | self.drbd_info83_sync = \
|
281 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile(filename=proc83_sync_data) |
282 | 873878b9 | Thomas Thrainer | self.drbd_info83_sync_krnl = \
|
283 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile(filename=proc83_sync_krnl_data) |
284 | 873878b9 | Thomas Thrainer | self.drbd_info84 = drbd.DRBD8Info.CreateFromFile(filename=proc84_data)
|
285 | 873878b9 | Thomas Thrainer | self.drbd_info84_sync = \
|
286 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile(filename=proc84_sync_data) |
287 | 873878b9 | Thomas Thrainer | |
288 | 873878b9 | Thomas Thrainer | def testIOErrors(self): |
289 | 873878b9 | Thomas Thrainer | """Test handling of errors while reading the proc file."""
|
290 | 873878b9 | Thomas Thrainer | temp_file = self._CreateTempFile()
|
291 | 873878b9 | Thomas Thrainer | os.unlink(temp_file) |
292 | 873878b9 | Thomas Thrainer | self.failUnlessRaises(errors.BlockDeviceError,
|
293 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile, filename=temp_file) |
294 | 873878b9 | Thomas Thrainer | |
295 | 873878b9 | Thomas Thrainer | def testHelper(self): |
296 | 873878b9 | Thomas Thrainer | """Test reading usermode_helper in /sys."""
|
297 | 873878b9 | Thomas Thrainer | sys_drbd_helper = testutils.TestDataFilename("sys_drbd_usermode_helper.txt")
|
298 | 47e0abee | Thomas Thrainer | drbd_helper = drbd.DRBD8.GetUsermodeHelper(filename=sys_drbd_helper) |
299 | 873878b9 | Thomas Thrainer | self.failUnlessEqual(drbd_helper, "/bin/true") |
300 | 873878b9 | Thomas Thrainer | |
301 | 873878b9 | Thomas Thrainer | def testHelperIOErrors(self): |
302 | 873878b9 | Thomas Thrainer | """Test handling of errors while reading usermode_helper in /sys."""
|
303 | 873878b9 | Thomas Thrainer | temp_file = self._CreateTempFile()
|
304 | 873878b9 | Thomas Thrainer | os.unlink(temp_file) |
305 | 873878b9 | Thomas Thrainer | self.failUnlessRaises(errors.BlockDeviceError,
|
306 | 47e0abee | Thomas Thrainer | drbd.DRBD8.GetUsermodeHelper, filename=temp_file) |
307 | 873878b9 | Thomas Thrainer | |
308 | 873878b9 | Thomas Thrainer | def testMinorNotFound(self): |
309 | 873878b9 | Thomas Thrainer | """Test not-found-minor in /proc"""
|
310 | 873878b9 | Thomas Thrainer | self.failUnless(not self.drbd_info.HasMinorStatus(9)) |
311 | 873878b9 | Thomas Thrainer | self.failUnless(not self.drbd_info83.HasMinorStatus(9)) |
312 | 873878b9 | Thomas Thrainer | self.failUnless(not self.drbd_info80e.HasMinorStatus(3)) |
313 | 873878b9 | Thomas Thrainer | |
314 | 873878b9 | Thomas Thrainer | def testLineNotMatch(self): |
315 | 873878b9 | Thomas Thrainer | """Test wrong line passed to drbd_info.DRBD8Status"""
|
316 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError, drbd_info.DRBD8Status, "foo") |
317 | 873878b9 | Thomas Thrainer | |
318 | 873878b9 | Thomas Thrainer | def testMinor0(self): |
319 | 873878b9 | Thomas Thrainer | """Test connected, primary device"""
|
320 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
321 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(0)
|
322 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
323 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_connected and stats.is_primary and |
324 | 873878b9 | Thomas Thrainer | stats.peer_secondary and stats.is_disk_uptodate)
|
325 | 873878b9 | Thomas Thrainer | |
326 | 873878b9 | Thomas Thrainer | def testMinor1(self): |
327 | 873878b9 | Thomas Thrainer | """Test connected, secondary device"""
|
328 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
329 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(1)
|
330 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
331 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_connected and stats.is_secondary and |
332 | 873878b9 | Thomas Thrainer | stats.peer_primary and stats.is_disk_uptodate)
|
333 | 873878b9 | Thomas Thrainer | |
334 | 873878b9 | Thomas Thrainer | def testMinor2(self): |
335 | 873878b9 | Thomas Thrainer | """Test unconfigured device"""
|
336 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, |
337 | 873878b9 | Thomas Thrainer | self.drbd_info80e, self.drbd_info84]: |
338 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(2)
|
339 | 873878b9 | Thomas Thrainer | self.failIf(stats.is_in_use)
|
340 | 873878b9 | Thomas Thrainer | |
341 | 873878b9 | Thomas Thrainer | def testMinor4(self): |
342 | 873878b9 | Thomas Thrainer | """Test WFconn device"""
|
343 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
344 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(4)
|
345 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
346 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_wfconn and stats.is_primary and |
347 | 873878b9 | Thomas Thrainer | stats.rrole == "Unknown" and |
348 | 873878b9 | Thomas Thrainer | stats.is_disk_uptodate) |
349 | 873878b9 | Thomas Thrainer | |
350 | 873878b9 | Thomas Thrainer | def testMinor6(self): |
351 | 873878b9 | Thomas Thrainer | """Test diskless device"""
|
352 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
353 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(6)
|
354 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
355 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_connected and stats.is_secondary and |
356 | 873878b9 | Thomas Thrainer | stats.peer_primary and stats.is_diskless)
|
357 | 873878b9 | Thomas Thrainer | |
358 | 873878b9 | Thomas Thrainer | def testMinor8(self): |
359 | 873878b9 | Thomas Thrainer | """Test standalone device"""
|
360 | 873878b9 | Thomas Thrainer | for info in [self.drbd_info, self.drbd_info83, self.drbd_info84]: |
361 | 873878b9 | Thomas Thrainer | stats = info.GetMinorStatus(8)
|
362 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_use)
|
363 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_standalone and |
364 | 873878b9 | Thomas Thrainer | stats.rrole == "Unknown" and |
365 | 873878b9 | Thomas Thrainer | stats.is_disk_uptodate) |
366 | 873878b9 | Thomas Thrainer | |
367 | 873878b9 | Thomas Thrainer | def testDRBD83SyncFine(self): |
368 | 873878b9 | Thomas Thrainer | stats = self.drbd_info83_sync.GetMinorStatus(3) |
369 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_resync)
|
370 | 873878b9 | Thomas Thrainer | self.assertAlmostEqual(stats.sync_percent, 34.9) |
371 | 873878b9 | Thomas Thrainer | |
372 | 873878b9 | Thomas Thrainer | def testDRBD83SyncBroken(self): |
373 | 873878b9 | Thomas Thrainer | stats = self.drbd_info83_sync_krnl.GetMinorStatus(3) |
374 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_resync)
|
375 | 873878b9 | Thomas Thrainer | self.assertAlmostEqual(stats.sync_percent, 2.4) |
376 | 873878b9 | Thomas Thrainer | |
377 | 873878b9 | Thomas Thrainer | def testDRBD84Sync(self): |
378 | 873878b9 | Thomas Thrainer | stats = self.drbd_info84_sync.GetMinorStatus(5) |
379 | 873878b9 | Thomas Thrainer | self.failUnless(stats.is_in_resync)
|
380 | 873878b9 | Thomas Thrainer | self.assertAlmostEqual(stats.sync_percent, 68.5) |
381 | 873878b9 | Thomas Thrainer | |
382 | 873878b9 | Thomas Thrainer | def testDRBDEmptyVersion(self): |
383 | 873878b9 | Thomas Thrainer | self.assertRaises(errors.BlockDeviceError,
|
384 | 873878b9 | Thomas Thrainer | drbd.DRBD8Info.CreateFromFile, |
385 | 873878b9 | Thomas Thrainer | filename=self.proc80ev_data)
|
386 | 873878b9 | Thomas Thrainer | |
387 | 873878b9 | Thomas Thrainer | |
388 | 74db37c0 | Thomas Thrainer | class TestDRBD8Construction(testutils.GanetiTestCase): |
389 | 74db37c0 | Thomas Thrainer | def setUp(self): |
390 | 74db37c0 | Thomas Thrainer | """Read in txt data"""
|
391 | 74db37c0 | Thomas Thrainer | testutils.GanetiTestCase.setUp(self)
|
392 | 74db37c0 | Thomas Thrainer | self.proc80_info = \
|
393 | 74db37c0 | Thomas Thrainer | drbd_info.DRBD8Info.CreateFromFile( |
394 | 74db37c0 | Thomas Thrainer | filename=testutils.TestDataFilename("proc_drbd8.txt"))
|
395 | 74db37c0 | Thomas Thrainer | self.proc83_info = \
|
396 | 74db37c0 | Thomas Thrainer | drbd_info.DRBD8Info.CreateFromFile( |
397 | 74db37c0 | Thomas Thrainer | filename=testutils.TestDataFilename("proc_drbd83.txt"))
|
398 | 74db37c0 | Thomas Thrainer | self.proc84_info = \
|
399 | 74db37c0 | Thomas Thrainer | drbd_info.DRBD8Info.CreateFromFile( |
400 | 74db37c0 | Thomas Thrainer | filename=testutils.TestDataFilename("proc_drbd84.txt"))
|
401 | 74db37c0 | Thomas Thrainer | |
402 | 74db37c0 | Thomas Thrainer | self.test_unique_id = ("hosta.com", 123, "host2.com", 123, 0, "secret") |
403 | 74db37c0 | Thomas Thrainer | |
404 | 47e0abee | Thomas Thrainer | @testutils.patch_object(drbd.DRBD8, "GetProcInfo") |
405 | 74db37c0 | Thomas Thrainer | def testConstructionWith80Data(self, mock_create_from_file): |
406 | 74db37c0 | Thomas Thrainer | mock_create_from_file.return_value = self.proc80_info
|
407 | 74db37c0 | Thomas Thrainer | |
408 | 239364d0 | Thomas Thrainer | inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}) |
409 | 74db37c0 | Thomas Thrainer | self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
|
410 | 74db37c0 | Thomas Thrainer | self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD83CmdGenerator)) |
411 | 74db37c0 | Thomas Thrainer | |
412 | 47e0abee | Thomas Thrainer | @testutils.patch_object(drbd.DRBD8, "GetProcInfo") |
413 | 74db37c0 | Thomas Thrainer | def testConstructionWith83Data(self, mock_create_from_file): |
414 | 74db37c0 | Thomas Thrainer | mock_create_from_file.return_value = self.proc83_info
|
415 | 74db37c0 | Thomas Thrainer | |
416 | 239364d0 | Thomas Thrainer | inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}) |
417 | 74db37c0 | Thomas Thrainer | self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
|
418 | 74db37c0 | Thomas Thrainer | self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD83CmdGenerator)) |
419 | 74db37c0 | Thomas Thrainer | |
420 | 47e0abee | Thomas Thrainer | @testutils.patch_object(drbd.DRBD8, "GetProcInfo") |
421 | 74db37c0 | Thomas Thrainer | def testConstructionWith84Data(self, mock_create_from_file): |
422 | 74db37c0 | Thomas Thrainer | mock_create_from_file.return_value = self.proc84_info
|
423 | 74db37c0 | Thomas Thrainer | |
424 | 239364d0 | Thomas Thrainer | inst = drbd.DRBD8Dev(self.test_unique_id, [], 123, {}) |
425 | 74db37c0 | Thomas Thrainer | self.assertEqual(inst._show_info_cls, drbd_info.DRBD84ShowInfo)
|
426 | daec28a7 | Thomas Thrainer | self.assertTrue(isinstance(inst._cmd_gen, drbd_cmdgen.DRBD84CmdGenerator)) |
427 | 74db37c0 | Thomas Thrainer | |
428 | 74db37c0 | Thomas Thrainer | |
429 | 873878b9 | Thomas Thrainer | if __name__ == "__main__": |
430 | 873878b9 | Thomas Thrainer | testutils.GanetiTestProgram() |