root / test / ganeti.constants_unittest.py @ d357f531
History | View | Annotate | Download (3.6 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 | eeb1d86a | Michael Hanselmann | # 0.0510-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 | eeb1d86a | Michael Hanselmann | |
28 | eeb1d86a | Michael Hanselmann | from ganeti import constants |
29 | eeb1d86a | Michael Hanselmann | |
30 | eeb1d86a | Michael Hanselmann | |
31 | eeb1d86a | Michael Hanselmann | class TestConstants(unittest.TestCase): |
32 | eeb1d86a | Michael Hanselmann | """Constants tests"""
|
33 | eeb1d86a | Michael Hanselmann | |
34 | eeb1d86a | Michael Hanselmann | def testConfigVersion(self): |
35 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_MAJOR >= 0 and |
36 | eeb1d86a | Michael Hanselmann | constants.CONFIG_MAJOR <= 99)
|
37 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_MINOR >= 0 and |
38 | eeb1d86a | Michael Hanselmann | constants.CONFIG_MINOR <= 99)
|
39 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_REVISION >= 0 and |
40 | eeb1d86a | Michael Hanselmann | constants.CONFIG_REVISION <= 9999)
|
41 | eeb1d86a | Michael Hanselmann | self.failUnless(constants.CONFIG_VERSION >= 0 and |
42 | eeb1d86a | Michael Hanselmann | constants.CONFIG_VERSION <= 99999999)
|
43 | eeb1d86a | Michael Hanselmann | |
44 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.BuildVersion(0, 0, 0) == 0) |
45 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.BuildVersion(10, 10, 1010) == 10101010) |
46 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.BuildVersion(12, 34, 5678) == 12345678) |
47 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.BuildVersion(99, 99, 9999) == 99999999) |
48 | 1b45f4e5 | Michael Hanselmann | |
49 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.SplitVersion(00000000) == (0, 0, 0)) |
50 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.SplitVersion(10101010) == (10, 10, 1010)) |
51 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.SplitVersion(12345678) == (12, 34, 5678)) |
52 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.SplitVersion(99999999) == (99, 99, 9999)) |
53 | 1b45f4e5 | Michael Hanselmann | self.failUnless(constants.SplitVersion(constants.CONFIG_VERSION) ==
|
54 | 1b45f4e5 | Michael Hanselmann | (constants.CONFIG_MAJOR, constants.CONFIG_MINOR, |
55 | 1b45f4e5 | Michael Hanselmann | constants.CONFIG_REVISION)) |
56 | 1b45f4e5 | Michael Hanselmann | |
57 | 74f37195 | Michael Hanselmann | def testDiskStatus(self): |
58 | 74f37195 | Michael Hanselmann | self.failUnless(constants.LDS_OKAY < constants.LDS_UNKNOWN)
|
59 | 74f37195 | Michael Hanselmann | self.failUnless(constants.LDS_UNKNOWN < constants.LDS_FAULTY)
|
60 | 74f37195 | Michael Hanselmann | |
61 | eeb1d86a | Michael Hanselmann | |
62 | 67fc3042 | Iustin Pop | class TestParameterNames(unittest.TestCase): |
63 | 67fc3042 | Iustin Pop | """HV/BE parameter tests"""
|
64 | 67fc3042 | Iustin Pop | VALID_NAME = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$")
|
65 | 67fc3042 | Iustin Pop | |
66 | 67fc3042 | Iustin Pop | def testNoDashes(self): |
67 | 67fc3042 | Iustin Pop | for kind, source in [('hypervisor', constants.HVS_PARAMETER_TYPES), |
68 | 476ce612 | Guido Trotter | ('backend', constants.BES_PARAMETER_TYPES),
|
69 | 476ce612 | Guido Trotter | ('nic', constants.NICS_PARAMETER_TYPES),
|
70 | 476ce612 | Guido Trotter | ]: |
71 | 67fc3042 | Iustin Pop | for key in source: |
72 | 67fc3042 | Iustin Pop | self.failUnless(self.VALID_NAME.match(key), |
73 | 67fc3042 | Iustin Pop | "The %s parameter '%s' contains invalid characters" %
|
74 | 67fc3042 | Iustin Pop | (kind, key)) |
75 | 67fc3042 | Iustin Pop | |
76 | 74f37195 | Michael Hanselmann | |
77 | 28a34a39 | Guido Trotter | class TestConfdConstants(unittest.TestCase): |
78 | 28a34a39 | Guido Trotter | """Test the confd constants"""
|
79 | 28a34a39 | Guido Trotter | |
80 | 28a34a39 | Guido Trotter | def testFourCc(self): |
81 | 28a34a39 | Guido Trotter | self.failUnlessEqual(len(constants.CONFD_MAGIC_FOURCC), 4, |
82 | 28a34a39 | Guido Trotter | "Invalid fourcc len, should be 4")
|
83 | 28a34a39 | Guido Trotter | |
84 | 28a34a39 | Guido Trotter | def _IsUniqueSequence(self, sequence): |
85 | 28a34a39 | Guido Trotter | seen = set()
|
86 | 28a34a39 | Guido Trotter | for member in sequence: |
87 | 28a34a39 | Guido Trotter | if member in seen: |
88 | 28a34a39 | Guido Trotter | return False |
89 | 28a34a39 | Guido Trotter | seen.add(member) |
90 | 28a34a39 | Guido Trotter | return True |
91 | 28a34a39 | Guido Trotter | |
92 | 28a34a39 | Guido Trotter | def testReqs(self): |
93 | 28a34a39 | Guido Trotter | self.failUnless(self._IsUniqueSequence(constants.CONFD_REQS), |
94 | 28a34a39 | Guido Trotter | "Duplicated confd request code")
|
95 | 28a34a39 | Guido Trotter | |
96 | 28a34a39 | Guido Trotter | def testReplStatuses(self): |
97 | 28a34a39 | Guido Trotter | self.failUnless(self._IsUniqueSequence(constants.CONFD_REPL_STATUSES), |
98 | 28a34a39 | Guido Trotter | "Duplicated confd reply status code")
|
99 | 28a34a39 | Guido Trotter | |
100 | 28a34a39 | Guido Trotter | |
101 | eeb1d86a | Michael Hanselmann | if __name__ == '__main__': |
102 | eeb1d86a | Michael Hanselmann | unittest.main() |