Revision fbdac0d9 test/ganeti.bdev_unittest.py
b/test/ganeti.bdev_unittest.py | ||
---|---|---|
28 | 28 |
from ganeti import bdev |
29 | 29 |
from ganeti import errors |
30 | 30 |
from ganeti import constants |
31 |
from ganeti import utils |
|
31 | 32 |
|
32 | 33 |
import testutils |
33 | 34 |
|
... | ... | |
372 | 373 |
output_extra_matches, volume_name) |
373 | 374 |
|
374 | 375 |
|
375 |
if __name__ == '__main__': |
|
376 |
class TestCheckFileStoragePath(unittest.TestCase): |
|
377 |
def testNonAbsolute(self): |
|
378 |
for i in ["", "tmp", "foo/bar/baz"]: |
|
379 |
self.assertRaises(errors.FileStoragePathError, |
|
380 |
bdev._CheckFileStoragePath, i, ["/tmp"]) |
|
381 |
|
|
382 |
self.assertRaises(errors.FileStoragePathError, |
|
383 |
bdev._CheckFileStoragePath, "/tmp", ["tmp", "xyz"]) |
|
384 |
|
|
385 |
def testNoAllowed(self): |
|
386 |
self.assertRaises(errors.FileStoragePathError, |
|
387 |
bdev._CheckFileStoragePath, "/tmp", []) |
|
388 |
|
|
389 |
def testNoAdditionalPathComponent(self): |
|
390 |
self.assertRaises(errors.FileStoragePathError, |
|
391 |
bdev._CheckFileStoragePath, "/tmp/foo", ["/tmp/foo"]) |
|
392 |
|
|
393 |
def testAllowed(self): |
|
394 |
bdev._CheckFileStoragePath("/tmp/foo/a", ["/tmp/foo"]) |
|
395 |
bdev._CheckFileStoragePath("/tmp/foo/a/x", ["/tmp/foo"]) |
|
396 |
|
|
397 |
|
|
398 |
class TestLoadAllowedFileStoragePaths(testutils.GanetiTestCase): |
|
399 |
def testDevNull(self): |
|
400 |
self.assertEqual(bdev.LoadAllowedFileStoragePaths("/dev/null"), []) |
|
401 |
|
|
402 |
def testNonExistantFile(self): |
|
403 |
filename = "/tmp/this/file/does/not/exist" |
|
404 |
assert not os.path.exists(filename) |
|
405 |
self.assertEqual(bdev.LoadAllowedFileStoragePaths(filename), []) |
|
406 |
|
|
407 |
def test(self): |
|
408 |
tmpfile = self._CreateTempFile() |
|
409 |
|
|
410 |
utils.WriteFile(tmpfile, data=""" |
|
411 |
# This is a test file |
|
412 |
/tmp |
|
413 |
/srv/storage |
|
414 |
relative/path |
|
415 |
""") |
|
416 |
|
|
417 |
self.assertEqual(bdev.LoadAllowedFileStoragePaths(tmpfile), [ |
|
418 |
"/tmp", |
|
419 |
"/srv/storage", |
|
420 |
"relative/path", |
|
421 |
]) |
|
422 |
|
|
423 |
|
|
424 |
if __name__ == "__main__": |
|
376 | 425 |
testutils.GanetiTestProgram() |
Also available in: Unified diff