From 93be53dacd93421b003a7219ec3a063728c720bd Mon Sep 17 00:00:00 2001
From: Balazs Lecz <leczb@google.com>
Date: Fri, 9 Apr 2010 11:39:09 +0100
Subject: [PATCH] Add basic unittests for uid_pool

Signed-off-by: Balazs Lecz <leczb@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 Makefile.am                     |  1 +
 test/ganeti.config_unittest.py  |  1 +
 test/ganeti.uidpool_unittest.py | 73 +++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100755 test/ganeti.uidpool_unittest.py

diff --git a/Makefile.am b/Makefile.am
index d50b7c2b4..9fa696461 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -341,6 +341,7 @@ python_tests = \
 	test/ganeti.rapi.resources_unittest.py \
 	test/ganeti.serializer_unittest.py \
 	test/ganeti.ssh_unittest.py \
+	test/ganeti.uidpool_unittest.py \
 	test/ganeti.utils_unittest.py \
 	test/ganeti.workerpool_unittest.py \
 	test/docs_unittest.py \
diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py
index 25fa7eda0..a57a3b709 100755
--- a/test/ganeti.config_unittest.py
+++ b/test/ganeti.config_unittest.py
@@ -76,6 +76,7 @@ class TestConfigRunner(unittest.TestCase):
       master_netdev=constants.DEFAULT_BRIDGE,
       cluster_name="cluster.local",
       file_storage_dir="/tmp",
+      uid_pool=[],
       )
 
     master_node_config = objects.Node(name=me.name,
diff --git a/test/ganeti.uidpool_unittest.py b/test/ganeti.uidpool_unittest.py
new file mode 100755
index 000000000..638c8b250
--- /dev/null
+++ b/test/ganeti.uidpool_unittest.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+#
+
+# Copyright (C) 2010 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 0.0510-1301, USA.
+
+
+"""Script for unittesting the uidpool module"""
+
+
+import unittest
+
+from ganeti import constants
+from ganeti import uidpool
+from ganeti import errors
+
+import testutils
+
+
+class TestUidPool(testutils.GanetiTestCase):
+  """Uid-pool tests"""
+
+  def setUp(self):
+    self.old_uid_min = constants.UIDPOOL_UID_MIN
+    self.old_uid_max = constants.UIDPOOL_UID_MAX
+    constants.UIDPOOL_UID_MIN = 1
+    constants.UIDPOOL_UID_MAX = 10
+
+  def tearDown(self):
+    constants.UIDPOOL_UID_MIN = self.old_uid_min
+    constants.UIDPOOL_UID_MAX = self.old_uid_max
+
+  def testParseUidPool(self):
+    self.assertEqualValues(
+        uidpool.ParseUidPool('1-100,200,'),
+        [(1, 100), (200, 200)])
+
+  def testCheckUidPool(self):
+    # UID < UIDPOOL_UID_MIN
+    self.assertRaises(errors.OpPrereqError,
+                      uidpool.CheckUidPool,
+                      [(0, 0)])
+    # UID > UIDPOOL_UID_MAX
+    self.assertRaises(errors.OpPrereqError,
+                      uidpool.CheckUidPool,
+                      [(11, 11)])
+    # lower boundary > higher boundary
+    self.assertRaises(errors.OpPrereqError,
+                      uidpool.CheckUidPool,
+                      [(2, 1)])
+
+  def testFormatUidPool(self):
+    self.assertEqualValues(
+        uidpool.FormatUidPool([(1, 100), (200, 200)]),
+        '1-100, 200'),
+
+
+if __name__ == '__main__':
+  testutils.GanetiTestProgram()
-- 
GitLab