From 0b04b18871baaf89e8b9dade630df7915948f474 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 28 Mar 2012 15:55:21 +0200 Subject: [PATCH] constants: Don't hardcode priorities for LOCK_ATTEMPTS_TIMEOUT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 25 +++++++++++++------------ test/ganeti.mcpu_unittest.py | 5 +++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/constants.py b/lib/constants.py index 28fc3d96e..27fc6e470 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -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" diff --git a/test/ganeti.mcpu_unittest.py b/test/ganeti.mcpu_unittest.py index 20707623c..2b052e1b9 100755 --- a/test/ganeti.mcpu_unittest.py +++ b/test/ganeti.mcpu_unittest.py @@ -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) -- GitLab