Revision 8a69b3a8 test/ganeti.bdev_unittest.py
b/test/ganeti.bdev_unittest.py | ||
---|---|---|
27 | 27 |
|
28 | 28 |
from ganeti import bdev |
29 | 29 |
from ganeti import errors |
30 |
from ganeti import constants |
|
30 | 31 |
|
31 | 32 |
import testutils |
32 | 33 |
|
... | ... | |
156 | 157 |
"remote_addr" not in result), |
157 | 158 |
"Should not find network info") |
158 | 159 |
|
160 |
def testBarriersOptions(self): |
|
161 |
"""Test class method that generates drbdsetup options for disk barriers""" |
|
162 |
# Tests that should fail because of wrong version/options combinations |
|
163 |
should_fail = [ |
|
164 |
(8, 0, 12, "bfd", True), |
|
165 |
(8, 0, 12, "fd", False), |
|
166 |
(8, 0, 12, "b", True), |
|
167 |
(8, 2, 7, "bfd", True), |
|
168 |
(8, 2, 7, "b", True) |
|
169 |
] |
|
170 |
|
|
171 |
for vmaj, vmin, vrel, opts, meta in should_fail: |
|
172 |
self.assertRaises(errors.BlockDeviceError, |
|
173 |
bdev.DRBD8._ComputeDiskBarrierArgs, |
|
174 |
vmaj, vmin, vrel, opts, meta) |
|
175 |
|
|
176 |
# get the valid options from the frozenset(frozenset()) in constants. |
|
177 |
valid_options = [list(x)[0] for x in constants.DRBD_VALID_BARRIER_OPT] |
|
178 |
|
|
179 |
# Versions that do not support anything |
|
180 |
for vmaj, vmin, vrel in ((8, 0, 0), (8, 0, 11), (8, 2, 6)): |
|
181 |
for opts in valid_options: |
|
182 |
self.assertRaises(errors.BlockDeviceError, |
|
183 |
bdev.DRBD8._ComputeDiskBarrierArgs, |
|
184 |
vmaj, vmin, vrel, opts, True) |
|
185 |
|
|
186 |
# Versions with partial support (testing only options that are supported) |
|
187 |
tests = [ |
|
188 |
(8, 0, 12, "n", False, []), |
|
189 |
(8, 0, 12, "n", True, ["--no-md-flushes"]), |
|
190 |
(8, 2, 7, "n", False, []), |
|
191 |
(8, 2, 7, "fd", False, ["--no-disk-flushes", "--no-disk-drain"]), |
|
192 |
(8, 0, 12, "n", True, ["--no-md-flushes"]), |
|
193 |
] |
|
194 |
|
|
195 |
# Versions that support everything |
|
196 |
for vmaj, vmin, vrel in ((8, 3, 0), (8, 3, 12)): |
|
197 |
tests.append((vmaj, vmin, vrel, "bfd", True, |
|
198 |
["--no-disk-barrier", "--no-disk-drain", |
|
199 |
"--no-disk-flushes", "--no-md-flushes"])) |
|
200 |
tests.append((vmaj, vmin, vrel, "n", False, [])) |
|
201 |
tests.append((vmaj, vmin, vrel, "b", True, |
|
202 |
["--no-disk-barrier", "--no-md-flushes"])) |
|
203 |
tests.append((vmaj, vmin, vrel, "fd", False, |
|
204 |
["--no-disk-flushes", "--no-disk-drain"])) |
|
205 |
tests.append((vmaj, vmin, vrel, "n", True, ["--no-md-flushes"])) |
|
206 |
|
|
207 |
# Test execution |
|
208 |
for test in tests: |
|
209 |
vmaj, vmin, vrel, disabled_barriers, disable_meta_flush, expected = test |
|
210 |
args = \ |
|
211 |
bdev.DRBD8._ComputeDiskBarrierArgs(vmaj, vmin, vrel, |
|
212 |
disabled_barriers, |
|
213 |
disable_meta_flush) |
|
214 |
self.failUnless(set(args) == set(expected), |
|
215 |
"For test %s, got wrong results %s" % (test, args)) |
|
216 |
|
|
217 |
# Unsupported or invalid versions |
|
218 |
for vmaj, vmin, vrel in ((0, 7, 25), (9, 0, 0), (7, 0, 0), (8, 4, 0)): |
|
219 |
self.assertRaises(errors.BlockDeviceError, |
|
220 |
bdev.DRBD8._ComputeDiskBarrierArgs, |
|
221 |
vmaj, vmin, vrel, "n", True) |
|
222 |
|
|
223 |
# Invalid options |
|
224 |
for option in ("", "c", "whatever", "nbdfc", "nf"): |
|
225 |
self.assertRaises(errors.BlockDeviceError, |
|
226 |
bdev.DRBD8._ComputeDiskBarrierArgs, |
|
227 |
8, 3, 11, option, True) |
|
228 |
|
|
159 | 229 |
|
160 | 230 |
class TestDRBD8Status(testutils.GanetiTestCase): |
161 | 231 |
"""Testing case for DRBD8 /proc status""" |
Also available in: Unified diff