root / test / py / ganeti.storage.gluster_unittest.py @ 58793040
History | View | Annotate | Download (4.5 kB)
1 | 8106dd64 | Santi Raffa | #!/usr/bin/python
|
---|---|---|---|
2 | 8106dd64 | Santi Raffa | #
|
3 | 8106dd64 | Santi Raffa | |
4 | 8106dd64 | Santi Raffa | # Copyright (C) 2013 Google Inc.
|
5 | 8106dd64 | Santi Raffa | #
|
6 | 8106dd64 | Santi Raffa | # This program is free software; you can redistribute it and/or modify
|
7 | 8106dd64 | Santi Raffa | # it under the terms of the GNU General Public License as published by
|
8 | 8106dd64 | Santi Raffa | # the Free Software Foundation; either version 2 of the License, or
|
9 | 8106dd64 | Santi Raffa | # (at your option) any later version.
|
10 | 8106dd64 | Santi Raffa | #
|
11 | 8106dd64 | Santi Raffa | # This program is distributed in the hope that it will be useful, but
|
12 | 8106dd64 | Santi Raffa | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 8106dd64 | Santi Raffa | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 8106dd64 | Santi Raffa | # General Public License for more details.
|
15 | 8106dd64 | Santi Raffa | #
|
16 | 8106dd64 | Santi Raffa | # You should have received a copy of the GNU General Public License
|
17 | 8106dd64 | Santi Raffa | # along with this program; if not, write to the Free Software
|
18 | 8106dd64 | Santi Raffa | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 8106dd64 | Santi Raffa | # 02110-1301, USA.
|
20 | 8106dd64 | Santi Raffa | |
21 | 8106dd64 | Santi Raffa | """Script for unittesting the ganeti.storage.gluster module"""
|
22 | 8106dd64 | Santi Raffa | |
23 | 58793040 | Santi Raffa | import os |
24 | 58793040 | Santi Raffa | import shutil |
25 | 58793040 | Santi Raffa | import tempfile |
26 | 58793040 | Santi Raffa | import unittest |
27 | 58793040 | Santi Raffa | import mock |
28 | 58793040 | Santi Raffa | |
29 | 58793040 | Santi Raffa | from ganeti import errors |
30 | 58793040 | Santi Raffa | from ganeti.storage import filestorage |
31 | 58793040 | Santi Raffa | from ganeti.storage import gluster |
32 | 58793040 | Santi Raffa | from ganeti import utils |
33 | 58793040 | Santi Raffa | |
34 | 8106dd64 | Santi Raffa | import testutils |
35 | 8106dd64 | Santi Raffa | |
36 | 58793040 | Santi Raffa | class TestGlusterVolume(testutils.GanetiTestCase): |
37 | 58793040 | Santi Raffa | |
38 | 58793040 | Santi Raffa | testAddrIpv = {4: "203.0.113.42", |
39 | 58793040 | Santi Raffa | 6: "2001:DB8::74:65:28:6:69", |
40 | 58793040 | Santi Raffa | } |
41 | 58793040 | Santi Raffa | |
42 | 58793040 | Santi Raffa | @staticmethod
|
43 | 58793040 | Santi Raffa | def _MakeVolume(addr=None, port=9001, |
44 | 58793040 | Santi Raffa | run_cmd=NotImplemented,
|
45 | 58793040 | Santi Raffa | vol_name="pinky"):
|
46 | 58793040 | Santi Raffa | |
47 | 58793040 | Santi Raffa | addr = addr if addr is not None else TestGlusterVolume.testAddrIpv[4] |
48 | 58793040 | Santi Raffa | |
49 | 58793040 | Santi Raffa | return gluster.GlusterVolume(addr, port, vol_name, _run_cmd=run_cmd,
|
50 | 58793040 | Santi Raffa | _mount_point="/invalid")
|
51 | 58793040 | Santi Raffa | |
52 | 58793040 | Santi Raffa | def setUp(self): |
53 | 58793040 | Santi Raffa | testutils.GanetiTestCase.setUp(self)
|
54 | 58793040 | Santi Raffa | |
55 | 58793040 | Santi Raffa | # Create some volumes.
|
56 | 58793040 | Santi Raffa | self.vol_a = TestGlusterVolume._MakeVolume()
|
57 | 58793040 | Santi Raffa | self.vol_a_clone = TestGlusterVolume._MakeVolume()
|
58 | 58793040 | Santi Raffa | self.vol_b = TestGlusterVolume._MakeVolume(vol_name="pinker") |
59 | 58793040 | Santi Raffa | |
60 | 58793040 | Santi Raffa | def testEquality(self): |
61 | 58793040 | Santi Raffa | self.assertEqual(self.vol_a, self.vol_a_clone) |
62 | 58793040 | Santi Raffa | |
63 | 58793040 | Santi Raffa | def testInequality(self): |
64 | 58793040 | Santi Raffa | self.assertNotEqual(self.vol_a, self.vol_b) |
65 | 58793040 | Santi Raffa | |
66 | 58793040 | Santi Raffa | def testHostnameResolution(self): |
67 | 58793040 | Santi Raffa | vol_1 = TestGlusterVolume._MakeVolume(addr="localhost")
|
68 | 58793040 | Santi Raffa | self.assertEqual(vol_1.server_ip, "127.0.0.1") |
69 | 58793040 | Santi Raffa | self.assertRaises(errors.ResolverError, lambda: \ |
70 | 58793040 | Santi Raffa | TestGlusterVolume._MakeVolume(addr="E_NOENT"))
|
71 | 58793040 | Santi Raffa | |
72 | 58793040 | Santi Raffa | def testKVMMountStrings(self): |
73 | 58793040 | Santi Raffa | # The only source of documentation I can find is:
|
74 | 58793040 | Santi Raffa | # https://github.com/qemu/qemu/commit/8d6d89c
|
75 | 58793040 | Santi Raffa | # This test gets as close as possible to the examples given there,
|
76 | 58793040 | Santi Raffa | # within the limits of our implementation (no transport specification,
|
77 | 58793040 | Santi Raffa | # no default port version).
|
78 | 58793040 | Santi Raffa | |
79 | 58793040 | Santi Raffa | vol_1 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[4],
|
80 | 58793040 | Santi Raffa | port=24007,
|
81 | 58793040 | Santi Raffa | vol_name="testvol")
|
82 | 58793040 | Santi Raffa | self.assertEqual(
|
83 | 58793040 | Santi Raffa | vol_1.GetKVMMountString("dir/a.img"),
|
84 | 58793040 | Santi Raffa | "gluster://203.0.113.42:24007/testvol/dir/a.img"
|
85 | 58793040 | Santi Raffa | ) |
86 | 58793040 | Santi Raffa | |
87 | 58793040 | Santi Raffa | vol_2 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[6],
|
88 | 58793040 | Santi Raffa | port=24007,
|
89 | 58793040 | Santi Raffa | vol_name="testvol")
|
90 | 58793040 | Santi Raffa | self.assertEqual(
|
91 | 58793040 | Santi Raffa | vol_2.GetKVMMountString("dir/a.img"),
|
92 | 58793040 | Santi Raffa | "gluster://[2001:db8:0:74:65:28:6:69]:24007/testvol/dir/a.img"
|
93 | 58793040 | Santi Raffa | ) |
94 | 58793040 | Santi Raffa | |
95 | 58793040 | Santi Raffa | vol_3 = TestGlusterVolume._MakeVolume(addr="localhost",
|
96 | 58793040 | Santi Raffa | port=9001,
|
97 | 58793040 | Santi Raffa | vol_name="testvol")
|
98 | 58793040 | Santi Raffa | self.assertEqual(
|
99 | 58793040 | Santi Raffa | vol_3.GetKVMMountString("dir/a.img"),
|
100 | 58793040 | Santi Raffa | "gluster://127.0.0.1:9001/testvol/dir/a.img"
|
101 | 58793040 | Santi Raffa | ) |
102 | 58793040 | Santi Raffa | |
103 | 58793040 | Santi Raffa | def testFUSEMountStrings(self): |
104 | 58793040 | Santi Raffa | vol_1 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[4],
|
105 | 58793040 | Santi Raffa | port=24007,
|
106 | 58793040 | Santi Raffa | vol_name="testvol")
|
107 | 58793040 | Santi Raffa | self.assertEqual(
|
108 | 58793040 | Santi Raffa | vol_1._GetFUSEMountString(), |
109 | 58793040 | Santi Raffa | "203.0.113.42:24007:testvol"
|
110 | 58793040 | Santi Raffa | ) |
111 | 58793040 | Santi Raffa | |
112 | 58793040 | Santi Raffa | vol_2 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[6],
|
113 | 58793040 | Santi Raffa | port=24007,
|
114 | 58793040 | Santi Raffa | vol_name="testvol")
|
115 | 58793040 | Santi Raffa | # This _ought_ to work. https://bugzilla.redhat.com/show_bug.cgi?id=764188
|
116 | 58793040 | Santi Raffa | self.assertEqual(
|
117 | 58793040 | Santi Raffa | vol_2._GetFUSEMountString(), |
118 | 58793040 | Santi Raffa | "2001:db8:0:74:65:28:6:69:24007:testvol"
|
119 | 58793040 | Santi Raffa | ) |
120 | 58793040 | Santi Raffa | |
121 | 58793040 | Santi Raffa | vol_3 = TestGlusterVolume._MakeVolume(addr="localhost",
|
122 | 58793040 | Santi Raffa | port=9001,
|
123 | 58793040 | Santi Raffa | vol_name="testvol")
|
124 | 58793040 | Santi Raffa | self.assertEqual(
|
125 | 58793040 | Santi Raffa | vol_3._GetFUSEMountString(), |
126 | 58793040 | Santi Raffa | "127.0.0.1:9001:testvol"
|
127 | 58793040 | Santi Raffa | ) |
128 | 58793040 | Santi Raffa | |
129 | 58793040 | Santi Raffa | |
130 | 8106dd64 | Santi Raffa | if __name__ == "__main__": |
131 | 8106dd64 | Santi Raffa | testutils.GanetiTestProgram() |