## Revision 8c811986

b/lib/locking.py
1033 1033
```    else:
```
1034 1034
```      return False
```
1035 1035

1036
```  def owning_all(self):
```
1037
```    """Checks whether current thread owns internal lock.
```
1038

1039
```    Holding the internal lock is equivalent with holding all locks in the set
```
1040
```    (the opposite does not necessarily hold as it can not be easily
```
1041
```    determined). L{add} and L{remove} require the internal lock.
```
1042

1043
```    @rtype: boolean
```
1044

1045
```    """
```
1046
```    return self.__lock.is_owned()
```
1047

1036 1048
```  def _add_owned(self, name=None):
```
1037 1049
```    """Note the current thread owns the given lock"""
```
1038 1050
```    if name is None:
```
......
1620 1632
```    """
```
1621 1633
```    return self.__keyring[level].check_owned(names, shared=shared)
```
1622 1634

1635
```  def owning_all(self, level):
```
1636
```    """Checks whether current thread owns all locks at a certain level.
```
1637

1638
```    @see: L{LockSet.owning_all}
```
1639

1640
```    """
```
1641
```    return self.__keyring[level].owning_all()
```
1642

1623 1643
```  def _upper_owned(self, level):
```
1624 1644
```    """Check that we don't own any lock at a level greater than the given one.
```
1625 1645

b/test/ganeti.locking_unittest.py
1606 1606
```    self.assertEqual(self.ls.acquire(None), set(["one", "two", "three"]))
```
1607 1607
```    # now empty it...
```
1608 1608
```    self.ls.remove(["one", "two", "three"])
```
1609
```    self.assertFalse(self.ls._names())
```
1609 1610
```    # and adds/locks by another thread still wait
```
1610 1611
```    self._addThread(target=self._doAddSet, args=(["nine"]))
```
1611 1612
```    self._addThread(target=self._doLockSet, args=(None, 1))
```
......
1713 1714
```  def testDowngradeEverything(self):
```
1714 1715
```    self.assertEqual(self.ls.acquire(locking.ALL_SET, shared=0),
```
1715 1716
```                     set(["one", "two", "three"]))
```
1717
```    self.assertTrue(self.ls.owning_all())
```
1716 1718

1717 1719
```    # Ensure all locks are now owned in exclusive mode
```
1718 1720
```    for name in self.ls._names():
```
......
1725 1727
```    for name in self.ls._names():
```
1726 1728
```      self.assertTrue(self.ls.check_owned(name, shared=1))
```
1727 1729

1730
```    self.assertTrue(self.ls.owning_all())
```
1731

1728 1732
```  def testPriority(self):
```
1729 1733
```    def _Acquire(prev, next, name, priority, success_fn):
```
1730 1734
```      prev.wait()
```
......
1890 1894
```                      set(self.nodes))
```
1891 1895
```    self.assertEquals(self.GL.list_owned(locking.LEVEL_NODE),
```
1892 1896
```                      set(self.nodes))
```
1897
```    self.assertTrue(self.GL.owning_all(locking.LEVEL_INSTANCE))
```
1898
```    self.assertTrue(self.GL.owning_all(locking.LEVEL_NODEGROUP))
```
1899
```    self.assertTrue(self.GL.owning_all(locking.LEVEL_NODE))
```
1893 1900
```    self.GL.release(locking.LEVEL_NODE)
```
1894 1901
```    self.GL.release(locking.LEVEL_NODEGROUP)
```
1895 1902
```    self.GL.release(locking.LEVEL_INSTANCE)
```
1896 1903
```    self.GL.release(locking.LEVEL_CLUSTER)
```
1897 1904

1898 1905
```  def testAcquireWholeAndPartial(self):
```
1906
```    self.assertFalse(self.GL.owning_all(locking.LEVEL_INSTANCE))
```
1899 1907
```    self.GL.acquire(locking.LEVEL_CLUSTER, ["BGL"], shared=1)
```
1900 1908
```    self.assertEquals(self.GL.acquire(locking.LEVEL_INSTANCE, None),
```
1901 1909
```                      set(self.instances))
```
......
1905 1913
```                      set(["n2"]))
```
1906 1914
```    self.assertEquals(self.GL.list_owned(locking.LEVEL_NODE),
```
1907 1915
```                      set(["n2"]))
```
1916
```    self.assertTrue(self.GL.owning_all(locking.LEVEL_INSTANCE))
```
1917
```    self.assertFalse(self.GL.owning_all(locking.LEVEL_NODE))
```
1908 1918
```    self.GL.release(locking.LEVEL_NODE)
```
1909 1919
```    self.GL.release(locking.LEVEL_INSTANCE)
```
1910 1920
```    self.GL.release(locking.LEVEL_CLUSTER)
```

Also available in: Unified diff