Commit 08a6c581 authored by Guido Trotter's avatar Guido Trotter
Browse files

Locking: remove LEVEL_CONFIG lockset

Since the ConfigWriter now handles its own locking it's not necessary to
have a specific level for the config in the Locking Manager anymore.
This patch thus removes it, and all the unittest calls that used it, or
depended on it being present.

Reviewed-by: iustinp
parent f78ede4e
......@@ -669,24 +669,19 @@ class LockSet:
# - at levels LEVEL_NODE and LEVEL_INSTANCE reside node and instance locks.
# If you need more than one node, or more than one instance, acquire them at
# the same time.
# - level LEVEL_CONFIG contains the configuration lock, which you must acquire
# before reading or changing the config file.
LEVEL_CLUSTER = 0
LEVEL_NODE = 1
LEVEL_INSTANCE = 2
LEVEL_CONFIG = 3
LEVELS = [LEVEL_CLUSTER,
LEVEL_NODE,
LEVEL_INSTANCE,
LEVEL_CONFIG]
LEVEL_INSTANCE]
# Lock levels which are modifiable
LEVELS_MOD = [LEVEL_NODE, LEVEL_INSTANCE]
# Constant for the big ganeti lock and config lock
# Constant for the big ganeti lock
BGL = 'BGL'
CONFIG = 'config'
class GanetiLockManager:
......@@ -720,7 +715,6 @@ class GanetiLockManager:
LEVEL_CLUSTER: LockSet([BGL]),
LEVEL_NODE: LockSet(nodes),
LEVEL_INSTANCE: LockSet(instances),
LEVEL_CONFIG: LockSet([CONFIG]),
}
def _names(self, level):
......
......@@ -583,7 +583,6 @@ class TestGanetiLockManager(unittest.TestCase):
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_CONFIG), set(['config']))
def testInitAndResources(self):
locking.GanetiLockManager._instance = None
......@@ -591,14 +590,12 @@ class TestGanetiLockManager(unittest.TestCase):
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.assertEqual(self.GL._names(locking.LEVEL_CONFIG), set(['config']))
locking.GanetiLockManager._instance = None
self.GL = locking.GanetiLockManager(nodes=self.nodes)
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.assertEqual(self.GL._names(locking.LEVEL_CONFIG), set(['config']))
locking.GanetiLockManager._instance = None
self.GL = locking.GanetiLockManager(instances=self.instances)
......@@ -606,7 +603,6 @@ class TestGanetiLockManager(unittest.TestCase):
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_CONFIG), set(['config']))
def testAcquireRelease(self):
self.GL.acquire(locking.LEVEL_CLUSTER, ['BGL'], shared=1)
......@@ -616,12 +612,10 @@ class TestGanetiLockManager(unittest.TestCase):
self.GL.acquire(locking.LEVEL_NODE, ['n1'])
self.assertEquals(self.GL._list_owned(locking.LEVEL_NODE), set(['n1']))
self.GL.acquire(locking.LEVEL_INSTANCE, ['i1', 'i2'])
self.GL.acquire(locking.LEVEL_CONFIG, ['config'])
self.GL.release(locking.LEVEL_INSTANCE, ['i2'])
self.assertEquals(self.GL._list_owned(locking.LEVEL_INSTANCE), set(['i1']))
self.GL.release(locking.LEVEL_NODE)
self.GL.release(locking.LEVEL_INSTANCE)
self.GL.release(locking.LEVEL_CONFIG)
self.assertRaises(errors.LockError, self.GL.acquire,
locking.LEVEL_INSTANCE, ['i5'])
self.GL.acquire(locking.LEVEL_INSTANCE, ['i3'], shared=1)
......@@ -645,9 +639,6 @@ class TestGanetiLockManager(unittest.TestCase):
self.assertRaises(AssertionError, self.GL.release,
locking.LEVEL_CLUSTER)
self.GL.release(locking.LEVEL_INSTANCE)
self.GL.acquire(locking.LEVEL_CONFIG, ['config'])
self.assertRaises(AssertionError, self.GL.release,
locking.LEVEL_CLUSTER)
def testWrongOrder(self):
self.GL.acquire(locking.LEVEL_CLUSTER, ['BGL'], shared=1)
......@@ -656,16 +647,6 @@ class TestGanetiLockManager(unittest.TestCase):
locking.LEVEL_NODE, ['n1'])
self.assertRaises(AssertionError, self.GL.acquire,
locking.LEVEL_INSTANCE, ['i2'])
self.GL.acquire(locking.LEVEL_CONFIG, ['config'])
self.assertRaises(AssertionError, self.GL.acquire,
locking.LEVEL_CONFIG, ['config'])
self.GL.release(locking.LEVEL_INSTANCE)
self.assertRaises(AssertionError, self.GL.acquire,
locking.LEVEL_NODE, ['n1'])
self.assertRaises(AssertionError, self.GL.acquire,
locking.LEVEL_INSTANCE, ['i2'])
self.assertRaises(AssertionError, self.GL.acquire,
locking.LEVEL_CONFIG, ['config'])
# Helper function to run as a thread that shared the BGL and then acquires
# some locks at another level.
......@@ -685,12 +666,10 @@ class TestGanetiLockManager(unittest.TestCase):
self.assertEqual(self.done.get(True, 1), 'DONE')
self.GL.acquire(locking.LEVEL_NODE, ['n1'])
self.GL.acquire(locking.LEVEL_INSTANCE, ['i3'])
self.GL.acquire(locking.LEVEL_CONFIG, ['config'])
Thread(target=self._doLock, args=(locking.LEVEL_INSTANCE, 'i1', 1)).start()
self.assertEqual(self.done.get(True, 1), 'DONE')
Thread(target=self._doLock, args=(locking.LEVEL_INSTANCE, 'i3', 1)).start()
self.assertRaises(Queue.Empty, self.done.get, True, 0.2)
self.GL.release(locking.LEVEL_CONFIG)
self.GL.release(locking.LEVEL_INSTANCE)
self.assertEqual(self.done.get(True, 1), 'DONE')
self.GL.acquire(locking.LEVEL_INSTANCE, ['i2'], shared=1)
......
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