4 # Copyright (C) 2010 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 uidpool module"""
27 from ganeti import constants
28 from ganeti import uidpool
29 from ganeti import errors
34 class TestUidPool(testutils.GanetiTestCase):
38 self.old_uid_min = constants.UIDPOOL_UID_MIN
39 self.old_uid_max = constants.UIDPOOL_UID_MAX
40 constants.UIDPOOL_UID_MIN = 1
41 constants.UIDPOOL_UID_MAX = 10
44 constants.UIDPOOL_UID_MIN = self.old_uid_min
45 constants.UIDPOOL_UID_MAX = self.old_uid_max
47 def testParseUidPool(self):
48 self.assertEqualValues(
49 uidpool.ParseUidPool('1-100,200,'),
50 [(1, 100), (200, 200)])
52 def testCheckUidPool(self):
53 # UID < UIDPOOL_UID_MIN
54 self.assertRaises(errors.OpPrereqError,
57 # UID > UIDPOOL_UID_MAX
58 self.assertRaises(errors.OpPrereqError,
61 # lower boundary > higher boundary
62 self.assertRaises(errors.OpPrereqError,
66 def testFormatUidPool(self):
67 self.assertEqualValues(
68 uidpool.FormatUidPool([(1, 100), (200, 200)]),
72 if __name__ == '__main__':
73 testutils.GanetiTestProgram()