Revision cdb08f44
b/lib/locking.py | ||
---|---|---|
93 | 93 |
""" |
94 | 94 |
self.__lock.acquire() |
95 | 95 |
try: |
96 |
result = self.__is_owned(shared) |
|
96 |
result = self.__is_owned(shared=shared)
|
|
97 | 97 |
finally: |
98 | 98 |
self.__lock.release() |
99 | 99 |
|
100 | 100 |
return result |
101 | 101 |
|
102 |
def __wait(self,c): |
|
102 |
def __wait(self, c):
|
|
103 | 103 |
"""Wait on the given condition, and raise an exception if the current lock |
104 | 104 |
is declared deleted in the meantime. |
105 | 105 |
|
... | ... | |
133 | 133 |
finally: |
134 | 134 |
self.__nwait_exc -= 1 |
135 | 135 |
|
136 |
|
|
137 | 136 |
def acquire(self, blocking=1, shared=0): |
138 | 137 |
"""Acquire a shared lock. |
139 | 138 |
|
... | ... | |
210 | 209 |
|
211 | 210 |
# If there are shared holders waiting there *must* be an exclusive holder |
212 | 211 |
# waiting as well; otherwise what were they waiting for? |
213 |
assert (self.__nwait_shr == 0 or self.__nwait_exc > 0,
|
|
214 |
"Lock sharers waiting while no exclusive is queueing")
|
|
212 |
assert self.__nwait_shr == 0 or self.__nwait_exc > 0, \
|
|
213 |
"Lock sharers waiting while no exclusive is queueing"
|
|
215 | 214 |
|
216 | 215 |
# If there are no more shared holders and some exclusive holders are |
217 | 216 |
# waiting let's wake one up. |
... | ... | |
337 | 336 |
"""Return a copy of the current set of elements. |
338 | 337 |
|
339 | 338 |
Used only for debugging purposes. |
339 |
|
|
340 | 340 |
""" |
341 | 341 |
self.__lock.acquire(shared=1) |
342 | 342 |
try: |
... | ... | |
460 | 460 |
(defaults to all the locks acquired at that level). |
461 | 461 |
|
462 | 462 |
""" |
463 |
|
|
464 | 463 |
assert self._is_owned(), "release() on lock set while not owner" |
465 | 464 |
|
466 | 465 |
# Support passing in a single resource to release rather than many |
... | ... | |
812 | 811 |
assert self._is_owned(level) or not self._upper_owned(level), ( |
813 | 812 |
"Cannot remove locks at a level while not owning it or" |
814 | 813 |
" owning some at a greater one") |
815 |
return self.__keyring[level].remove(names, blocking) |
|
816 |
|
|
814 |
return self.__keyring[level].remove(names, blocking=blocking) |
b/test/ganeti.locking_unittest.py | ||
---|---|---|
235 | 235 |
|
236 | 236 |
def setUp(self): |
237 | 237 |
self.resources = ['one', 'two', 'three'] |
238 |
self.ls = locking.LockSet(self.resources) |
|
238 |
self.ls = locking.LockSet(members=self.resources)
|
|
239 | 239 |
# helper threads use the 'done' queue to tell the master they finished. |
240 | 240 |
self.done = Queue.Queue(0) |
241 | 241 |
|
... | ... | |
496 | 496 |
def testLockNames(self): |
497 | 497 |
self.assertEqual(self.GL._names(locking.LEVEL_CLUSTER), set(['BGL'])) |
498 | 498 |
self.assertEqual(self.GL._names(locking.LEVEL_NODE), set(self.nodes)) |
499 |
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE), set(self.instances)) |
|
499 |
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE), |
|
500 |
set(self.instances)) |
|
500 | 501 |
self.assertEqual(self.GL._names(locking.LEVEL_CONFIG), set(['config'])) |
501 | 502 |
|
502 | 503 |
def testInitAndResources(self): |
... | ... | |
518 | 519 |
self.GL = locking.GanetiLockManager(instances=self.instances) |
519 | 520 |
self.assertEqual(self.GL._names(locking.LEVEL_CLUSTER), set(['BGL'])) |
520 | 521 |
self.assertEqual(self.GL._names(locking.LEVEL_NODE), set()) |
521 |
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE), set(self.instances)) |
|
522 |
self.assertEqual(self.GL._names(locking.LEVEL_INSTANCE), |
|
523 |
set(self.instances)) |
|
522 | 524 |
self.assertEqual(self.GL._names(locking.LEVEL_CONFIG), set(['config'])) |
523 | 525 |
|
524 | 526 |
def testAcquireRelease(self): |
Also available in: Unified diff