From e4335b5bd4f62dfeb1cd9e1f2e2b001e14ecb924 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 13 Oct 2009 18:34:04 +0200
Subject: [PATCH] locking.LockSet: Improve assertions

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/locking.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/locking.py b/lib/locking.py
index adc7a235e..f13d7b23f 100644
--- a/lib/locking.py
+++ b/lib/locking.py
@@ -699,6 +699,9 @@ class LockSet:
   def _del_owned(self, name=None):
     """Note the current thread owns the given lock"""
 
+    assert not (name is None and self.__lock._is_owned()), \
+           "Cannot hold internal lock when deleting owner status"
+
     if name is not None:
       self.__owners[threading.currentThread()].remove(name)
 
@@ -1212,7 +1215,9 @@ class GanetiLockManager:
     assert (not self._contains_BGL(level, names) or
             not self._upper_owned(LEVEL_CLUSTER)), (
             "Cannot release the Big Ganeti Lock while holding something"
-            " at upper levels")
+            " at upper levels (%r)" %
+            (", ".join(["%s=%r" % (LEVEL_NAMES[i], self._list_owned(i))
+                        for i in self.__keyring.keys()]), ))
 
     # Release will complain if we don't own the locks already
     return self.__keyring[level].release(names)
-- 
GitLab