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