4 # Copyright (C) 2006, 2007, 2008 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Script for unittesting the constants module"""
28 from ganeti import constants
29 from ganeti import locking
34 class TestConstants(unittest.TestCase):
37 def testConfigVersion(self):
38 self.failUnless(constants.CONFIG_MAJOR >= 0 and
39 constants.CONFIG_MAJOR <= 99)
40 self.failUnless(constants.CONFIG_MINOR >= 0 and
41 constants.CONFIG_MINOR <= 99)
42 self.failUnless(constants.CONFIG_REVISION >= 0 and
43 constants.CONFIG_REVISION <= 9999)
44 self.failUnless(constants.CONFIG_VERSION >= 0 and
45 constants.CONFIG_VERSION <= 99999999)
47 self.failUnless(constants.BuildVersion(0, 0, 0) == 0)
48 self.failUnless(constants.BuildVersion(10, 10, 1010) == 10101010)
49 self.failUnless(constants.BuildVersion(12, 34, 5678) == 12345678)
50 self.failUnless(constants.BuildVersion(99, 99, 9999) == 99999999)
52 self.failUnless(constants.SplitVersion(00000000) == (0, 0, 0))
53 self.failUnless(constants.SplitVersion(10101010) == (10, 10, 1010))
54 self.failUnless(constants.SplitVersion(12345678) == (12, 34, 5678))
55 self.failUnless(constants.SplitVersion(99999999) == (99, 99, 9999))
56 self.failUnless(constants.SplitVersion(constants.CONFIG_VERSION) ==
57 (constants.CONFIG_MAJOR, constants.CONFIG_MINOR,
58 constants.CONFIG_REVISION))
60 def testDiskStatus(self):
61 self.failUnless(constants.LDS_OKAY < constants.LDS_UNKNOWN)
62 self.failUnless(constants.LDS_UNKNOWN < constants.LDS_FAULTY)
64 def testClockSkew(self):
65 self.failUnless(constants.NODE_MAX_CLOCK_SKEW <
66 (0.8 * constants.CONFD_MAX_CLOCK_SKEW))
68 def testSslCertExpiration(self):
69 self.failUnless(constants.SSL_CERT_EXPIRATION_ERROR <
70 constants.SSL_CERT_EXPIRATION_WARN)
72 def testOpCodePriority(self):
73 self.failUnless(constants.OP_PRIO_LOWEST > constants.OP_PRIO_LOW)
74 self.failUnless(constants.OP_PRIO_LOW > constants.OP_PRIO_NORMAL)
75 self.failUnlessEqual(constants.OP_PRIO_NORMAL, locking._DEFAULT_PRIORITY)
76 self.failUnlessEqual(constants.OP_PRIO_DEFAULT, locking._DEFAULT_PRIORITY)
77 self.failUnless(constants.OP_PRIO_NORMAL > constants.OP_PRIO_HIGH)
78 self.failUnless(constants.OP_PRIO_HIGH > constants.OP_PRIO_HIGHEST)
81 class TestParameterNames(unittest.TestCase):
82 """HV/BE parameter tests"""
83 VALID_NAME = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$")
85 def testNoDashes(self):
86 for kind, source in [('hypervisor', constants.HVS_PARAMETER_TYPES),
87 ('backend', constants.BES_PARAMETER_TYPES),
88 ('nic', constants.NICS_PARAMETER_TYPES),
89 ("instdisk", constants.IDISK_PARAMS_TYPES),
90 ("instnic", constants.INIC_PARAMS_TYPES),
93 self.failUnless(self.VALID_NAME.match(key),
94 "The %s parameter '%s' contains invalid characters" %
98 class TestConfdConstants(unittest.TestCase):
99 """Test the confd constants"""
101 def testFourCc(self):
102 self.failUnlessEqual(len(constants.CONFD_MAGIC_FOURCC), 4,
103 "Invalid fourcc len, should be 4")
105 def _IsUniqueSequence(self, sequence):
107 for member in sequence:
114 self.failUnless(self._IsUniqueSequence(constants.CONFD_REQS),
115 "Duplicated confd request code")
117 def testReplStatuses(self):
118 self.failUnless(self._IsUniqueSequence(constants.CONFD_REPL_STATUSES),
119 "Duplicated confd reply status code")
122 if __name__ == '__main__':
123 testutils.GanetiTestProgram()