root / test / py / ganeti.constants_unittest.py @ 14933c17
History | View | Annotate | Download (6.4 kB)
1 | eeb1d86a | Michael Hanselmann | #!/usr/bin/python
|
---|---|---|---|
2 | eeb1d86a | Michael Hanselmann | #
|
3 | eeb1d86a | Michael Hanselmann | |
4 | eeb1d86a | Michael Hanselmann | # Copyright (C) 2006, 2007, 2008 Google Inc.
|
5 | eeb1d86a | Michael Hanselmann | #
|
6 | eeb1d86a | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | eeb1d86a | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | eeb1d86a | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | eeb1d86a | Michael Hanselmann | # (at your option) any later version.
|
10 | eeb1d86a | Michael Hanselmann | #
|
11 | eeb1d86a | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | eeb1d86a | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | eeb1d86a | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | eeb1d86a | Michael Hanselmann | # General Public License for more details.
|
15 | eeb1d86a | Michael Hanselmann | #
|
16 | eeb1d86a | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | eeb1d86a | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | eeb1d86a | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | fd7b69c0 | Michael Hanselmann | # 02110-1301, USA.
|
20 | eeb1d86a | Michael Hanselmann | |
21 | eeb1d86a | Michael Hanselmann | |
22 | eeb1d86a | Michael Hanselmann | """Script for unittesting the constants module"""
|
23 | eeb1d86a | Michael Hanselmann | |
24 | eeb1d86a | Michael Hanselmann | |
25 | eeb1d86a | Michael Hanselmann | import unittest |
26 | 67fc3042 | Iustin Pop | import re |
27 | b8d51bb2 | Michael Hanselmann | import itertools |
28 | eeb1d86a | Michael Hanselmann | |
29 | eeb1d86a | Michael Hanselmann | from ganeti import constants |
30 | e5d8774b | Michael Hanselmann | from ganeti import locking |
31 | b8d51bb2 | Michael Hanselmann | from ganeti import utils |
32 | eeb1d86a | Michael Hanselmann | |
33 | effc1b86 | Jose A. Lopes | from ganeti.utils import version |
34 | effc1b86 | Jose A. Lopes | |
35 | 25231ec5 | Michael Hanselmann | import testutils |
36 | 25231ec5 | Michael Hanselmann | |
37 | eeb1d86a | Michael Hanselmann | |
38 | eeb1d86a | Michael Hanselmann | class TestConstants(unittest.TestCase): |
39 | eeb1d86a | Michael Hanselmann | """Constants tests"""
|
40 | eeb1d86a | Michael Hanselmann | |
41 | eeb1d86a | Michael Hanselmann | def testConfigVersion(self): |
42 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_MAJOR >= 0 and |
43 | eeb1d86a | Michael Hanselmann | constants.CONFIG_MAJOR <= 99)
|
44 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_MINOR >= 0 and |
45 | eeb1d86a | Michael Hanselmann | constants.CONFIG_MINOR <= 99)
|
46 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_REVISION >= 0 and |
47 | eeb1d86a | Michael Hanselmann | constants.CONFIG_REVISION <= 9999)
|
48 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_VERSION >= 0 and |
49 | eeb1d86a | Michael Hanselmann | constants.CONFIG_VERSION <= 99999999)
|
50 | eeb1d86a | Michael Hanselmann | |
51 | effc1b86 | Jose A. Lopes | self.failUnless(version.BuildVersion(0, 0, 0) == 0) |
52 | effc1b86 | Jose A. Lopes | self.failUnless(version.BuildVersion(10, 10, 1010) == 10101010) |
53 | effc1b86 | Jose A. Lopes | self.failUnless(version.BuildVersion(12, 34, 5678) == 12345678) |
54 | effc1b86 | Jose A. Lopes | self.failUnless(version.BuildVersion(99, 99, 9999) == 99999999) |
55 | 1b45f4e5 | Michael Hanselmann | |
56 | effc1b86 | Jose A. Lopes | self.failUnless(version.SplitVersion(00000000) == (0, 0, 0)) |
57 | effc1b86 | Jose A. Lopes | self.failUnless(version.SplitVersion(10101010) == (10, 10, 1010)) |
58 | effc1b86 | Jose A. Lopes | self.failUnless(version.SplitVersion(12345678) == (12, 34, 5678)) |
59 | effc1b86 | Jose A. Lopes | self.failUnless(version.SplitVersion(99999999) == (99, 99, 9999)) |
60 | effc1b86 | Jose A. Lopes | self.failUnless(version.SplitVersion(constants.CONFIG_VERSION) ==
|
61 | 1b45f4e5 | Michael Hanselmann | (constants.CONFIG_MAJOR, constants.CONFIG_MINOR, |
62 | 1b45f4e5 | Michael Hanselmann | constants.CONFIG_REVISION)) |
63 | 1b45f4e5 | Michael Hanselmann | |
64 | 74f37195 | Michael Hanselmann | def testDiskStatus(self): |
65 | 74f37195 | Michael Hanselmann | self.failUnless(constants.LDS_OKAY < constants.LDS_UNKNOWN)
|
66 | 74f37195 | Michael Hanselmann | self.failUnless(constants.LDS_UNKNOWN < constants.LDS_FAULTY)
|
67 | 74f37195 | Michael Hanselmann | |
68 | 313b2dd4 | Michael Hanselmann | def testClockSkew(self): |
69 | 313b2dd4 | Michael Hanselmann | self.failUnless(constants.NODE_MAX_CLOCK_SKEW <
|
70 | 313b2dd4 | Michael Hanselmann | (0.8 * constants.CONFD_MAX_CLOCK_SKEW))
|
71 | 313b2dd4 | Michael Hanselmann | |
72 | b98bf262 | Michael Hanselmann | def testSslCertExpiration(self): |
73 | b98bf262 | Michael Hanselmann | self.failUnless(constants.SSL_CERT_EXPIRATION_ERROR <
|
74 | b98bf262 | Michael Hanselmann | constants.SSL_CERT_EXPIRATION_WARN) |
75 | b98bf262 | Michael Hanselmann | |
76 | e5d8774b | Michael Hanselmann | def testOpCodePriority(self): |
77 | e5d8774b | Michael Hanselmann | self.failUnless(constants.OP_PRIO_LOWEST > constants.OP_PRIO_LOW)
|
78 | e5d8774b | Michael Hanselmann | self.failUnless(constants.OP_PRIO_LOW > constants.OP_PRIO_NORMAL)
|
79 | e5d8774b | Michael Hanselmann | self.failUnlessEqual(constants.OP_PRIO_NORMAL, locking._DEFAULT_PRIORITY)
|
80 | e5d8774b | Michael Hanselmann | self.failUnlessEqual(constants.OP_PRIO_DEFAULT, locking._DEFAULT_PRIORITY)
|
81 | e5d8774b | Michael Hanselmann | self.failUnless(constants.OP_PRIO_NORMAL > constants.OP_PRIO_HIGH)
|
82 | e5d8774b | Michael Hanselmann | self.failUnless(constants.OP_PRIO_HIGH > constants.OP_PRIO_HIGHEST)
|
83 | e5d8774b | Michael Hanselmann | |
84 | bc5d0215 | Andrea Spadaccini | def testDiskDefaults(self): |
85 | 880ab678 | Helga Velroyen | self.failUnless(
|
86 | 880ab678 | Helga Velroyen | set(constants.DISK_LD_DEFAULTS.keys()) ==
|
87 | 880ab678 | Helga Velroyen | set(constants.DISK_TEMPLATES) - set([constants.DT_DISKLESS])) |
88 | bc5d0215 | Andrea Spadaccini | self.failUnless(set(constants.DISK_DT_DEFAULTS.keys()) == |
89 | bc5d0215 | Andrea Spadaccini | constants.DISK_TEMPLATES) |
90 | bc5d0215 | Andrea Spadaccini | |
91 | 1eaddbc6 | Michael Hanselmann | def testJobStatus(self): |
92 | 1eaddbc6 | Michael Hanselmann | self.assertFalse(constants.JOBS_PENDING & constants.JOBS_FINALIZED)
|
93 | 1eaddbc6 | Michael Hanselmann | self.assertFalse(constants.JOBS_PENDING - constants.JOB_STATUS_ALL)
|
94 | 1eaddbc6 | Michael Hanselmann | self.assertFalse(constants.JOBS_FINALIZED - constants.JOB_STATUS_ALL)
|
95 | 1eaddbc6 | Michael Hanselmann | |
96 | 5fee2c83 | Michael Hanselmann | def testDefaultsForAllHypervisors(self): |
97 | 5fee2c83 | Michael Hanselmann | self.assertEqual(frozenset(constants.HVC_DEFAULTS.keys()), |
98 | 5fee2c83 | Michael Hanselmann | constants.HYPER_TYPES) |
99 | 5fee2c83 | Michael Hanselmann | |
100 | 5fee2c83 | Michael Hanselmann | def testDefaultHypervisor(self): |
101 | 5fee2c83 | Michael Hanselmann | self.assertTrue(constants.DEFAULT_ENABLED_HYPERVISOR in |
102 | 5fee2c83 | Michael Hanselmann | constants.HYPER_TYPES) |
103 | 5fee2c83 | Michael Hanselmann | |
104 | eeb1d86a | Michael Hanselmann | |
105 | b8d51bb2 | Michael Hanselmann | class TestExportedNames(unittest.TestCase): |
106 | b8d51bb2 | Michael Hanselmann | _VALID_NAME_RE = re.compile(r"^[A-Z][A-Z0-9_]+$")
|
107 | b8d51bb2 | Michael Hanselmann | _BUILTIN_NAME_RE = re.compile(r"^__\w+__$")
|
108 | b8d51bb2 | Michael Hanselmann | _EXCEPTIONS = frozenset([
|
109 | b8d51bb2 | Michael Hanselmann | "SplitVersion",
|
110 | b8d51bb2 | Michael Hanselmann | "BuildVersion",
|
111 | b8d51bb2 | Michael Hanselmann | ]) |
112 | b8d51bb2 | Michael Hanselmann | |
113 | b8d51bb2 | Michael Hanselmann | def test(self): |
114 | b8d51bb2 | Michael Hanselmann | wrong = \ |
115 | b8d51bb2 | Michael Hanselmann | set(itertools.ifilterfalse(self._BUILTIN_NAME_RE.match, |
116 | b8d51bb2 | Michael Hanselmann | itertools.ifilterfalse(self._VALID_NAME_RE.match,
|
117 | b8d51bb2 | Michael Hanselmann | dir(constants))))
|
118 | b8d51bb2 | Michael Hanselmann | wrong -= self._EXCEPTIONS
|
119 | b8d51bb2 | Michael Hanselmann | self.assertFalse(wrong,
|
120 | b8d51bb2 | Michael Hanselmann | msg=("Invalid names exported from constants module: %s" %
|
121 | b8d51bb2 | Michael Hanselmann | utils.CommaJoin(sorted(wrong))))
|
122 | b8d51bb2 | Michael Hanselmann | |
123 | b8d51bb2 | Michael Hanselmann | |
124 | 67fc3042 | Iustin Pop | class TestParameterNames(unittest.TestCase): |
125 | 67fc3042 | Iustin Pop | """HV/BE parameter tests"""
|
126 | 67fc3042 | Iustin Pop | VALID_NAME = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$")
|
127 | 67fc3042 | Iustin Pop | |
128 | 67fc3042 | Iustin Pop | def testNoDashes(self): |
129 | 8c114acd | Michael Hanselmann | for kind, source in [("hypervisor", constants.HVS_PARAMETER_TYPES), |
130 | 8c114acd | Michael Hanselmann | ("backend", constants.BES_PARAMETER_TYPES),
|
131 | 8c114acd | Michael Hanselmann | ("nic", constants.NICS_PARAMETER_TYPES),
|
132 | 405241dc | Michael Hanselmann | ("instdisk", constants.IDISK_PARAMS_TYPES),
|
133 | 405241dc | Michael Hanselmann | ("instnic", constants.INIC_PARAMS_TYPES),
|
134 | 476ce612 | Guido Trotter | ]: |
135 | 67fc3042 | Iustin Pop | for key in source: |
136 | 67fc3042 | Iustin Pop | self.failUnless(self.VALID_NAME.match(key), |
137 | 67fc3042 | Iustin Pop | "The %s parameter '%s' contains invalid characters" %
|
138 | 67fc3042 | Iustin Pop | (kind, key)) |
139 | 67fc3042 | Iustin Pop | |
140 | 74f37195 | Michael Hanselmann | |
141 | 28a34a39 | Guido Trotter | class TestConfdConstants(unittest.TestCase): |
142 | 28a34a39 | Guido Trotter | """Test the confd constants"""
|
143 | 28a34a39 | Guido Trotter | |
144 | 28a34a39 | Guido Trotter | def testFourCc(self): |
145 | 7bb6e137 | Michael Hanselmann | self.assertEqual(len(constants.CONFD_MAGIC_FOURCC), 4, |
146 | 7bb6e137 | Michael Hanselmann | msg="Invalid fourcc len, should be 4")
|
147 | 28a34a39 | Guido Trotter | |
148 | 28a34a39 | Guido Trotter | def testReqs(self): |
149 | 7bb6e137 | Michael Hanselmann | self.assertFalse(utils.FindDuplicates(constants.CONFD_REQS),
|
150 | 7bb6e137 | Michael Hanselmann | msg="Duplicated confd request code")
|
151 | 28a34a39 | Guido Trotter | |
152 | 28a34a39 | Guido Trotter | def testReplStatuses(self): |
153 | 7bb6e137 | Michael Hanselmann | self.assertFalse(utils.FindDuplicates(constants.CONFD_REPL_STATUSES),
|
154 | 7bb6e137 | Michael Hanselmann | msg="Duplicated confd reply status code")
|
155 | 28a34a39 | Guido Trotter | |
156 | 0b6c56bb | Helga Velroyen | class TestDiskTemplateConstants(unittest.TestCase): |
157 | 0b6c56bb | Helga Velroyen | |
158 | 0b6c56bb | Helga Velroyen | def testPreference(self): |
159 | 0b6c56bb | Helga Velroyen | self.assertEqual(set(constants.DISK_TEMPLATE_PREFERENCE), |
160 | 0b6c56bb | Helga Velroyen | set(constants.DISK_TEMPLATES))
|
161 | 0b6c56bb | Helga Velroyen | |
162 | 0b6c56bb | Helga Velroyen | def testMapToStorageTypes(self): |
163 | 0b6c56bb | Helga Velroyen | for disk_template in constants.DISK_TEMPLATES: |
164 | 0b6c56bb | Helga Velroyen | self.assertTrue(
|
165 | 0b6c56bb | Helga Velroyen | constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template] is not None) |
166 | 0b6c56bb | Helga Velroyen | |
167 | d48c944b | Helga Velroyen | def testLvmDiskTemplates(self): |
168 | d48c944b | Helga Velroyen | lvm_by_storage_type = [ |
169 | d48c944b | Helga Velroyen | dt for dt in constants.DISK_TEMPLATES |
170 | d48c944b | Helga Velroyen | if constants.ST_LVM_VG == constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[dt]]
|
171 | d48c944b | Helga Velroyen | self.assertEqual(set(lvm_by_storage_type), set(constants.DTS_LVM)) |
172 | d48c944b | Helga Velroyen | |
173 | 28a34a39 | Guido Trotter | |
174 | 7bb6e137 | Michael Hanselmann | if __name__ == "__main__": |
175 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |