Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
cdb08f44
Commit
cdb08f44
authored
Mar 04, 2008
by
Michael Hanselmann
Browse files
Codestyle updates for locking code
Reviewed-by: ultrotter
parent
3b7ed473
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/locking.py
View file @
cdb08f44
...
...
@@ -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
)
test/ganeti.locking_unittest.py
View file @
cdb08f44
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment