root / test / ganeti.bdev_unittest.py @ 415feb2e
History | View | Annotate | Download (14 kB)
1 | 3840729d | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | 3840729d | Iustin Pop | #
|
3 | 3840729d | Iustin Pop | |
4 | fcee765d | Manuel Franceschini | # Copyright (C) 2006, 2007, 2010 Google Inc.
|
5 | 3840729d | Iustin Pop | #
|
6 | 3840729d | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | 3840729d | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | 3840729d | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | 3840729d | Iustin Pop | # (at your option) any later version.
|
10 | 3840729d | Iustin Pop | #
|
11 | 3840729d | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | 3840729d | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 3840729d | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 3840729d | Iustin Pop | # General Public License for more details.
|
15 | 3840729d | Iustin Pop | #
|
16 | 3840729d | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | 3840729d | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | 3840729d | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 3840729d | Iustin Pop | # 02110-1301, USA.
|
20 | 3840729d | Iustin Pop | |
21 | 3840729d | Iustin Pop | |
22 | 3840729d | Iustin Pop | """Script for unittesting the bdev module"""
|
23 | 3840729d | Iustin Pop | |
24 | 3840729d | Iustin Pop | |
25 | 6634816b | Iustin Pop | import os |
26 | 3840729d | Iustin Pop | import unittest |
27 | 3840729d | Iustin Pop | |
28 | 3840729d | Iustin Pop | from ganeti import bdev |
29 | 6b90c22e | Iustin Pop | from ganeti import errors |
30 | 8a69b3a8 | Andrea Spadaccini | from ganeti import constants |
31 | 3840729d | Iustin Pop | |
32 | 25231ec5 | Michael Hanselmann | import testutils |
33 | 25231ec5 | Michael Hanselmann | |
34 | 3840729d | Iustin Pop | |
35 | fcee765d | Manuel Franceschini | class TestBaseDRBD(testutils.GanetiTestCase): |
36 | fcee765d | Manuel Franceschini | def testGetVersion(self): |
37 | fcee765d | Manuel Franceschini | data = [ |
38 | fcee765d | Manuel Franceschini | ["version: 8.0.12 (api:76/proto:86-91)"],
|
39 | fcee765d | Manuel Franceschini | ["version: 8.2.7 (api:88/proto:0-100)"],
|
40 | fcee765d | Manuel Franceschini | ["version: 8.3.7.49 (api:188/proto:13-191)"],
|
41 | fcee765d | Manuel Franceschini | ] |
42 | fcee765d | Manuel Franceschini | result = [ |
43 | fcee765d | Manuel Franceschini | { |
44 | fcee765d | Manuel Franceschini | "k_major": 8, |
45 | fcee765d | Manuel Franceschini | "k_minor": 0, |
46 | fcee765d | Manuel Franceschini | "k_point": 12, |
47 | fcee765d | Manuel Franceschini | "api": 76, |
48 | fcee765d | Manuel Franceschini | "proto": 86, |
49 | fcee765d | Manuel Franceschini | "proto2": "91", |
50 | fcee765d | Manuel Franceschini | }, |
51 | fcee765d | Manuel Franceschini | { |
52 | fcee765d | Manuel Franceschini | "k_major": 8, |
53 | fcee765d | Manuel Franceschini | "k_minor": 2, |
54 | fcee765d | Manuel Franceschini | "k_point": 7, |
55 | fcee765d | Manuel Franceschini | "api": 88, |
56 | fcee765d | Manuel Franceschini | "proto": 0, |
57 | fcee765d | Manuel Franceschini | "proto2": "100", |
58 | fcee765d | Manuel Franceschini | }, |
59 | fcee765d | Manuel Franceschini | { |
60 | fcee765d | Manuel Franceschini | "k_major": 8, |
61 | fcee765d | Manuel Franceschini | "k_minor": 3, |
62 | fcee765d | Manuel Franceschini | "k_point": 7, |
63 | fcee765d | Manuel Franceschini | "api": 188, |
64 | fcee765d | Manuel Franceschini | "proto": 13, |
65 | fcee765d | Manuel Franceschini | "proto2": "191", |
66 | fcee765d | Manuel Franceschini | } |
67 | fcee765d | Manuel Franceschini | ] |
68 | fcee765d | Manuel Franceschini | for d,r in zip(data, result): |
69 | fcee765d | Manuel Franceschini | self.assertEqual(bdev.BaseDRBD._GetVersion(d), r)
|
70 | fcee765d | Manuel Franceschini | |
71 | fcee765d | Manuel Franceschini | |
72 | 149a5439 | Iustin Pop | class TestDRBD8Runner(testutils.GanetiTestCase): |
73 | 3840729d | Iustin Pop | """Testing case for DRBD8"""
|
74 | 3840729d | Iustin Pop | |
75 | 3840729d | Iustin Pop | @staticmethod
|
76 | 3840729d | Iustin Pop | def _has_disk(data, dname, mname): |
77 | 3840729d | Iustin Pop | """Check local disk corectness"""
|
78 | 3840729d | Iustin Pop | retval = ( |
79 | 3840729d | Iustin Pop | "local_dev" in data and |
80 | 3840729d | Iustin Pop | data["local_dev"] == dname and |
81 | 3840729d | Iustin Pop | "meta_dev" in data and |
82 | 3840729d | Iustin Pop | data["meta_dev"] == mname and |
83 | 3840729d | Iustin Pop | "meta_index" in data and |
84 | 3840729d | Iustin Pop | data["meta_index"] == 0 |
85 | 3840729d | Iustin Pop | ) |
86 | 3840729d | Iustin Pop | return retval
|
87 | 3840729d | Iustin Pop | |
88 | 3840729d | Iustin Pop | @staticmethod
|
89 | 3840729d | Iustin Pop | def _has_net(data, local, remote): |
90 | 3840729d | Iustin Pop | """Check network connection parameters"""
|
91 | 3840729d | Iustin Pop | retval = ( |
92 | 3840729d | Iustin Pop | "local_addr" in data and |
93 | 3840729d | Iustin Pop | data["local_addr"] == local and |
94 | 3840729d | Iustin Pop | "remote_addr" in data and |
95 | 3840729d | Iustin Pop | data["remote_addr"] == remote
|
96 | 3840729d | Iustin Pop | ) |
97 | 3840729d | Iustin Pop | return retval
|
98 | 3840729d | Iustin Pop | |
99 | 3840729d | Iustin Pop | def testParserCreation(self): |
100 | 3840729d | Iustin Pop | """Test drbdsetup show parser creation"""
|
101 | 3840729d | Iustin Pop | bdev.DRBD8._GetShowParser() |
102 | 3840729d | Iustin Pop | |
103 | 5a672c30 | Manuel Franceschini | def testParser80(self): |
104 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for disk and network version 8.0"""
|
105 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-8.0.txt") |
106 | 3840729d | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
107 | 3840729d | Iustin Pop | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
108 | 3840729d | Iustin Pop | "/dev/xenvg/test.meta"),
|
109 | 3840729d | Iustin Pop | "Wrong local disk info")
|
110 | 926feaf1 | Manuel Franceschini | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
111 | 926feaf1 | Manuel Franceschini | ("192.0.2.2", 11000)), |
112 | 01e2ce3a | Iustin Pop | "Wrong network info (8.0.x)")
|
113 | 01e2ce3a | Iustin Pop | |
114 | 5a672c30 | Manuel Franceschini | def testParser83(self): |
115 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for disk and network version 8.3"""
|
116 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-8.3.txt") |
117 | 01e2ce3a | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
118 | 01e2ce3a | Iustin Pop | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
119 | 01e2ce3a | Iustin Pop | "/dev/xenvg/test.meta"),
|
120 | 01e2ce3a | Iustin Pop | "Wrong local disk info")
|
121 | 926feaf1 | Manuel Franceschini | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
122 | 926feaf1 | Manuel Franceschini | ("192.0.2.2", 11000)), |
123 | 5a672c30 | Manuel Franceschini | "Wrong network info (8.0.x)")
|
124 | 3840729d | Iustin Pop | |
125 | 5a672c30 | Manuel Franceschini | def testParserNetIP4(self): |
126 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for IPv4 network"""
|
127 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-net-ip4.txt") |
128 | 3840729d | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
129 | 3840729d | Iustin Pop | self.failUnless(("local_dev" not in result and |
130 | 3840729d | Iustin Pop | "meta_dev" not in result and |
131 | 3840729d | Iustin Pop | "meta_index" not in result), |
132 | 3840729d | Iustin Pop | "Should not find local disk info")
|
133 | 926feaf1 | Manuel Franceschini | self.failUnless(self._has_net(result, ("192.0.2.1", 11002), |
134 | 926feaf1 | Manuel Franceschini | ("192.0.2.2", 11002)), |
135 | 5a672c30 | Manuel Franceschini | "Wrong network info (IPv4)")
|
136 | 5a672c30 | Manuel Franceschini | |
137 | 5a672c30 | Manuel Franceschini | def testParserNetIP6(self): |
138 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for IPv6 network"""
|
139 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-net-ip6.txt") |
140 | 5a672c30 | Manuel Franceschini | result = bdev.DRBD8._GetDevInfo(data) |
141 | 5a672c30 | Manuel Franceschini | self.failUnless(("local_dev" not in result and |
142 | 5a672c30 | Manuel Franceschini | "meta_dev" not in result and |
143 | 5a672c30 | Manuel Franceschini | "meta_index" not in result), |
144 | 5a672c30 | Manuel Franceschini | "Should not find local disk info")
|
145 | 5a672c30 | Manuel Franceschini | self.failUnless(self._has_net(result, ("2001:db8:65::1", 11048), |
146 | 5a672c30 | Manuel Franceschini | ("2001:db8:66::1", 11048)), |
147 | 5a672c30 | Manuel Franceschini | "Wrong network info (IPv6)")
|
148 | 3840729d | Iustin Pop | |
149 | 3840729d | Iustin Pop | def testParserDisk(self): |
150 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for disk"""
|
151 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-disk.txt") |
152 | 3840729d | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
153 | 3840729d | Iustin Pop | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
154 | 3840729d | Iustin Pop | "/dev/xenvg/test.meta"),
|
155 | 3840729d | Iustin Pop | "Wrong local disk info")
|
156 | 3840729d | Iustin Pop | self.failUnless(("local_addr" not in result and |
157 | 3840729d | Iustin Pop | "remote_addr" not in result), |
158 | 3840729d | Iustin Pop | "Should not find network info")
|
159 | 3840729d | Iustin Pop | |
160 | 8a69b3a8 | Andrea Spadaccini | def testBarriersOptions(self): |
161 | 8a69b3a8 | Andrea Spadaccini | """Test class method that generates drbdsetup options for disk barriers"""
|
162 | 8a69b3a8 | Andrea Spadaccini | # Tests that should fail because of wrong version/options combinations
|
163 | 8a69b3a8 | Andrea Spadaccini | should_fail = [ |
164 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "bfd", True), |
165 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "fd", False), |
166 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "b", True), |
167 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "bfd", True), |
168 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "b", True) |
169 | 8a69b3a8 | Andrea Spadaccini | ] |
170 | 8a69b3a8 | Andrea Spadaccini | |
171 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel, opts, meta in should_fail: |
172 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
173 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
174 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, opts, meta) |
175 | 8a69b3a8 | Andrea Spadaccini | |
176 | 8a69b3a8 | Andrea Spadaccini | # get the valid options from the frozenset(frozenset()) in constants.
|
177 | 8a69b3a8 | Andrea Spadaccini | valid_options = [list(x)[0] for x in constants.DRBD_VALID_BARRIER_OPT] |
178 | 8a69b3a8 | Andrea Spadaccini | |
179 | 8a69b3a8 | Andrea Spadaccini | # Versions that do not support anything
|
180 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel in ((8, 0, 0), (8, 0, 11), (8, 2, 6)): |
181 | 8a69b3a8 | Andrea Spadaccini | for opts in valid_options: |
182 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
183 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
184 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, opts, True)
|
185 | 8a69b3a8 | Andrea Spadaccini | |
186 | 8a69b3a8 | Andrea Spadaccini | # Versions with partial support (testing only options that are supported)
|
187 | 8a69b3a8 | Andrea Spadaccini | tests = [ |
188 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "n", False, []), |
189 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
190 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "n", False, []), |
191 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "fd", False, ["--no-disk-flushes", "--no-disk-drain"]), |
192 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
193 | 8a69b3a8 | Andrea Spadaccini | ] |
194 | 8a69b3a8 | Andrea Spadaccini | |
195 | 8a69b3a8 | Andrea Spadaccini | # Versions that support everything
|
196 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel in ((8, 3, 0), (8, 3, 12)): |
197 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "bfd", True, |
198 | 8a69b3a8 | Andrea Spadaccini | ["--no-disk-barrier", "--no-disk-drain", |
199 | 8a69b3a8 | Andrea Spadaccini | "--no-disk-flushes", "--no-md-flushes"])) |
200 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "n", False, [])) |
201 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "b", True, |
202 | 8a69b3a8 | Andrea Spadaccini | ["--no-disk-barrier", "--no-md-flushes"])) |
203 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "fd", False, |
204 | 8a69b3a8 | Andrea Spadaccini | ["--no-disk-flushes", "--no-disk-drain"])) |
205 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "n", True, ["--no-md-flushes"])) |
206 | 8a69b3a8 | Andrea Spadaccini | |
207 | 8a69b3a8 | Andrea Spadaccini | # Test execution
|
208 | 8a69b3a8 | Andrea Spadaccini | for test in tests: |
209 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, disabled_barriers, disable_meta_flush, expected = test |
210 | 8a69b3a8 | Andrea Spadaccini | args = \ |
211 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs(vmaj, vmin, vrel, |
212 | 8a69b3a8 | Andrea Spadaccini | disabled_barriers, |
213 | 8a69b3a8 | Andrea Spadaccini | disable_meta_flush) |
214 | 8a69b3a8 | Andrea Spadaccini | self.failUnless(set(args) == set(expected), |
215 | 8a69b3a8 | Andrea Spadaccini | "For test %s, got wrong results %s" % (test, args))
|
216 | 8a69b3a8 | Andrea Spadaccini | |
217 | 8a69b3a8 | Andrea Spadaccini | # Unsupported or invalid versions
|
218 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel in ((0, 7, 25), (9, 0, 0), (7, 0, 0), (8, 4, 0)): |
219 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
220 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
221 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, "n", True) |
222 | 8a69b3a8 | Andrea Spadaccini | |
223 | 8a69b3a8 | Andrea Spadaccini | # Invalid options
|
224 | 8a69b3a8 | Andrea Spadaccini | for option in ("", "c", "whatever", "nbdfc", "nf"): |
225 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
226 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
227 | 8a69b3a8 | Andrea Spadaccini | 8, 3, 11, option, True) |
228 | 8a69b3a8 | Andrea Spadaccini | |
229 | 6b90c22e | Iustin Pop | |
230 | 149a5439 | Iustin Pop | class TestDRBD8Status(testutils.GanetiTestCase): |
231 | 6b90c22e | Iustin Pop | """Testing case for DRBD8 /proc status"""
|
232 | 6b90c22e | Iustin Pop | |
233 | 6b90c22e | Iustin Pop | def setUp(self): |
234 | 6b90c22e | Iustin Pop | """Read in txt data"""
|
235 | 51596eb2 | Iustin Pop | testutils.GanetiTestCase.setUp(self)
|
236 | 149a5439 | Iustin Pop | proc_data = self._TestDataFilename("proc_drbd8.txt") |
237 | 67d101d4 | Iustin Pop | proc80e_data = self._TestDataFilename("proc_drbd80-emptyline.txt") |
238 | 01e2ce3a | Iustin Pop | proc83_data = self._TestDataFilename("proc_drbd83.txt") |
239 | 7a380ddf | René Nussbaumer | proc83_sync_data = self._TestDataFilename("proc_drbd83_sync.txt") |
240 | 7a380ddf | René Nussbaumer | proc83_sync_krnl_data = \ |
241 | 7a380ddf | René Nussbaumer | self._TestDataFilename("proc_drbd83_sync_krnl2.6.39.txt") |
242 | ae9da390 | Iustin Pop | self.proc_data = bdev.DRBD8._GetProcData(filename=proc_data)
|
243 | 67d101d4 | Iustin Pop | self.proc80e_data = bdev.DRBD8._GetProcData(filename=proc80e_data)
|
244 | 01e2ce3a | Iustin Pop | self.proc83_data = bdev.DRBD8._GetProcData(filename=proc83_data)
|
245 | 7a380ddf | René Nussbaumer | self.proc83_sync_data = bdev.DRBD8._GetProcData(filename=proc83_sync_data)
|
246 | 7a380ddf | René Nussbaumer | self.proc83_sync_krnl_data = \
|
247 | 7a380ddf | René Nussbaumer | bdev.DRBD8._GetProcData(filename=proc83_sync_krnl_data) |
248 | 6b90c22e | Iustin Pop | self.mass_data = bdev.DRBD8._MassageProcData(self.proc_data) |
249 | 67d101d4 | Iustin Pop | self.mass80e_data = bdev.DRBD8._MassageProcData(self.proc80e_data) |
250 | 01e2ce3a | Iustin Pop | self.mass83_data = bdev.DRBD8._MassageProcData(self.proc83_data) |
251 | 7a380ddf | René Nussbaumer | self.mass83_sync_data = bdev.DRBD8._MassageProcData(self.proc83_sync_data) |
252 | 7a380ddf | René Nussbaumer | self.mass83_sync_krnl_data = \
|
253 | 7a380ddf | René Nussbaumer | bdev.DRBD8._MassageProcData(self.proc83_sync_krnl_data)
|
254 | 6b90c22e | Iustin Pop | |
255 | f6eaed12 | Iustin Pop | def testIOErrors(self): |
256 | f6eaed12 | Iustin Pop | """Test handling of errors while reading the proc file."""
|
257 | f6eaed12 | Iustin Pop | temp_file = self._CreateTempFile()
|
258 | f6eaed12 | Iustin Pop | os.unlink(temp_file) |
259 | f6eaed12 | Iustin Pop | self.failUnlessRaises(errors.BlockDeviceError,
|
260 | f6eaed12 | Iustin Pop | bdev.DRBD8._GetProcData, filename=temp_file) |
261 | f6eaed12 | Iustin Pop | |
262 | 549071a0 | Luca Bigliardi | def testHelper(self): |
263 | 549071a0 | Luca Bigliardi | """Test reading usermode_helper in /sys."""
|
264 | 549071a0 | Luca Bigliardi | sys_drbd_helper = self._TestDataFilename("sys_drbd_usermode_helper.txt") |
265 | 549071a0 | Luca Bigliardi | drbd_helper = bdev.DRBD8.GetUsermodeHelper(filename=sys_drbd_helper) |
266 | 549071a0 | Luca Bigliardi | self.failUnlessEqual(drbd_helper, "/bin/true") |
267 | 549071a0 | Luca Bigliardi | |
268 | 549071a0 | Luca Bigliardi | def testHelperIOErrors(self): |
269 | 549071a0 | Luca Bigliardi | """Test handling of errors while reading usermode_helper in /sys."""
|
270 | 549071a0 | Luca Bigliardi | temp_file = self._CreateTempFile()
|
271 | 549071a0 | Luca Bigliardi | os.unlink(temp_file) |
272 | 549071a0 | Luca Bigliardi | self.failUnlessRaises(errors.BlockDeviceError,
|
273 | 549071a0 | Luca Bigliardi | bdev.DRBD8.GetUsermodeHelper, filename=temp_file) |
274 | 549071a0 | Luca Bigliardi | |
275 | 6b90c22e | Iustin Pop | def testMinorNotFound(self): |
276 | 6b90c22e | Iustin Pop | """Test not-found-minor in /proc"""
|
277 | 6b90c22e | Iustin Pop | self.failUnless(9 not in self.mass_data) |
278 | 01e2ce3a | Iustin Pop | self.failUnless(9 not in self.mass83_data) |
279 | 67d101d4 | Iustin Pop | self.failUnless(3 not in self.mass80e_data) |
280 | 6b90c22e | Iustin Pop | |
281 | 6b90c22e | Iustin Pop | def testLineNotMatch(self): |
282 | 6b90c22e | Iustin Pop | """Test wrong line passed to DRBD8Status"""
|
283 | 6b90c22e | Iustin Pop | self.assertRaises(errors.BlockDeviceError, bdev.DRBD8Status, "foo") |
284 | 6b90c22e | Iustin Pop | |
285 | 6b90c22e | Iustin Pop | def testMinor0(self): |
286 | 6b90c22e | Iustin Pop | """Test connected, primary device"""
|
287 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
288 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[0])
|
289 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
290 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_connected and stats.is_primary and |
291 | 01e2ce3a | Iustin Pop | stats.peer_secondary and stats.is_disk_uptodate)
|
292 | 6b90c22e | Iustin Pop | |
293 | 6b90c22e | Iustin Pop | def testMinor1(self): |
294 | 6b90c22e | Iustin Pop | """Test connected, secondary device"""
|
295 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
296 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[1])
|
297 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
298 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_connected and stats.is_secondary and |
299 | 01e2ce3a | Iustin Pop | stats.peer_primary and stats.is_disk_uptodate)
|
300 | 6b90c22e | Iustin Pop | |
301 | 767d52d3 | Iustin Pop | def testMinor2(self): |
302 | 767d52d3 | Iustin Pop | """Test unconfigured device"""
|
303 | 67d101d4 | Iustin Pop | for data in [self.mass_data, self.mass83_data, self.mass80e_data]: |
304 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[2])
|
305 | 01e2ce3a | Iustin Pop | self.failIf(stats.is_in_use)
|
306 | 767d52d3 | Iustin Pop | |
307 | 6b90c22e | Iustin Pop | def testMinor4(self): |
308 | 6b90c22e | Iustin Pop | """Test WFconn device"""
|
309 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
310 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[4])
|
311 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
312 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_wfconn and stats.is_primary and |
313 | 01e2ce3a | Iustin Pop | stats.rrole == 'Unknown' and |
314 | 01e2ce3a | Iustin Pop | stats.is_disk_uptodate) |
315 | 6b90c22e | Iustin Pop | |
316 | 6b90c22e | Iustin Pop | def testMinor6(self): |
317 | 6b90c22e | Iustin Pop | """Test diskless device"""
|
318 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
319 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[6])
|
320 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
321 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_connected and stats.is_secondary and |
322 | 01e2ce3a | Iustin Pop | stats.peer_primary and stats.is_diskless)
|
323 | 6b90c22e | Iustin Pop | |
324 | 6b90c22e | Iustin Pop | def testMinor8(self): |
325 | 6b90c22e | Iustin Pop | """Test standalone device"""
|
326 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
327 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[8])
|
328 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
329 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_standalone and |
330 | 01e2ce3a | Iustin Pop | stats.rrole == 'Unknown' and |
331 | 01e2ce3a | Iustin Pop | stats.is_disk_uptodate) |
332 | 6b90c22e | Iustin Pop | |
333 | 7a380ddf | René Nussbaumer | def testDRBD83SyncFine(self): |
334 | 7a380ddf | René Nussbaumer | stats = bdev.DRBD8Status(self.mass83_sync_data[3]) |
335 | 7a380ddf | René Nussbaumer | self.failUnless(stats.is_in_resync)
|
336 | 7a380ddf | René Nussbaumer | self.failUnless(stats.sync_percent is not None) |
337 | 7a380ddf | René Nussbaumer | |
338 | 7a380ddf | René Nussbaumer | def testDRBD83SyncBroken(self): |
339 | 7a380ddf | René Nussbaumer | stats = bdev.DRBD8Status(self.mass83_sync_krnl_data[3]) |
340 | 7a380ddf | René Nussbaumer | self.failUnless(stats.is_in_resync)
|
341 | 7a380ddf | René Nussbaumer | self.failUnless(stats.sync_percent is not None) |
342 | 7a380ddf | René Nussbaumer | |
343 | 7181fba0 | Constantinos Venetsanopoulos | |
344 | 7181fba0 | Constantinos Venetsanopoulos | class TestRADOSBlockDevice(testutils.GanetiTestCase): |
345 | 7181fba0 | Constantinos Venetsanopoulos | def test_ParseRbdShowmappedOutput(self): |
346 | 7181fba0 | Constantinos Venetsanopoulos | volume_name = "abc9778-8e8ace5b.rbd.disk0"
|
347 | 7181fba0 | Constantinos Venetsanopoulos | output_ok = \ |
348 | 7181fba0 | Constantinos Venetsanopoulos | ("0\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
|
349 | 7181fba0 | Constantinos Venetsanopoulos | "1\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd16\n"
|
350 | 7181fba0 | Constantinos Venetsanopoulos | "line\twith\tfewer\tfields\n"
|
351 | 7181fba0 | Constantinos Venetsanopoulos | "")
|
352 | 7181fba0 | Constantinos Venetsanopoulos | output_empty = ""
|
353 | 7181fba0 | Constantinos Venetsanopoulos | output_no_matches = \ |
354 | 7181fba0 | Constantinos Venetsanopoulos | ("0\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
|
355 | 7181fba0 | Constantinos Venetsanopoulos | "1\trbd\tabcdef01-9817.rbd.disk0\t-\t/dev/rbd10\n"
|
356 | 7181fba0 | Constantinos Venetsanopoulos | "2\trbd\tcdef0123-9817.rbd.disk0\t-\t/dev/rbd12\n"
|
357 | 7181fba0 | Constantinos Venetsanopoulos | "something\twith\tfewer\tfields"
|
358 | 7181fba0 | Constantinos Venetsanopoulos | "")
|
359 | 7181fba0 | Constantinos Venetsanopoulos | output_extra_matches = \ |
360 | 7181fba0 | Constantinos Venetsanopoulos | ("0\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd11\n"
|
361 | 7181fba0 | Constantinos Venetsanopoulos | "1\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
|
362 | 7181fba0 | Constantinos Venetsanopoulos | "2\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd16\n"
|
363 | 7181fba0 | Constantinos Venetsanopoulos | "something\twith\tfewer\tfields"
|
364 | 7181fba0 | Constantinos Venetsanopoulos | "")
|
365 | 7181fba0 | Constantinos Venetsanopoulos | |
366 | 7181fba0 | Constantinos Venetsanopoulos | parse_function = bdev.RADOSBlockDevice._ParseRbdShowmappedOutput |
367 | 7181fba0 | Constantinos Venetsanopoulos | self.assertEqual(parse_function(output_ok, volume_name), "/dev/rbd16") |
368 | 7181fba0 | Constantinos Venetsanopoulos | self.assertRaises(errors.BlockDeviceError, parse_function,
|
369 | 7181fba0 | Constantinos Venetsanopoulos | output_empty, volume_name) |
370 | 7181fba0 | Constantinos Venetsanopoulos | self.assertEqual(parse_function(output_no_matches, volume_name), None) |
371 | 7181fba0 | Constantinos Venetsanopoulos | self.assertRaises(errors.BlockDeviceError, parse_function,
|
372 | 7181fba0 | Constantinos Venetsanopoulos | output_extra_matches, volume_name) |
373 | 7181fba0 | Constantinos Venetsanopoulos | |
374 | 7181fba0 | Constantinos Venetsanopoulos | |
375 | 3840729d | Iustin Pop | if __name__ == '__main__': |
376 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |