From 900df6cdc8a80f4ea6dd3ba3a5c5a9c9d15757f6 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 8 Oct 2010 15:57:36 +0200
Subject: [PATCH] mcpu: Raise directly in _AcquireLocks

Removes code duplication.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/mcpu.py | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lib/mcpu.py b/lib/mcpu.py
index b657378ce..0cddbc683 100644
--- a/lib/mcpu.py
+++ b/lib/mcpu.py
@@ -229,6 +229,8 @@ class Processor(object):
     @param shared: Whether the locks should be acquired in shared mode
     @type timeout: None or float
     @param timeout: Timeout for acquiring the locks
+    @raise LockAcquireTimeout: In case locks couldn't be acquired in specified
+        amount of time
 
     """
     if self._cbs:
@@ -237,6 +239,9 @@ class Processor(object):
     acquired = self.context.glm.acquire(level, names, shared=shared,
                                         timeout=timeout, priority=priority)
 
+    if acquired is None:
+      raise LockAcquireTimeout()
+
     return acquired
 
   def _ExecLU(self, lu):
@@ -306,10 +311,6 @@ class Processor(object):
 
           acquired = self._AcquireLocks(level, needed_locks, share,
                                         calc_timeout(), priority)
-
-          if acquired is None:
-            raise LockAcquireTimeout()
-
         else:
           # Adding locks
           add_locks = lu.add_locks[level]
@@ -374,11 +375,9 @@ class Processor(object):
       # Acquire the Big Ganeti Lock exclusively if this LU requires it,
       # and in a shared fashion otherwise (to prevent concurrent run with
       # an exclusive LU.
-      if self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL,
-                            not lu_class.REQ_BGL, calc_timeout(),
-                            priority) is None:
-        raise LockAcquireTimeout()
-
+      self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL,
+                          not lu_class.REQ_BGL, calc_timeout(),
+                          priority)
       try:
         lu = lu_class(self, op, self.context, self.rpc)
         lu.ExpandNames()
-- 
GitLab