constants: Don't hardcode priorities for LOCK_ATTEMPTS_TIMEOUT
authorMichael Hanselmann <hansmi@google.com>
Wed, 28 Mar 2012 13:55:21 +0000 (15:55 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 30 Mar 2012 12:02:23 +0000 (14:02 +0200)
Also include unittest for LOCK_ATTEMPTS_TIMEOUT.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

lib/constants.py
test/ganeti.mcpu_unittest.py

index 28fc3d9..27fc6e4 100644 (file)
@@ -533,18 +533,6 @@ EXPORT_MODES = frozenset([
   EXPORT_MODE_REMOTE,
   ])
 
-# Lock recalculate mode
-LOCKS_REPLACE = "replace"
-LOCKS_APPEND = "append"
-
-# Lock timeout (sum) before we should go into blocking acquire (still
-# can be reset by priority change); computed as max time (10 hours)
-# before we should actually go into blocking acquire given that we
-# start from default priority level; in seconds
-LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / 20.0
-LOCK_ATTEMPTS_MAXWAIT = 15.0
-LOCK_ATTEMPTS_MINWAIT = 1.0
-
 # instance creation modes
 INSTANCE_CREATE = "create"
 INSTANCE_IMPORT = "import"
@@ -1600,6 +1588,19 @@ OP_PRIO_SUBMIT_VALID = frozenset([
 
 OP_PRIO_DEFAULT = OP_PRIO_NORMAL
 
+# Lock recalculate mode
+LOCKS_REPLACE = "replace"
+LOCKS_APPEND = "append"
+
+# Lock timeout (sum) before we should go into blocking acquire (still
+# can be reset by priority change); computed as max time (10 hours)
+# before we should actually go into blocking acquire given that we
+# start from default priority level; in seconds
+# TODO
+LOCK_ATTEMPTS_TIMEOUT = 10 * 3600 / (OP_PRIO_DEFAULT - OP_PRIO_HIGHEST)
+LOCK_ATTEMPTS_MAXWAIT = 15.0
+LOCK_ATTEMPTS_MINWAIT = 1.0
+
 # Execution log types
 ELOG_MESSAGE = "message"
 ELOG_PROGRESS = "progress"
index 2070762..2b052e1 100755 (executable)
@@ -40,6 +40,11 @@ class TestLockAttemptTimeoutStrategy(unittest.TestCase):
     self.assert_(len(tpa) > LOCK_ATTEMPTS_TIMEOUT / LOCK_ATTEMPTS_MAXWAIT)
     self.assert_(sum(tpa) >= LOCK_ATTEMPTS_TIMEOUT)
 
+    self.assertTrue(LOCK_ATTEMPTS_TIMEOUT >= 1800,
+                    msg="Waiting less than half an hour per priority")
+    self.assertTrue(LOCK_ATTEMPTS_TIMEOUT <= 3600,
+                    msg="Waiting more than an hour per priority")
+
   def testSimple(self):
     strat = mcpu.LockAttemptTimeoutStrategy(_random_fn=lambda: 0.5,
                                             _time_fn=lambda: 0.0)