root / test / ganeti.uidpool_unittest.py @ fde0203b
History | View | Annotate | Download (2.6 kB)
1 | 93be53da | Balazs Lecz | #!/usr/bin/python
|
---|---|---|---|
2 | 93be53da | Balazs Lecz | #
|
3 | 93be53da | Balazs Lecz | |
4 | 93be53da | Balazs Lecz | # Copyright (C) 2010 Google Inc.
|
5 | 93be53da | Balazs Lecz | #
|
6 | 93be53da | Balazs Lecz | # This program is free software; you can redistribute it and/or modify
|
7 | 93be53da | Balazs Lecz | # it under the terms of the GNU General Public License as published by
|
8 | 93be53da | Balazs Lecz | # the Free Software Foundation; either version 2 of the License, or
|
9 | 93be53da | Balazs Lecz | # (at your option) any later version.
|
10 | 93be53da | Balazs Lecz | #
|
11 | 93be53da | Balazs Lecz | # This program is distributed in the hope that it will be useful, but
|
12 | 93be53da | Balazs Lecz | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 93be53da | Balazs Lecz | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 93be53da | Balazs Lecz | # General Public License for more details.
|
15 | 93be53da | Balazs Lecz | #
|
16 | 93be53da | Balazs Lecz | # You should have received a copy of the GNU General Public License
|
17 | 93be53da | Balazs Lecz | # along with this program; if not, write to the Free Software
|
18 | 93be53da | Balazs Lecz | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 93be53da | Balazs Lecz | # 0.0510-1301, USA.
|
20 | 93be53da | Balazs Lecz | |
21 | 93be53da | Balazs Lecz | |
22 | 93be53da | Balazs Lecz | """Script for unittesting the uidpool module"""
|
23 | 93be53da | Balazs Lecz | |
24 | 93be53da | Balazs Lecz | |
25 | 93be53da | Balazs Lecz | import unittest |
26 | 93be53da | Balazs Lecz | |
27 | 93be53da | Balazs Lecz | from ganeti import constants |
28 | 93be53da | Balazs Lecz | from ganeti import uidpool |
29 | 93be53da | Balazs Lecz | from ganeti import errors |
30 | 93be53da | Balazs Lecz | |
31 | 93be53da | Balazs Lecz | import testutils |
32 | 93be53da | Balazs Lecz | |
33 | 93be53da | Balazs Lecz | |
34 | 93be53da | Balazs Lecz | class TestUidPool(testutils.GanetiTestCase): |
35 | 93be53da | Balazs Lecz | """Uid-pool tests"""
|
36 | 93be53da | Balazs Lecz | |
37 | 93be53da | Balazs Lecz | def setUp(self): |
38 | 93be53da | Balazs Lecz | self.old_uid_min = constants.UIDPOOL_UID_MIN
|
39 | 93be53da | Balazs Lecz | self.old_uid_max = constants.UIDPOOL_UID_MAX
|
40 | 93be53da | Balazs Lecz | constants.UIDPOOL_UID_MIN = 1
|
41 | 93be53da | Balazs Lecz | constants.UIDPOOL_UID_MAX = 10
|
42 | 93be53da | Balazs Lecz | |
43 | 93be53da | Balazs Lecz | def tearDown(self): |
44 | 93be53da | Balazs Lecz | constants.UIDPOOL_UID_MIN = self.old_uid_min
|
45 | 93be53da | Balazs Lecz | constants.UIDPOOL_UID_MAX = self.old_uid_max
|
46 | 93be53da | Balazs Lecz | |
47 | 93be53da | Balazs Lecz | def testParseUidPool(self): |
48 | 93be53da | Balazs Lecz | self.assertEqualValues(
|
49 | 41b10cf6 | Guido Trotter | uidpool.ParseUidPool("1-100,200,"),
|
50 | 93be53da | Balazs Lecz | [(1, 100), (200, 200)]) |
51 | 41b10cf6 | Guido Trotter | self.assertEqualValues(
|
52 | 41b10cf6 | Guido Trotter | uidpool.ParseUidPool("1000:2000-2500", separator=":"), |
53 | 41b10cf6 | Guido Trotter | [(1000, 1000), (2000, 2500)]) |
54 | 41b10cf6 | Guido Trotter | self.assertEqualValues(
|
55 | 41b10cf6 | Guido Trotter | uidpool.ParseUidPool("1000\n2000-2500", separator="\n"), |
56 | 41b10cf6 | Guido Trotter | [(1000, 1000), (2000, 2500)]) |
57 | 93be53da | Balazs Lecz | |
58 | 93be53da | Balazs Lecz | def testCheckUidPool(self): |
59 | 93be53da | Balazs Lecz | # UID < UIDPOOL_UID_MIN
|
60 | 93be53da | Balazs Lecz | self.assertRaises(errors.OpPrereqError,
|
61 | 93be53da | Balazs Lecz | uidpool.CheckUidPool, |
62 | 93be53da | Balazs Lecz | [(0, 0)]) |
63 | 93be53da | Balazs Lecz | # UID > UIDPOOL_UID_MAX
|
64 | 93be53da | Balazs Lecz | self.assertRaises(errors.OpPrereqError,
|
65 | 93be53da | Balazs Lecz | uidpool.CheckUidPool, |
66 | 93be53da | Balazs Lecz | [(11, 11)]) |
67 | 93be53da | Balazs Lecz | # lower boundary > higher boundary
|
68 | 93be53da | Balazs Lecz | self.assertRaises(errors.OpPrereqError,
|
69 | 93be53da | Balazs Lecz | uidpool.CheckUidPool, |
70 | 93be53da | Balazs Lecz | [(2, 1)]) |
71 | 93be53da | Balazs Lecz | |
72 | 93be53da | Balazs Lecz | def testFormatUidPool(self): |
73 | 93be53da | Balazs Lecz | self.assertEqualValues(
|
74 | 93be53da | Balazs Lecz | uidpool.FormatUidPool([(1, 100), (200, 200)]), |
75 | 41b10cf6 | Guido Trotter | "1-100, 200")
|
76 | 41b10cf6 | Guido Trotter | self.assertEqualValues(
|
77 | 41b10cf6 | Guido Trotter | uidpool.FormatUidPool([(1, 100), (200, 200)], separator=":"), |
78 | 41b10cf6 | Guido Trotter | "1-100:200")
|
79 | 41b10cf6 | Guido Trotter | self.assertEqualValues(
|
80 | 41b10cf6 | Guido Trotter | uidpool.FormatUidPool([(1, 100), (200, 200)], separator="\n"), |
81 | 41b10cf6 | Guido Trotter | "1-100\n200")
|
82 | 93be53da | Balazs Lecz | |
83 | 93be53da | Balazs Lecz | |
84 | 93be53da | Balazs Lecz | if __name__ == '__main__': |
85 | 93be53da | Balazs Lecz | testutils.GanetiTestProgram() |