root / test / py / ganeti.utils.storage_unittest.py @ 70e8dd0a
History | View | Annotate | Download (5.5 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 import objects |
30 | 683335b3 | Helga Velroyen | from ganeti.utils import storage |
31 | 683335b3 | Helga Velroyen | |
32 | 683335b3 | Helga Velroyen | import testutils |
33 | 683335b3 | Helga Velroyen | |
34 | 683335b3 | Helga Velroyen | |
35 | 683335b3 | Helga Velroyen | class TestGetStorageUnitForDiskTemplate(unittest.TestCase): |
36 | 683335b3 | Helga Velroyen | |
37 | 683335b3 | Helga Velroyen | def setUp(self): |
38 | 683335b3 | Helga Velroyen | self._default_vg_name = "some_vg_name" |
39 | d721894a | Helga Velroyen | self._cluster = mock.Mock()
|
40 | d721894a | Helga Velroyen | self._cluster.file_storage_dir = "my/file/storage/dir" |
41 | 2fe1e043 | Helga Velroyen | self._cluster.shared_file_storage_dir = "my/shared/file/storage/dir" |
42 | 683335b3 | Helga Velroyen | self._cfg = mock.Mock()
|
43 | 683335b3 | Helga Velroyen | self._cfg.GetVGName = mock.Mock(return_value=self._default_vg_name) |
44 | d721894a | Helga Velroyen | self._cfg.GetClusterInfo = mock.Mock(return_value=self._cluster) |
45 | 683335b3 | Helga Velroyen | |
46 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateLvm(self): |
47 | 683335b3 | Helga Velroyen | for disk_template in [constants.DT_DRBD8, constants.DT_PLAIN]: |
48 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
49 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
50 | 683335b3 | Helga Velroyen | disk_template) |
51 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_LVM_VG)
|
52 | 683335b3 | Helga Velroyen | self.assertEqual(storage_key, self._default_vg_name) |
53 | 683335b3 | Helga Velroyen | |
54 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateFile(self): |
55 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
56 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
57 | 683335b3 | Helga Velroyen | constants.DT_FILE) |
58 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_FILE)
|
59 | d721894a | Helga Velroyen | self.assertEqual(storage_key, self._cluster.file_storage_dir) |
60 | 683335b3 | Helga Velroyen | |
61 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateSharedFile(self): |
62 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
63 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
64 | 683335b3 | Helga Velroyen | constants.DT_SHARED_FILE) |
65 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_FILE)
|
66 | 2fe1e043 | Helga Velroyen | self.assertEqual(storage_key, self._cluster.shared_file_storage_dir) |
67 | 683335b3 | Helga Velroyen | |
68 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForDiskTemplateDiskless(self): |
69 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
70 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate(self._cfg,
|
71 | 683335b3 | Helga Velroyen | constants.DT_DISKLESS) |
72 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_DISKLESS)
|
73 | 683335b3 | Helga Velroyen | self.assertEqual(storage_key, None) |
74 | 683335b3 | Helga Velroyen | |
75 | 683335b3 | Helga Velroyen | def testGetDefaultStorageUnitForSpindles(self): |
76 | 683335b3 | Helga Velroyen | (storage_type, storage_key) = \ |
77 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForSpindles(self._cfg)
|
78 | 683335b3 | Helga Velroyen | self.assertEqual(storage_type, constants.ST_LVM_PV)
|
79 | 683335b3 | Helga Velroyen | self.assertEqual(storage_key, self._default_vg_name) |
80 | 683335b3 | Helga Velroyen | |
81 | 683335b3 | Helga Velroyen | |
82 | 683335b3 | Helga Velroyen | class TestGetStorageUnitsOfCluster(unittest.TestCase): |
83 | 683335b3 | Helga Velroyen | |
84 | 683335b3 | Helga Velroyen | def setUp(self): |
85 | 683335b3 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate = \ |
86 | 683335b3 | Helga Velroyen | mock.Mock(return_value=("foo", "bar")) |
87 | 683335b3 | Helga Velroyen | |
88 | 683335b3 | Helga Velroyen | self._cluster_cfg = objects.Cluster()
|
89 | 683335b3 | Helga Velroyen | self._enabled_disk_templates = \
|
90 | 683335b3 | Helga Velroyen | [constants.DT_DRBD8, constants.DT_PLAIN, constants.DT_FILE, |
91 | 683335b3 | Helga Velroyen | constants.DT_SHARED_FILE] |
92 | 683335b3 | Helga Velroyen | self._cluster_cfg.enabled_disk_templates = \
|
93 | 683335b3 | Helga Velroyen | self._enabled_disk_templates
|
94 | 683335b3 | Helga Velroyen | self._cfg = mock.Mock()
|
95 | 683335b3 | Helga Velroyen | self._cfg.GetClusterInfo = mock.Mock(return_value=self._cluster_cfg) |
96 | 683335b3 | Helga Velroyen | self._cfg.GetVGName = mock.Mock(return_value="some_vg_name") |
97 | 683335b3 | Helga Velroyen | |
98 | 683335b3 | Helga Velroyen | def testGetStorageUnitsOfCluster(self): |
99 | 683335b3 | Helga Velroyen | storage_units = storage.GetStorageUnitsOfCluster(self._cfg)
|
100 | 683335b3 | Helga Velroyen | self.assertEqual(len(storage_units), len(self._enabled_disk_templates)) |
101 | 683335b3 | Helga Velroyen | |
102 | 683335b3 | Helga Velroyen | def testGetStorageUnitsOfClusterWithSpindles(self): |
103 | 683335b3 | Helga Velroyen | storage_units = storage.GetStorageUnitsOfCluster( |
104 | 683335b3 | Helga Velroyen | self._cfg, include_spindles=True) |
105 | 683335b3 | Helga Velroyen | self.assertEqual(len(storage_units), len(self._enabled_disk_templates) + 1) |
106 | 683335b3 | Helga Velroyen | self.assertTrue(constants.ST_LVM_PV in [st for (st, sk) in storage_units]) |
107 | 683335b3 | Helga Velroyen | |
108 | 683335b3 | Helga Velroyen | |
109 | b669aa41 | Helga Velroyen | class TestGetStorageUnits(unittest.TestCase): |
110 | b669aa41 | Helga Velroyen | |
111 | b669aa41 | Helga Velroyen | def setUp(self): |
112 | b669aa41 | Helga Velroyen | storage._GetDefaultStorageUnitForDiskTemplate = \ |
113 | b669aa41 | Helga Velroyen | mock.Mock(return_value=("foo", "bar")) |
114 | b669aa41 | Helga Velroyen | self._cfg = mock.Mock()
|
115 | b669aa41 | Helga Velroyen | |
116 | b669aa41 | Helga Velroyen | def testGetStorageUnits(self): |
117 | b669aa41 | Helga Velroyen | disk_templates = [constants.DT_FILE, constants.DT_SHARED_FILE] |
118 | b669aa41 | Helga Velroyen | storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
|
119 | b669aa41 | Helga Velroyen | self.assertEqual(len(storage_units), len(disk_templates)) |
120 | b669aa41 | Helga Velroyen | |
121 | b669aa41 | Helga Velroyen | def testGetStorageUnitsLvm(self): |
122 | b669aa41 | Helga Velroyen | disk_templates = [constants.DT_PLAIN, constants.DT_DRBD8] |
123 | b669aa41 | Helga Velroyen | storage_units = storage.GetStorageUnits(self._cfg, disk_templates)
|
124 | b669aa41 | Helga Velroyen | self.assertEqual(len(storage_units), len(disk_templates) + 1) |
125 | b669aa41 | Helga Velroyen | |
126 | b669aa41 | Helga Velroyen | |
127 | 683335b3 | Helga Velroyen | class TestLookupSpaceInfoByStorageType(unittest.TestCase): |
128 | 683335b3 | Helga Velroyen | |
129 | 683335b3 | Helga Velroyen | def setUp(self): |
130 | 683335b3 | Helga Velroyen | self._space_info = [
|
131 | 683335b3 | Helga Velroyen | {"type": st, "name": st + "_key", "storage_size": 0, "storage_free": 0} |
132 | d8e55568 | Helga Velroyen | for st in constants.STORAGE_TYPES] |
133 | 683335b3 | Helga Velroyen | |
134 | 683335b3 | Helga Velroyen | def testValidLookup(self): |
135 | 683335b3 | Helga Velroyen | query_type = constants.ST_LVM_PV |
136 | 683335b3 | Helga Velroyen | result = storage.LookupSpaceInfoByStorageType(self._space_info, query_type)
|
137 | 683335b3 | Helga Velroyen | self.assertEqual(query_type, result["type"]) |
138 | 683335b3 | Helga Velroyen | |
139 | 683335b3 | Helga Velroyen | def testNotInList(self): |
140 | 683335b3 | Helga Velroyen | result = storage.LookupSpaceInfoByStorageType(self._space_info,
|
141 | 683335b3 | Helga Velroyen | "non_existing_type")
|
142 | 683335b3 | Helga Velroyen | self.assertEqual(None, result) |
143 | 683335b3 | Helga Velroyen | |
144 | 683335b3 | Helga Velroyen | |
145 | 683335b3 | Helga Velroyen | if __name__ == "__main__": |
146 | 683335b3 | Helga Velroyen | testutils.GanetiTestProgram() |