Revision d4803c24

b/lib/locking.py
390 390
    Used only for debugging purposes.
391 391

  
392 392
    """
393
    self.__lock.acquire(shared=1)
393
    # If we don't already own the set-level lock acquired
394
    # we'll get it and note we need to release it later.
395
    release_lock = False
396
    if not self.__lock._is_owned():
397
      release_lock = True
398
      self.__lock.acquire(shared=1)
394 399
    try:
395 400
      result = self.__names()
396 401
    finally:
397
      self.__lock.release()
402
      if release_lock:
403
        self.__lock.release()
398 404
    return set(result)
399 405

  
400 406
  def acquire(self, names, blocking=1, shared=0):
b/test/ganeti.locking_unittest.py
393 393
  def testAcquireSetLock(self):
394 394
    # acquire the set-lock exclusively
395 395
    self.assertEquals(self.ls.acquire(None), set(['one', 'two', 'three']))
396
    self.assertEquals(self.ls._list_owned(), set(['one', 'two', 'three']))
397
    self.assertEquals(self.ls._is_owned(), True)
398
    self.assertEquals(self.ls._names(), set(['one', 'two', 'three']))
396 399
    # I can still add/remove elements...
397 400
    self.assertEquals(self.ls.remove(['two', 'three']), ['two', 'three'])
398 401
    self.assert_(self.ls.add('six'))

Also available in: Unified diff