root / test / py / ganeti.utils.storage_unittest.py @ 14933c17
History | View | Annotate | Download (4.1 kB)
1 | 683335b3 | Helga Velroyen | #!/usr/bin/python
|
---|---|---|---|
2 | 683335b3 | Helga Velroyen | #
|
3 | 683335b3 | Helga Velroyen | |
4 | 683335b3 | Helga Velroyen | # Copyright (C) 2013 Google Inc.
|
5 | 683335b3 | Helga Velroyen | #
|
6 | 683335b3 | Helga Velroyen | # This program is free software; you can redistribute it and/or modify
|
7 | 683335b3 | Helga Velroyen | # it under the terms of the GNU General Public License as published by
|
8 | 683335b3 | Helga Velroyen | # the Free Software Foundation; either version 2 of the License, or
|
9 | 683335b3 | Helga Velroyen | # (at your option) any later version.
|
10 | 683335b3 | Helga Velroyen | #
|
11 | 683335b3 | Helga Velroyen | # This program is distributed in the hope that it will be useful, but
|
12 | 683335b3 | Helga Velroyen | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 683335b3 | Helga Velroyen | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 683335b3 | Helga Velroyen | # General Public License for more details.
|
15 | 683335b3 | Helga Velroyen | #
|
16 | 683335b3 | Helga Velroyen | # You should have received a copy of the GNU General Public License
|
17 | 683335b3 | Helga Velroyen | # along with this program; if not, write to the Free Software
|
18 | 683335b3 | Helga Velroyen | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 683335b3 | Helga Velroyen | # 02110-1301, USA.
|
20 | 683335b3 | Helga Velroyen | |
21 | 683335b3 | Helga Velroyen | |
22 | 683335b3 | Helga Velroyen | """Script for unittesting the ganeti.utils.storage module"""
|
23 | 683335b3 | Helga Velroyen | |
24 | 683335b3 | Helga Velroyen | import mock |
25 | 683335b3 | Helga Velroyen | |
26 | 683335b3 | Helga Velroyen | import unittest |
27 | 683335b3 | Helga Velroyen | |
28 | 683335b3 | Helga Velroyen | from ganeti import constants |
29 | 683335b3 | Helga Velroyen | from ganeti.utils import storage |
30 | 683335b3 | Helga Velroyen | |
31 | 683335b3 | Helga Velroyen | import testutils |
32 | 683335b3 | Helga Velroyen | |
33 | 683335b3 | Helga Velroyen | |
34 | 683335b3 | Helga Velroyen | class TestGetStorageUnitForDiskTemplate(unittest.TestCase): |
35 | 683335b3 | Helga Velroyen | |
36 | 683335b3 | Helga Velroyen | def setUp(self): |
37 | 683335b3 | Helga Velroyen | self._default_vg_name = "some_vg_name" |
38 | d721894a | Helga Velroyen | self._cluster = mock.Mock()
|
39 | d721894a | Helga Velroyen | self._cluster.file_storage_dir = "my/file/storage/dir" |
40 | 2fe1e043 | Helga Velroyen | self._cluster.shared_file_storage_dir = "my/shared/file/storage/dir" |
41 | 683335b3 | Helga Velroyen | self._cfg = mock.Mock()
|
42 | 683335b3 | Helga Velroyen | self._cfg.GetVGName = mock.Mock(return_value=self._default_vg_name) |
43 | d721894a | Helga Velroyen | self._cfg.GetClusterInfo = mock.Mock(return_value=self._cluster) |
44 | 683335b3 | Helga Velroyen | |
45 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateLvm(self): |
46 | 683335b3 | Helga Velroyen | for disk_template in [constants.DT_DRBD8, constants.DT_PLAIN]: |
47 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
48 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
49 | 683335b3 | Helga Velroyen | disk_template) |
50 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_LVM_VG)
|
51 | 683335b3 | Helga Velroyen | self.assertEqual(storage_key, self._default_vg_name) |
52 | 683335b3 | Helga Velroyen | |
53 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateFile(self): |
54 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
55 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
56 | 683335b3 | Helga Velroyen | constants.DT_FILE) |
57 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_FILE)
|
58 | d721894a | Helga Velroyen | self.assertEqual(storage_key, self._cluster.file_storage_dir) |
59 | 683335b3 | Helga Velroyen | |
60 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateSharedFile(self): |
61 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
62 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
63 | 683335b3 | Helga Velroyen | constants.DT_SHARED_FILE) |
64 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_FILE)
|
65 | 2fe1e043 | Helga Velroyen | self.assertEqual(storage_key, self._cluster.shared_file_storage_dir) |
66 | 683335b3 | Helga Velroyen | |
67 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateDiskless(self): |
68 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
69 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
70 | 683335b3 | Helga Velroyen | constants.DT_DISKLESS) |
71 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_DISKLESS)
|
72 | 683335b3 | Helga Velroyen | self.assertEqual(storage_key, None) |
73 | 683335b3 | Helga Velroyen | |
74 | 683335b3 | Helga Velroyen | |
75 | b669aa41 | Helga Velroyen | class TestGetStorageUnits(unittest.TestCase): |
76 | b669aa41 | Helga Velroyen | |
77 | b669aa41 | Helga Velroyen | def setUp(self): |
78 | b669aa41 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate = \ |
79 | b669aa41 | Helga Velroyen | mock.Mock(return_value=("foo", "bar")) |
80 | b669aa41 | Helga Velroyen | self._cfg = mock.Mock()
|
81 | b669aa41 | Helga Velroyen | |
82 | b669aa41 | Helga Velroyen | def testGetStorageUnits(self): |
83 | a09639d1 | Santi Raffa | disk_templates = constants.DTS_FILEBASED |
84 | b669aa41 | Helga Velroyen | storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
|
85 | b669aa41 | Helga Velroyen | self.assertEqual(len(storage_units), len(disk_templates)) |
86 | b669aa41 | Helga Velroyen | |
87 | b669aa41 | Helga Velroyen | def testGetStorageUnitsLvm(self): |
88 | b669aa41 | Helga Velroyen | disk_templates = [constants.DT_PLAIN, constants.DT_DRBD8] |
89 | b669aa41 | Helga Velroyen | storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
|
90 | 6c00b2c7 | Helga Velroyen | self.assertEqual(len(storage_units), len(disk_templates)) |
91 | b669aa41 | Helga Velroyen | |
92 | b669aa41 | Helga Velroyen | |
93 | 683335b3 | Helga Velroyen | class TestLookupSpaceInfoByStorageType(unittest.TestCase): |
94 | 683335b3 | Helga Velroyen | |
95 | 683335b3 | Helga Velroyen | def setUp(self): |
96 | 683335b3 | Helga Velroyen | self._space_info = [
|
97 | 683335b3 | Helga Velroyen | {"type": st, "name": st + "_key", "storage_size": 0, "storage_free": 0} |
98 | d8e55568 | Helga Velroyen | for st in constants.STORAGE_TYPES] |
99 | 683335b3 | Helga Velroyen | |
100 | 683335b3 | Helga Velroyen | def testValidLookup(self): |
101 | 683335b3 | Helga Velroyen | query_type = constants.ST_LVM_PV |
102 | 683335b3 | Helga Velroyen | result = storage.LookupSpaceInfoByStorageType(self._space_info, query_type)
|
103 | 683335b3 | Helga Velroyen | self.assertEqual(query_type, result["type"]) |
104 | 683335b3 | Helga Velroyen | |
105 | 683335b3 | Helga Velroyen | def testNotInList(self): |
106 | 683335b3 | Helga Velroyen | result = storage.LookupSpaceInfoByStorageType(self._space_info,
|
107 | 683335b3 | Helga Velroyen | "non_existing_type")
|
108 | 683335b3 | Helga Velroyen | self.assertEqual(None, result) |
109 | 683335b3 | Helga Velroyen | |
110 | 683335b3 | Helga Velroyen | |
111 | 683335b3 | Helga Velroyen | if __name__ == "__main__": |
112 | 683335b3 | Helga Velroyen | testutils.GanetiTestProgram() |