Commit cdb08f44 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Codestyle updates for locking code

Reviewed-by: ultrotter
parent 3b7ed473
......@@ -93,13 +93,13 @@ class SharedLock:
"""
self.__lock.acquire()
try:
result = self.__is_owned(shared)
result = self.__is_owned(shared=shared)
finally:
self.__lock.release()
return result
def __wait(self,c):
def __wait(self, c):
"""Wait on the given condition, and raise an exception if the current lock
is declared deleted in the meantime.
......@@ -133,7 +133,6 @@ class SharedLock:
finally:
self.__nwait_exc -= 1
def acquire(self, blocking=1, shared=0):
"""Acquire a shared lock.
......@@ -210,8 +209,8 @@ class SharedLock:
# If there are shared holders waiting there *must* be an exclusive holder
# waiting as well; otherwise what were they waiting for?
assert (self.__nwait_shr == 0 or self.__nwait_exc > 0,
"Lock sharers waiting while no exclusive is queueing")
assert self.__nwait_shr == 0 or self.__nwait_exc > 0, \
"Lock sharers waiting while no exclusive is queueing"
# If there are no more shared holders and some exclusive holders are
# waiting let's wake one up.
......@@ -337,6 +336,7 @@ class LockSet:
"""Return a copy of the current set of elements.
Used only for debugging purposes.
"""
self.__lock.acquire(shared=1)
try:
......@@ -460,7 +460,6 @@ class LockSet:
(defaults to all the locks acquired at that level).
"""
assert self._is_owned(), "release() on lock set while not owner"
# Support passing in a single resource to release rather than many
......@@ -812,5 +811,4 @@ class GanetiLockManager:
assert self._is_owned(level) or not self._upper_owned(level), (
"Cannot remove locks at a level while not owning it or"
" owning some at a greater one")
return self.__keyring[level].remove(names, blocking)
return self.__keyring[level].remove(names, blocking=blocking)
......@@ -235,7 +235,7 @@ class TestLockSet(unittest.TestCase):
def setUp(self):
self.resources = ['one', 'two', 'three']
self.ls = locking.LockSet(self.resources)
self.ls = locking.LockSet(members=self.resources)
# helper threads use the 'done' queue to tell the master they finished.
self.done = Queue.Queue(0)
......@@ -496,7 +496,8 @@ class TestGanetiLockManager(unittest.TestCase):
def testLockNames(self):
self.assertEqual(self.GL._names(locking.LEVEL_CLUSTER), set(['BGL']))
self.assertEqual(self.GL._names(locking.LEVEL_NODE), set(self.nodes))
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE), set(self.instances))
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE),
set(self.instances))
self.assertEqual(self.GL._names(locking.LEVEL_CONFIG), set(['config']))
def testInitAndResources(self):
......@@ -518,7 +519,8 @@ class TestGanetiLockManager(unittest.TestCase):
self.GL = locking.GanetiLockManager(instances=self.instances)
self.assertEqual(self.GL._names(locking.LEVEL_CLUSTER), set(['BGL']))
self.assertEqual(self.GL._names(locking.LEVEL_NODE), set())
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE), set(self.instances))
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE),
set(self.instances))
self.assertEqual(self.GL._names(locking.LEVEL_CONFIG), set(['config']))
def testAcquireRelease(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment