root / test / ganeti.bdev_unittest.py @ e9a81214
History | View | Annotate | Download (17.6 kB)
1 | 3840729d | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | 3840729d | Iustin Pop | #
|
3 | 3840729d | Iustin Pop | |
4 | df99f3a9 | Michael Hanselmann | # Copyright (C) 2006, 2007, 2010, 2012 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 | fbdac0d9 | Michael Hanselmann | from ganeti import utils |
32 | df99f3a9 | Michael Hanselmann | from ganeti import pathutils |
33 | 3840729d | Iustin Pop | |
34 | 25231ec5 | Michael Hanselmann | import testutils |
35 | 25231ec5 | Michael Hanselmann | |
36 | 3840729d | Iustin Pop | |
37 | fcee765d | Manuel Franceschini | class TestBaseDRBD(testutils.GanetiTestCase): |
38 | fcee765d | Manuel Franceschini | def testGetVersion(self): |
39 | fcee765d | Manuel Franceschini | data = [ |
40 | fcee765d | Manuel Franceschini | ["version: 8.0.12 (api:76/proto:86-91)"],
|
41 | fcee765d | Manuel Franceschini | ["version: 8.2.7 (api:88/proto:0-100)"],
|
42 | fcee765d | Manuel Franceschini | ["version: 8.3.7.49 (api:188/proto:13-191)"],
|
43 | fcee765d | Manuel Franceschini | ] |
44 | fcee765d | Manuel Franceschini | result = [ |
45 | fcee765d | Manuel Franceschini | { |
46 | fcee765d | Manuel Franceschini | "k_major": 8, |
47 | fcee765d | Manuel Franceschini | "k_minor": 0, |
48 | fcee765d | Manuel Franceschini | "k_point": 12, |
49 | fcee765d | Manuel Franceschini | "api": 76, |
50 | fcee765d | Manuel Franceschini | "proto": 86, |
51 | fcee765d | Manuel Franceschini | "proto2": "91", |
52 | fcee765d | Manuel Franceschini | }, |
53 | fcee765d | Manuel Franceschini | { |
54 | fcee765d | Manuel Franceschini | "k_major": 8, |
55 | fcee765d | Manuel Franceschini | "k_minor": 2, |
56 | fcee765d | Manuel Franceschini | "k_point": 7, |
57 | fcee765d | Manuel Franceschini | "api": 88, |
58 | fcee765d | Manuel Franceschini | "proto": 0, |
59 | fcee765d | Manuel Franceschini | "proto2": "100", |
60 | fcee765d | Manuel Franceschini | }, |
61 | fcee765d | Manuel Franceschini | { |
62 | fcee765d | Manuel Franceschini | "k_major": 8, |
63 | fcee765d | Manuel Franceschini | "k_minor": 3, |
64 | fcee765d | Manuel Franceschini | "k_point": 7, |
65 | fcee765d | Manuel Franceschini | "api": 188, |
66 | fcee765d | Manuel Franceschini | "proto": 13, |
67 | fcee765d | Manuel Franceschini | "proto2": "191", |
68 | fcee765d | Manuel Franceschini | } |
69 | fcee765d | Manuel Franceschini | ] |
70 | fcee765d | Manuel Franceschini | for d,r in zip(data, result): |
71 | fcee765d | Manuel Franceschini | self.assertEqual(bdev.BaseDRBD._GetVersion(d), r)
|
72 | fcee765d | Manuel Franceschini | |
73 | fcee765d | Manuel Franceschini | |
74 | 149a5439 | Iustin Pop | class TestDRBD8Runner(testutils.GanetiTestCase): |
75 | 3840729d | Iustin Pop | """Testing case for DRBD8"""
|
76 | 3840729d | Iustin Pop | |
77 | 3840729d | Iustin Pop | @staticmethod
|
78 | 3840729d | Iustin Pop | def _has_disk(data, dname, mname): |
79 | 3840729d | Iustin Pop | """Check local disk corectness"""
|
80 | 3840729d | Iustin Pop | retval = ( |
81 | 3840729d | Iustin Pop | "local_dev" in data and |
82 | 3840729d | Iustin Pop | data["local_dev"] == dname and |
83 | 3840729d | Iustin Pop | "meta_dev" in data and |
84 | 3840729d | Iustin Pop | data["meta_dev"] == mname and |
85 | 3840729d | Iustin Pop | "meta_index" in data and |
86 | 3840729d | Iustin Pop | data["meta_index"] == 0 |
87 | 3840729d | Iustin Pop | ) |
88 | 3840729d | Iustin Pop | return retval
|
89 | 3840729d | Iustin Pop | |
90 | 3840729d | Iustin Pop | @staticmethod
|
91 | 3840729d | Iustin Pop | def _has_net(data, local, remote): |
92 | 3840729d | Iustin Pop | """Check network connection parameters"""
|
93 | 3840729d | Iustin Pop | retval = ( |
94 | 3840729d | Iustin Pop | "local_addr" in data and |
95 | 3840729d | Iustin Pop | data["local_addr"] == local and |
96 | 3840729d | Iustin Pop | "remote_addr" in data and |
97 | 3840729d | Iustin Pop | data["remote_addr"] == remote
|
98 | 3840729d | Iustin Pop | ) |
99 | 3840729d | Iustin Pop | return retval
|
100 | 3840729d | Iustin Pop | |
101 | 3840729d | Iustin Pop | def testParserCreation(self): |
102 | 3840729d | Iustin Pop | """Test drbdsetup show parser creation"""
|
103 | 3840729d | Iustin Pop | bdev.DRBD8._GetShowParser() |
104 | 3840729d | Iustin Pop | |
105 | 5a672c30 | Manuel Franceschini | def testParser80(self): |
106 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for disk and network version 8.0"""
|
107 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-8.0.txt") |
108 | 3840729d | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
109 | 3840729d | Iustin Pop | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
110 | 3840729d | Iustin Pop | "/dev/xenvg/test.meta"),
|
111 | 3840729d | Iustin Pop | "Wrong local disk info")
|
112 | 926feaf1 | Manuel Franceschini | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
113 | 926feaf1 | Manuel Franceschini | ("192.0.2.2", 11000)), |
114 | 01e2ce3a | Iustin Pop | "Wrong network info (8.0.x)")
|
115 | 01e2ce3a | Iustin Pop | |
116 | 5a672c30 | Manuel Franceschini | def testParser83(self): |
117 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for disk and network version 8.3"""
|
118 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-8.3.txt") |
119 | 01e2ce3a | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
120 | 01e2ce3a | Iustin Pop | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
121 | 01e2ce3a | Iustin Pop | "/dev/xenvg/test.meta"),
|
122 | 01e2ce3a | Iustin Pop | "Wrong local disk info")
|
123 | 926feaf1 | Manuel Franceschini | self.failUnless(self._has_net(result, ("192.0.2.1", 11000), |
124 | 926feaf1 | Manuel Franceschini | ("192.0.2.2", 11000)), |
125 | 5a672c30 | Manuel Franceschini | "Wrong network info (8.0.x)")
|
126 | 3840729d | Iustin Pop | |
127 | 5a672c30 | Manuel Franceschini | def testParserNetIP4(self): |
128 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for IPv4 network"""
|
129 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-net-ip4.txt") |
130 | 3840729d | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
131 | 3840729d | Iustin Pop | self.failUnless(("local_dev" not in result and |
132 | 3840729d | Iustin Pop | "meta_dev" not in result and |
133 | 3840729d | Iustin Pop | "meta_index" not in result), |
134 | 3840729d | Iustin Pop | "Should not find local disk info")
|
135 | 926feaf1 | Manuel Franceschini | self.failUnless(self._has_net(result, ("192.0.2.1", 11002), |
136 | 926feaf1 | Manuel Franceschini | ("192.0.2.2", 11002)), |
137 | 5a672c30 | Manuel Franceschini | "Wrong network info (IPv4)")
|
138 | 5a672c30 | Manuel Franceschini | |
139 | 5a672c30 | Manuel Franceschini | def testParserNetIP6(self): |
140 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for IPv6 network"""
|
141 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-net-ip6.txt") |
142 | 5a672c30 | Manuel Franceschini | result = bdev.DRBD8._GetDevInfo(data) |
143 | 5a672c30 | Manuel Franceschini | self.failUnless(("local_dev" not in result and |
144 | 5a672c30 | Manuel Franceschini | "meta_dev" not in result and |
145 | 5a672c30 | Manuel Franceschini | "meta_index" not in result), |
146 | 5a672c30 | Manuel Franceschini | "Should not find local disk info")
|
147 | 5a672c30 | Manuel Franceschini | self.failUnless(self._has_net(result, ("2001:db8:65::1", 11048), |
148 | 5a672c30 | Manuel Franceschini | ("2001:db8:66::1", 11048)), |
149 | 5a672c30 | Manuel Franceschini | "Wrong network info (IPv6)")
|
150 | 3840729d | Iustin Pop | |
151 | 3840729d | Iustin Pop | def testParserDisk(self): |
152 | 5a672c30 | Manuel Franceschini | """Test drbdsetup show parser for disk"""
|
153 | 5a672c30 | Manuel Franceschini | data = self._ReadTestData("bdev-drbd-disk.txt") |
154 | 3840729d | Iustin Pop | result = bdev.DRBD8._GetDevInfo(data) |
155 | 3840729d | Iustin Pop | self.failUnless(self._has_disk(result, "/dev/xenvg/test.data", |
156 | 3840729d | Iustin Pop | "/dev/xenvg/test.meta"),
|
157 | 3840729d | Iustin Pop | "Wrong local disk info")
|
158 | 3840729d | Iustin Pop | self.failUnless(("local_addr" not in result and |
159 | 3840729d | Iustin Pop | "remote_addr" not in result), |
160 | 3840729d | Iustin Pop | "Should not find network info")
|
161 | 3840729d | Iustin Pop | |
162 | 8a69b3a8 | Andrea Spadaccini | def testBarriersOptions(self): |
163 | 8a69b3a8 | Andrea Spadaccini | """Test class method that generates drbdsetup options for disk barriers"""
|
164 | 8a69b3a8 | Andrea Spadaccini | # Tests that should fail because of wrong version/options combinations
|
165 | 8a69b3a8 | Andrea Spadaccini | should_fail = [ |
166 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "bfd", True), |
167 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "fd", False), |
168 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "b", True), |
169 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "bfd", True), |
170 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "b", True) |
171 | 8a69b3a8 | Andrea Spadaccini | ] |
172 | 8a69b3a8 | Andrea Spadaccini | |
173 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel, opts, meta in should_fail: |
174 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
175 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
176 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, opts, meta) |
177 | 8a69b3a8 | Andrea Spadaccini | |
178 | 8a69b3a8 | Andrea Spadaccini | # get the valid options from the frozenset(frozenset()) in constants.
|
179 | 8a69b3a8 | Andrea Spadaccini | valid_options = [list(x)[0] for x in constants.DRBD_VALID_BARRIER_OPT] |
180 | 8a69b3a8 | Andrea Spadaccini | |
181 | 8a69b3a8 | Andrea Spadaccini | # Versions that do not support anything
|
182 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel in ((8, 0, 0), (8, 0, 11), (8, 2, 6)): |
183 | 8a69b3a8 | Andrea Spadaccini | for opts in valid_options: |
184 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
185 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
186 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, opts, True)
|
187 | 8a69b3a8 | Andrea Spadaccini | |
188 | 8a69b3a8 | Andrea Spadaccini | # Versions with partial support (testing only options that are supported)
|
189 | 8a69b3a8 | Andrea Spadaccini | tests = [ |
190 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "n", False, []), |
191 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
192 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "n", False, []), |
193 | 8a69b3a8 | Andrea Spadaccini | (8, 2, 7, "fd", False, ["--no-disk-flushes", "--no-disk-drain"]), |
194 | 8a69b3a8 | Andrea Spadaccini | (8, 0, 12, "n", True, ["--no-md-flushes"]), |
195 | 8a69b3a8 | Andrea Spadaccini | ] |
196 | 8a69b3a8 | Andrea Spadaccini | |
197 | 8a69b3a8 | Andrea Spadaccini | # Versions that support everything
|
198 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel in ((8, 3, 0), (8, 3, 12)): |
199 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "bfd", True, |
200 | 8a69b3a8 | Andrea Spadaccini | ["--no-disk-barrier", "--no-disk-drain", |
201 | 8a69b3a8 | Andrea Spadaccini | "--no-disk-flushes", "--no-md-flushes"])) |
202 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "n", False, [])) |
203 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "b", True, |
204 | 8a69b3a8 | Andrea Spadaccini | ["--no-disk-barrier", "--no-md-flushes"])) |
205 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "fd", False, |
206 | 8a69b3a8 | Andrea Spadaccini | ["--no-disk-flushes", "--no-disk-drain"])) |
207 | 8a69b3a8 | Andrea Spadaccini | tests.append((vmaj, vmin, vrel, "n", True, ["--no-md-flushes"])) |
208 | 8a69b3a8 | Andrea Spadaccini | |
209 | 8a69b3a8 | Andrea Spadaccini | # Test execution
|
210 | 8a69b3a8 | Andrea Spadaccini | for test in tests: |
211 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, disabled_barriers, disable_meta_flush, expected = test |
212 | 8a69b3a8 | Andrea Spadaccini | args = \ |
213 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs(vmaj, vmin, vrel, |
214 | 8a69b3a8 | Andrea Spadaccini | disabled_barriers, |
215 | 8a69b3a8 | Andrea Spadaccini | disable_meta_flush) |
216 | 8a69b3a8 | Andrea Spadaccini | self.failUnless(set(args) == set(expected), |
217 | 8a69b3a8 | Andrea Spadaccini | "For test %s, got wrong results %s" % (test, args))
|
218 | 8a69b3a8 | Andrea Spadaccini | |
219 | 8a69b3a8 | Andrea Spadaccini | # Unsupported or invalid versions
|
220 | 8a69b3a8 | Andrea Spadaccini | for vmaj, vmin, vrel in ((0, 7, 25), (9, 0, 0), (7, 0, 0), (8, 4, 0)): |
221 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
222 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
223 | 8a69b3a8 | Andrea Spadaccini | vmaj, vmin, vrel, "n", True) |
224 | 8a69b3a8 | Andrea Spadaccini | |
225 | 8a69b3a8 | Andrea Spadaccini | # Invalid options
|
226 | 8a69b3a8 | Andrea Spadaccini | for option in ("", "c", "whatever", "nbdfc", "nf"): |
227 | 8a69b3a8 | Andrea Spadaccini | self.assertRaises(errors.BlockDeviceError,
|
228 | 8a69b3a8 | Andrea Spadaccini | bdev.DRBD8._ComputeDiskBarrierArgs, |
229 | 8a69b3a8 | Andrea Spadaccini | 8, 3, 11, option, True) |
230 | 8a69b3a8 | Andrea Spadaccini | |
231 | 6b90c22e | Iustin Pop | |
232 | 149a5439 | Iustin Pop | class TestDRBD8Status(testutils.GanetiTestCase): |
233 | 6b90c22e | Iustin Pop | """Testing case for DRBD8 /proc status"""
|
234 | 6b90c22e | Iustin Pop | |
235 | 6b90c22e | Iustin Pop | def setUp(self): |
236 | 6b90c22e | Iustin Pop | """Read in txt data"""
|
237 | 51596eb2 | Iustin Pop | testutils.GanetiTestCase.setUp(self)
|
238 | 149a5439 | Iustin Pop | proc_data = self._TestDataFilename("proc_drbd8.txt") |
239 | 67d101d4 | Iustin Pop | proc80e_data = self._TestDataFilename("proc_drbd80-emptyline.txt") |
240 | 01e2ce3a | Iustin Pop | proc83_data = self._TestDataFilename("proc_drbd83.txt") |
241 | 7a380ddf | Renรฉ Nussbaumer | proc83_sync_data = self._TestDataFilename("proc_drbd83_sync.txt") |
242 | 7a380ddf | Renรฉ Nussbaumer | proc83_sync_krnl_data = \ |
243 | 7a380ddf | Renรฉ Nussbaumer | self._TestDataFilename("proc_drbd83_sync_krnl2.6.39.txt") |
244 | ae9da390 | Iustin Pop | self.proc_data = bdev.DRBD8._GetProcData(filename=proc_data)
|
245 | 67d101d4 | Iustin Pop | self.proc80e_data = bdev.DRBD8._GetProcData(filename=proc80e_data)
|
246 | 01e2ce3a | Iustin Pop | self.proc83_data = bdev.DRBD8._GetProcData(filename=proc83_data)
|
247 | 7a380ddf | Renรฉ Nussbaumer | self.proc83_sync_data = bdev.DRBD8._GetProcData(filename=proc83_sync_data)
|
248 | 7a380ddf | Renรฉ Nussbaumer | self.proc83_sync_krnl_data = \
|
249 | 7a380ddf | Renรฉ Nussbaumer | bdev.DRBD8._GetProcData(filename=proc83_sync_krnl_data) |
250 | 6b90c22e | Iustin Pop | self.mass_data = bdev.DRBD8._MassageProcData(self.proc_data) |
251 | 67d101d4 | Iustin Pop | self.mass80e_data = bdev.DRBD8._MassageProcData(self.proc80e_data) |
252 | 01e2ce3a | Iustin Pop | self.mass83_data = bdev.DRBD8._MassageProcData(self.proc83_data) |
253 | 7a380ddf | Renรฉ Nussbaumer | self.mass83_sync_data = bdev.DRBD8._MassageProcData(self.proc83_sync_data) |
254 | 7a380ddf | Renรฉ Nussbaumer | self.mass83_sync_krnl_data = \
|
255 | 7a380ddf | Renรฉ Nussbaumer | bdev.DRBD8._MassageProcData(self.proc83_sync_krnl_data)
|
256 | 6b90c22e | Iustin Pop | |
257 | f6eaed12 | Iustin Pop | def testIOErrors(self): |
258 | f6eaed12 | Iustin Pop | """Test handling of errors while reading the proc file."""
|
259 | f6eaed12 | Iustin Pop | temp_file = self._CreateTempFile()
|
260 | f6eaed12 | Iustin Pop | os.unlink(temp_file) |
261 | f6eaed12 | Iustin Pop | self.failUnlessRaises(errors.BlockDeviceError,
|
262 | f6eaed12 | Iustin Pop | bdev.DRBD8._GetProcData, filename=temp_file) |
263 | f6eaed12 | Iustin Pop | |
264 | 549071a0 | Luca Bigliardi | def testHelper(self): |
265 | 549071a0 | Luca Bigliardi | """Test reading usermode_helper in /sys."""
|
266 | 549071a0 | Luca Bigliardi | sys_drbd_helper = self._TestDataFilename("sys_drbd_usermode_helper.txt") |
267 | 549071a0 | Luca Bigliardi | drbd_helper = bdev.DRBD8.GetUsermodeHelper(filename=sys_drbd_helper) |
268 | 549071a0 | Luca Bigliardi | self.failUnlessEqual(drbd_helper, "/bin/true") |
269 | 549071a0 | Luca Bigliardi | |
270 | 549071a0 | Luca Bigliardi | def testHelperIOErrors(self): |
271 | 549071a0 | Luca Bigliardi | """Test handling of errors while reading usermode_helper in /sys."""
|
272 | 549071a0 | Luca Bigliardi | temp_file = self._CreateTempFile()
|
273 | 549071a0 | Luca Bigliardi | os.unlink(temp_file) |
274 | 549071a0 | Luca Bigliardi | self.failUnlessRaises(errors.BlockDeviceError,
|
275 | 549071a0 | Luca Bigliardi | bdev.DRBD8.GetUsermodeHelper, filename=temp_file) |
276 | 549071a0 | Luca Bigliardi | |
277 | 6b90c22e | Iustin Pop | def testMinorNotFound(self): |
278 | 6b90c22e | Iustin Pop | """Test not-found-minor in /proc"""
|
279 | 6b90c22e | Iustin Pop | self.failUnless(9 not in self.mass_data) |
280 | 01e2ce3a | Iustin Pop | self.failUnless(9 not in self.mass83_data) |
281 | 67d101d4 | Iustin Pop | self.failUnless(3 not in self.mass80e_data) |
282 | 6b90c22e | Iustin Pop | |
283 | 6b90c22e | Iustin Pop | def testLineNotMatch(self): |
284 | 6b90c22e | Iustin Pop | """Test wrong line passed to DRBD8Status"""
|
285 | 6b90c22e | Iustin Pop | self.assertRaises(errors.BlockDeviceError, bdev.DRBD8Status, "foo") |
286 | 6b90c22e | Iustin Pop | |
287 | 6b90c22e | Iustin Pop | def testMinor0(self): |
288 | 6b90c22e | Iustin Pop | """Test connected, primary device"""
|
289 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
290 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[0])
|
291 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
292 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_connected and stats.is_primary and |
293 | 01e2ce3a | Iustin Pop | stats.peer_secondary and stats.is_disk_uptodate)
|
294 | 6b90c22e | Iustin Pop | |
295 | 6b90c22e | Iustin Pop | def testMinor1(self): |
296 | 6b90c22e | Iustin Pop | """Test connected, secondary device"""
|
297 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
298 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[1])
|
299 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
300 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_connected and stats.is_secondary and |
301 | 01e2ce3a | Iustin Pop | stats.peer_primary and stats.is_disk_uptodate)
|
302 | 6b90c22e | Iustin Pop | |
303 | 767d52d3 | Iustin Pop | def testMinor2(self): |
304 | 767d52d3 | Iustin Pop | """Test unconfigured device"""
|
305 | 67d101d4 | Iustin Pop | for data in [self.mass_data, self.mass83_data, self.mass80e_data]: |
306 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[2])
|
307 | 01e2ce3a | Iustin Pop | self.failIf(stats.is_in_use)
|
308 | 767d52d3 | Iustin Pop | |
309 | 6b90c22e | Iustin Pop | def testMinor4(self): |
310 | 6b90c22e | Iustin Pop | """Test WFconn device"""
|
311 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
312 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[4])
|
313 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
314 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_wfconn and stats.is_primary and |
315 | 8c114acd | Michael Hanselmann | stats.rrole == "Unknown" and |
316 | 01e2ce3a | Iustin Pop | stats.is_disk_uptodate) |
317 | 6b90c22e | Iustin Pop | |
318 | 6b90c22e | Iustin Pop | def testMinor6(self): |
319 | 6b90c22e | Iustin Pop | """Test diskless device"""
|
320 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
321 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[6])
|
322 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
323 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_connected and stats.is_secondary and |
324 | 01e2ce3a | Iustin Pop | stats.peer_primary and stats.is_diskless)
|
325 | 6b90c22e | Iustin Pop | |
326 | 6b90c22e | Iustin Pop | def testMinor8(self): |
327 | 6b90c22e | Iustin Pop | """Test standalone device"""
|
328 | 01e2ce3a | Iustin Pop | for data in [self.mass_data, self.mass83_data]: |
329 | 01e2ce3a | Iustin Pop | stats = bdev.DRBD8Status(data[8])
|
330 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_in_use)
|
331 | 01e2ce3a | Iustin Pop | self.failUnless(stats.is_standalone and |
332 | 8c114acd | Michael Hanselmann | stats.rrole == "Unknown" and |
333 | 01e2ce3a | Iustin Pop | stats.is_disk_uptodate) |
334 | 6b90c22e | Iustin Pop | |
335 | 7a380ddf | Renรฉ Nussbaumer | def testDRBD83SyncFine(self): |
336 | 7a380ddf | Renรฉ Nussbaumer | stats = bdev.DRBD8Status(self.mass83_sync_data[3]) |
337 | 7a380ddf | Renรฉ Nussbaumer | self.failUnless(stats.is_in_resync)
|
338 | 7a380ddf | Renรฉ Nussbaumer | self.failUnless(stats.sync_percent is not None) |
339 | 7a380ddf | Renรฉ Nussbaumer | |
340 | 7a380ddf | Renรฉ Nussbaumer | def testDRBD83SyncBroken(self): |
341 | 7a380ddf | Renรฉ Nussbaumer | stats = bdev.DRBD8Status(self.mass83_sync_krnl_data[3]) |
342 | 7a380ddf | Renรฉ Nussbaumer | self.failUnless(stats.is_in_resync)
|
343 | 7a380ddf | Renรฉ Nussbaumer | self.failUnless(stats.sync_percent is not None) |
344 | 7a380ddf | Renรฉ Nussbaumer | |
345 | 7181fba0 | Constantinos Venetsanopoulos | |
346 | 7181fba0 | Constantinos Venetsanopoulos | class TestRADOSBlockDevice(testutils.GanetiTestCase): |
347 | 7181fba0 | Constantinos Venetsanopoulos | def test_ParseRbdShowmappedOutput(self): |
348 | 7181fba0 | Constantinos Venetsanopoulos | volume_name = "abc9778-8e8ace5b.rbd.disk0"
|
349 | 7181fba0 | Constantinos Venetsanopoulos | output_ok = \ |
350 | 7181fba0 | Constantinos Venetsanopoulos | ("0\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
|
351 | 7181fba0 | Constantinos Venetsanopoulos | "1\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd16\n"
|
352 | 7181fba0 | Constantinos Venetsanopoulos | "line\twith\tfewer\tfields\n"
|
353 | 7181fba0 | Constantinos Venetsanopoulos | "")
|
354 | 7181fba0 | Constantinos Venetsanopoulos | output_empty = ""
|
355 | 7181fba0 | Constantinos Venetsanopoulos | output_no_matches = \ |
356 | 7181fba0 | Constantinos Venetsanopoulos | ("0\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
|
357 | 7181fba0 | Constantinos Venetsanopoulos | "1\trbd\tabcdef01-9817.rbd.disk0\t-\t/dev/rbd10\n"
|
358 | 7181fba0 | Constantinos Venetsanopoulos | "2\trbd\tcdef0123-9817.rbd.disk0\t-\t/dev/rbd12\n"
|
359 | 7181fba0 | Constantinos Venetsanopoulos | "something\twith\tfewer\tfields"
|
360 | 7181fba0 | Constantinos Venetsanopoulos | "")
|
361 | 7181fba0 | Constantinos Venetsanopoulos | output_extra_matches = \ |
362 | 7181fba0 | Constantinos Venetsanopoulos | ("0\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd11\n"
|
363 | 7181fba0 | Constantinos Venetsanopoulos | "1\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
|
364 | 7181fba0 | Constantinos Venetsanopoulos | "2\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd16\n"
|
365 | 7181fba0 | Constantinos Venetsanopoulos | "something\twith\tfewer\tfields"
|
366 | 7181fba0 | Constantinos Venetsanopoulos | "")
|
367 | 7181fba0 | Constantinos Venetsanopoulos | |
368 | 7181fba0 | Constantinos Venetsanopoulos | parse_function = bdev.RADOSBlockDevice._ParseRbdShowmappedOutput |
369 | 7181fba0 | Constantinos Venetsanopoulos | self.assertEqual(parse_function(output_ok, volume_name), "/dev/rbd16") |
370 | 7181fba0 | Constantinos Venetsanopoulos | self.assertRaises(errors.BlockDeviceError, parse_function,
|
371 | 7181fba0 | Constantinos Venetsanopoulos | output_empty, volume_name) |
372 | 7181fba0 | Constantinos Venetsanopoulos | self.assertEqual(parse_function(output_no_matches, volume_name), None) |
373 | 7181fba0 | Constantinos Venetsanopoulos | self.assertRaises(errors.BlockDeviceError, parse_function,
|
374 | 7181fba0 | Constantinos Venetsanopoulos | output_extra_matches, volume_name) |
375 | 7181fba0 | Constantinos Venetsanopoulos | |
376 | 7181fba0 | Constantinos Venetsanopoulos | |
377 | 23e3c9b7 | Michael Hanselmann | class TestComputeWrongFileStoragePathsInternal(unittest.TestCase): |
378 | 23e3c9b7 | Michael Hanselmann | def testPaths(self): |
379 | 23e3c9b7 | Michael Hanselmann | paths = bdev._GetForbiddenFileStoragePaths() |
380 | 23e3c9b7 | Michael Hanselmann | |
381 | 23e3c9b7 | Michael Hanselmann | for path in ["/bin", "/usr/local/sbin", "/lib64", "/etc", "/sys"]: |
382 | 23e3c9b7 | Michael Hanselmann | self.assertTrue(path in paths) |
383 | 23e3c9b7 | Michael Hanselmann | |
384 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(set(map(os.path.normpath, paths)), paths) |
385 | 23e3c9b7 | Michael Hanselmann | |
386 | 23e3c9b7 | Michael Hanselmann | def test(self): |
387 | 23e3c9b7 | Michael Hanselmann | vfsp = bdev._ComputeWrongFileStoragePaths |
388 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(vfsp([]), [])
|
389 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(vfsp(["/tmp"]), []) |
390 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(vfsp(["/bin/ls"]), ["/bin/ls"]) |
391 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(vfsp(["/bin"]), ["/bin"]) |
392 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(vfsp(["/usr/sbin/vim", "/srv/file-storage"]), |
393 | 23e3c9b7 | Michael Hanselmann | ["/usr/sbin/vim"])
|
394 | 23e3c9b7 | Michael Hanselmann | |
395 | 23e3c9b7 | Michael Hanselmann | |
396 | 23e3c9b7 | Michael Hanselmann | class TestComputeWrongFileStoragePaths(testutils.GanetiTestCase): |
397 | 23e3c9b7 | Michael Hanselmann | def test(self): |
398 | 23e3c9b7 | Michael Hanselmann | tmpfile = self._CreateTempFile()
|
399 | 23e3c9b7 | Michael Hanselmann | |
400 | 23e3c9b7 | Michael Hanselmann | utils.WriteFile(tmpfile, data="""
|
401 | 23e3c9b7 | Michael Hanselmann | /tmp
|
402 | 23e3c9b7 | Michael Hanselmann | x/y///z/relative
|
403 | 23e3c9b7 | Michael Hanselmann | # This is a test file
|
404 | 23e3c9b7 | Michael Hanselmann | /srv/storage
|
405 | 23e3c9b7 | Michael Hanselmann | /bin
|
406 | 23e3c9b7 | Michael Hanselmann | /usr/local/lib32/
|
407 | 23e3c9b7 | Michael Hanselmann | relative/path
|
408 | 23e3c9b7 | Michael Hanselmann | """)
|
409 | 23e3c9b7 | Michael Hanselmann | |
410 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(bdev.ComputeWrongFileStoragePaths(_filename=tmpfile), [
|
411 | 23e3c9b7 | Michael Hanselmann | "/bin",
|
412 | 23e3c9b7 | Michael Hanselmann | "/usr/local/lib32",
|
413 | 23e3c9b7 | Michael Hanselmann | "relative/path",
|
414 | 23e3c9b7 | Michael Hanselmann | "x/y/z/relative",
|
415 | 23e3c9b7 | Michael Hanselmann | ]) |
416 | 23e3c9b7 | Michael Hanselmann | |
417 | 23e3c9b7 | Michael Hanselmann | |
418 | 23e3c9b7 | Michael Hanselmann | class TestCheckFileStoragePathInternal(unittest.TestCase): |
419 | fbdac0d9 | Michael Hanselmann | def testNonAbsolute(self): |
420 | fbdac0d9 | Michael Hanselmann | for i in ["", "tmp", "foo/bar/baz"]: |
421 | fbdac0d9 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
422 | fbdac0d9 | Michael Hanselmann | bdev._CheckFileStoragePath, i, ["/tmp"])
|
423 | fbdac0d9 | Michael Hanselmann | |
424 | fbdac0d9 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
425 | fbdac0d9 | Michael Hanselmann | bdev._CheckFileStoragePath, "/tmp", ["tmp", "xyz"]) |
426 | fbdac0d9 | Michael Hanselmann | |
427 | fbdac0d9 | Michael Hanselmann | def testNoAllowed(self): |
428 | fbdac0d9 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
429 | fbdac0d9 | Michael Hanselmann | bdev._CheckFileStoragePath, "/tmp", [])
|
430 | fbdac0d9 | Michael Hanselmann | |
431 | fbdac0d9 | Michael Hanselmann | def testNoAdditionalPathComponent(self): |
432 | fbdac0d9 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
433 | fbdac0d9 | Michael Hanselmann | bdev._CheckFileStoragePath, "/tmp/foo", ["/tmp/foo"]) |
434 | fbdac0d9 | Michael Hanselmann | |
435 | fbdac0d9 | Michael Hanselmann | def testAllowed(self): |
436 | fbdac0d9 | Michael Hanselmann | bdev._CheckFileStoragePath("/tmp/foo/a", ["/tmp/foo"]) |
437 | fbdac0d9 | Michael Hanselmann | bdev._CheckFileStoragePath("/tmp/foo/a/x", ["/tmp/foo"]) |
438 | fbdac0d9 | Michael Hanselmann | |
439 | fbdac0d9 | Michael Hanselmann | |
440 | 23e3c9b7 | Michael Hanselmann | class TestCheckFileStoragePath(testutils.GanetiTestCase): |
441 | 23e3c9b7 | Michael Hanselmann | def testNonExistantFile(self): |
442 | 23e3c9b7 | Michael Hanselmann | filename = "/tmp/this/file/does/not/exist"
|
443 | 23e3c9b7 | Michael Hanselmann | assert not os.path.exists(filename) |
444 | 23e3c9b7 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
445 | 23e3c9b7 | Michael Hanselmann | bdev.CheckFileStoragePath, "/bin/", _filename=filename)
|
446 | 23e3c9b7 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
447 | 23e3c9b7 | Michael Hanselmann | bdev.CheckFileStoragePath, "/srv/file-storage",
|
448 | 23e3c9b7 | Michael Hanselmann | _filename=filename) |
449 | 23e3c9b7 | Michael Hanselmann | |
450 | 23e3c9b7 | Michael Hanselmann | def testAllowedPath(self): |
451 | 23e3c9b7 | Michael Hanselmann | tmpfile = self._CreateTempFile()
|
452 | 23e3c9b7 | Michael Hanselmann | |
453 | 23e3c9b7 | Michael Hanselmann | utils.WriteFile(tmpfile, data="""
|
454 | 23e3c9b7 | Michael Hanselmann | /srv/storage
|
455 | 23e3c9b7 | Michael Hanselmann | """)
|
456 | 23e3c9b7 | Michael Hanselmann | |
457 | 23e3c9b7 | Michael Hanselmann | bdev.CheckFileStoragePath("/srv/storage/inst1", _filename=tmpfile)
|
458 | 23e3c9b7 | Michael Hanselmann | |
459 | 23e3c9b7 | Michael Hanselmann | # No additional path component
|
460 | 23e3c9b7 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
461 | 23e3c9b7 | Michael Hanselmann | bdev.CheckFileStoragePath, "/srv/storage",
|
462 | 23e3c9b7 | Michael Hanselmann | _filename=tmpfile) |
463 | 23e3c9b7 | Michael Hanselmann | |
464 | 23e3c9b7 | Michael Hanselmann | # Forbidden path
|
465 | 23e3c9b7 | Michael Hanselmann | self.assertRaises(errors.FileStoragePathError,
|
466 | 23e3c9b7 | Michael Hanselmann | bdev.CheckFileStoragePath, "/usr/lib64/xyz",
|
467 | 23e3c9b7 | Michael Hanselmann | _filename=tmpfile) |
468 | 23e3c9b7 | Michael Hanselmann | |
469 | 23e3c9b7 | Michael Hanselmann | |
470 | fbdac0d9 | Michael Hanselmann | class TestLoadAllowedFileStoragePaths(testutils.GanetiTestCase): |
471 | fbdac0d9 | Michael Hanselmann | def testDevNull(self): |
472 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(bdev._LoadAllowedFileStoragePaths("/dev/null"), []) |
473 | fbdac0d9 | Michael Hanselmann | |
474 | fbdac0d9 | Michael Hanselmann | def testNonExistantFile(self): |
475 | fbdac0d9 | Michael Hanselmann | filename = "/tmp/this/file/does/not/exist"
|
476 | fbdac0d9 | Michael Hanselmann | assert not os.path.exists(filename) |
477 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(bdev._LoadAllowedFileStoragePaths(filename), [])
|
478 | fbdac0d9 | Michael Hanselmann | |
479 | fbdac0d9 | Michael Hanselmann | def test(self): |
480 | fbdac0d9 | Michael Hanselmann | tmpfile = self._CreateTempFile()
|
481 | fbdac0d9 | Michael Hanselmann | |
482 | fbdac0d9 | Michael Hanselmann | utils.WriteFile(tmpfile, data="""
|
483 | fbdac0d9 | Michael Hanselmann | # This is a test file
|
484 | fbdac0d9 | Michael Hanselmann | /tmp
|
485 | fbdac0d9 | Michael Hanselmann | /srv/storage
|
486 | fbdac0d9 | Michael Hanselmann | relative/path
|
487 | fbdac0d9 | Michael Hanselmann | """)
|
488 | fbdac0d9 | Michael Hanselmann | |
489 | 23e3c9b7 | Michael Hanselmann | self.assertEqual(bdev._LoadAllowedFileStoragePaths(tmpfile), [
|
490 | fbdac0d9 | Michael Hanselmann | "/tmp",
|
491 | fbdac0d9 | Michael Hanselmann | "/srv/storage",
|
492 | fbdac0d9 | Michael Hanselmann | "relative/path",
|
493 | fbdac0d9 | Michael Hanselmann | ]) |
494 | fbdac0d9 | Michael Hanselmann | |
495 | fbdac0d9 | Michael Hanselmann | |
496 | fbdac0d9 | Michael Hanselmann | if __name__ == "__main__": |
497 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |