Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.locking_unittest.py @ ebfb2f46

History | View | Annotate | Download (81.7 kB)

# Date Author Comment
2f96c43c 10/18/2012 07:58 pm Michael Hanselmann

test/*.py: Replace '' with ""

There might be more, but at least replace all these low-hanging fruits.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Helga Velroyen <>

5ad68a23 04/13/2012 04:19 pm Michael Hanselmann

Merge branch 'devel-2.5'

  • devel-2.5: (29 commits)
    gnt-* {add,list,remove}-tags: Unify options
    Bump version for 2.5.0 final release
    configure.ac: Fix “too many arguments” error
    Fix extra whitespace
    Further fixes concerning drbd port release
    Fix a bug concerning TCP port release...
8d7d8b57 03/22/2012 03:03 pm Michael Hanselmann

locking: Handle spurious notifications on lock acquire

This was already a TODO since the implementation of lock priorities in
September 2010. Under certain conditions a waiting acquire can be
notified at a time when it can't actually get the lock. In this case it...

26082b7e 03/22/2012 02:50 pm Michael Hanselmann

locking: Fix lock deletion with timeout

While working on another SharedLock fix I realized timeouts on lock
deletion don't work very well if the timeout actually expires. This
patch fixes the issue and adds a new unittest.

Signed-off-by: Michael Hanselmann <>...

c6a622cf 11/30/2011 12:16 pm Michael Hanselmann

locking: Allow checking if lock is owned in certain mode

With this patch the “LockSet” and “GanetiLockManager” classes have a new
function to check if a single or a group of locks (at a certain level)
have been acquired in a specific mode. This will be used for additional...

ee2b99e3 11/15/2011 03:50 pm Michael Hanselmann

locking: Make some aliased methods public

Some methods, such as “_is_owned” and “list_owned”, have been aliased to
make them public for a while now. This patch makes the actual
implementation public.

SharedLock's “is_owned” needs to be aliased to “_is_owned” to remain...

fd7b69c0 10/31/2011 04:36 pm Michael Hanselmann

Fix wrong headers and licences

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Stephen Shirley <>

44b4eddc 07/21/2011 02:55 pm Michael Hanselmann

Make lock monitor more versatile

With this change it'll be possible to register other lock information
providers. One usecase for this are job dependencies, which can be shown
in the output of “gnt-debug locks”, too.

The lock monitor is changed to accept more than one return value from...

3dbe3ddf 05/13/2011 03:57 pm Michael Hanselmann

SharedLock: Implement downgrade from exclusive to shared mode

If a job needs to modify a resource and then wait for a result, it must
acquire the resource lock in exclusive mode. In some cases it would be
possible to only have a shared lock for waiting. Until now it was not...

83f2d5f6 05/09/2011 06:33 pm Michael Hanselmann

locking: Make parameter to condition's wait() positional

It is always used in the locking code. Unittests are updated.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Guido Trotter <>

e4e35357 03/16/2011 07:37 pm Michael Hanselmann

locking: Fix race condition in lock monitor

In some rare cases it can happen that a lock is re-created very soon
after deletion, while the old instance hasn't been destructed yet. In
such a case the code would detect a duplicate name and raise an
exception....

cfb084ae 01/21/2011 11:04 am René Nussbaumer

Rename QRFS_* to RS_*

This patch renames QRFS_* to RS_* fields so they can be used in other
places (i.e. LUs) without confusion, as this was initially meant for
query operations.

Signed-off-by: René Nussbaumer <>
Reviewed-by: Iustin Pop <>

24d16f76 01/06/2011 12:08 pm Michael Hanselmann

Convert “gnt-debug locks” to query2

Locks can now be queried using “Query(what="lock", …)” over LUXI.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

819ca990 12/06/2010 02:59 pm Guido Trotter

locking: add nodegroup lock level

This also changes masterd to initialize the ganeti's manager with the
current list of nodegroup uuids, and updates unittests

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

4badc36c 10/28/2010 05:06 pm Guido Trotter

Add test for modifiable locking levels

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

f9116d58 10/28/2010 05:06 pm Guido Trotter

GanetiLockManager, remove default values

The nodes and instances parameters to the constructor are mandatory
anyway, as a value of None will fail when creating the LockSet. Rather
than fixing this adding code lines, since we never used the default
value, let's remove them and require that the parameters are passed....

887c7aa6 09/07/2010 04:56 pm Michael Hanselmann

locking: Implement priorities in SharedLock and LockSet

For proper support of job priorities, jobs' locks need to respect
priorities. Otherwise it could happen that a job with a lower priority
could get a lock before a job with a higher priority (depending on...

c31825f7 08/27/2010 03:03 pm Michael Hanselmann

Show list of pending acquires in “gnt-debug locks”

This is accomplished by keeping a list of waiting threads instead
of just their number inside the lock-internal condition. A few
other tweaks to the output format are also made.

Signed-off-by: Michael Hanselmann <>...

73c25d35 08/24/2010 06:29 pm Michael Hanselmann

Fix race condition in locking unittest

While writing unittests for the new lock monitor, I made a small mistake and
didn't synchronize acquiring locks properly. This patch takes care of this
issue by adding additional synchronization.

Signed-off-by: Michael Hanselmann <>...

19b9ba9a 08/24/2010 05:57 pm Michael Hanselmann

Add simple lock monitor

This patch adds an initial implementation of a lock monitor, accessible
for the user through “gnt-debug locks”. It currently shows all resource
locks: BGL, nodes and instances. Config and job queue locks could be
shown too, but wouldn't be of much help. The current owner(s) and mode...

7f93570a 07/16/2010 04:56 pm Iustin Pop

Implement lock names for debugging purposes

This patch adds lock names to SharedLocks and LockSets, that can be used
later for displaying the actual locks being held/used in places where we
only have the lock, and not the entire context of the locking operation....

158206e0 06/30/2010 02:17 pm Manuel Franceschini

User assertFalse instead of assert_(not ...)

Signed-off-by: Manuel Franceschini <>
Reviewed-by: Guido Trotter <>

7f890059 06/10/2010 05:45 pm Guido Trotter

_BaseCondition: allow saving/restoring state

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

1a4e32d0 06/10/2010 05:45 pm Guido Trotter

SharedLock _acquire_restore and _release_save

If a shared lock is used inside a condition, we need to make sure that
it's reacquired in the same way as it was originally, after the wait.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

51e3bb92 01/15/2010 12:16 pm Michael Hanselmann

Fix long-standing race condition bug in locking unittest

Every once in a while we saw failures in the locking unittest, but
weren't able to determine the cause. This patch fixes it by using
threading.Event instead of plain threading.Condition to notify another...

25231ec5 11/03/2009 12:34 pm Michael Hanselmann

Ignore log messages in unittests

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

23683c26 10/13/2009 08:08 pm Michael Hanselmann

Test LockSet.acquire return value for timeout

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Guido Trotter <>

5aab242c 10/12/2009 01:46 pm Michael Hanselmann

locking.LockSet: Implement acquire timeouts

The timeout passed to LockSet.acquire() is measured over all lock acquires. If
LockSet.acquire fails to acquire all requested locks within the specified
amount of time, all locks are released again and the acquire fails....

f1501b3f 10/02/2009 06:52 pm Michael Hanselmann

Replace all xrange() with range()

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

008b92fa 10/02/2009 03:04 pm Michael Hanselmann

More locking tests race conditions fixes

There were more race conditions. By adding a notify function to
SharedLock.acquire we can prevent them.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

34cb5617 10/01/2009 07:47 pm Guido Trotter

SingleActionPipeCondition =~ s/Action/Notify/

With this patch we simplify usage on the SingleActionCondition (which
wasn't a condition at all) by making it a real condition. This way we
can just wait() on it, or notifyAll() as we would on a normal one. The...

b8140229 10/01/2009 07:46 pm Guido Trotter

testNotification: add more checking about order

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

c5fe2a67 10/01/2009 07:45 pm Guido Trotter

Abstract base condition test cases

This way they can be used to test different condition classes.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

63f2e724 10/01/2009 07:45 pm Guido Trotter

Move the "done" queue inside _ThreadedTestCase

All (ok, all but one) _ThreadedTestCase users have a done Queue, so we
move its building in the _ThreadedTestCase setUp

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

a66bd91b 10/01/2009 07:35 pm Michael Hanselmann

locking.SharedLock: Fix bug in delete function

SharedLock.__acquire_unlocked uses keyword parameters. Just passing
the timeout would set the “shared” parameter.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

5e0a6daf 10/01/2009 07:17 pm Michael Hanselmann

Rename LockSet.acquire parameter “blocking” to “timeout”

Also remove the “blocking” parameter from LockSet.remove and
GanetiLockManager.remove. There's no point in implementing timeouts on removal
unless we need them.

Signed-off-by: Michael Hanselmann <>...

2042aa94 10/01/2009 04:59 pm Michael Hanselmann

Try to fix locking unittests

Our automated test system found a few problems in the new locking
unittests. This patch should fix them, although I wasn't able to
reproduce the problem. All are race conditions.

Signed-off-by: Michael Hanselmann <>...

48dabc6a 09/30/2009 06:34 pm Michael Hanselmann

Add _PipeCondition class

_PipeCondition is a condition implemented using pipe(2) and poll(2).
It allows the implementation of timeouts without using a busy-wait loop
with time.sleep.

Unlike Python's built-in threading.Condition class and to save file
descriptors and an internal queue, it can only be used to notify...

d76167a5 09/30/2009 06:34 pm Michael Hanselmann

Add _SingleActionPipeCondition class

This class will be used as a basic block for pipe(2)-based
conditions. Upon initialization it creates a pipe and can be
notified once (hence the “single action” in the name). A
callable helper class is used to wait for notifications....

84e344d4 09/30/2009 06:33 pm Michael Hanselmann

SharedLock: implement timeouts

This patch greatly simplifies the SharedLock code and implements
timeouts for the acquire() and delete() functions. A wrapper around
Python's threading.Condition class must be used to ensure thread
safety when check whether there are any waiters left....

a143be68 11/18/2008 01:30 pm Iustin Pop

Skip another testWaitingXblocksY

The waiting sharer blocks exclusive is another not-possible to test
right now.

Sorry for missing it the first time; there are no other testWaiting...
tests.

Reviewed-by: ultrotter

e6416152 11/18/2008 11:58 am Iustin Pop

Skip the waitingExclusiveBlockSharer test

Until we have a way to properly test this, we'll skip the test.

Reviewed-by: imsnah

4607c978 11/12/2008 08:25 am Iustin Pop

Convert the locking unittests to repetition-test

Currently the locking tests are using timeouts to ensure an event will
'never happen'. However, this is suboptimal.

The patch converts all of these to instead: not wait, but sequence the
operations logically and expect that they execute as such. In case of...

d2aff862 09/11/2008 12:44 pm Guido Trotter

LockSet: forbid add() on a partially owned set

This patch bans add() on a half-acquired set. This behavior was
previously possible, but created a deadlock if someone tried to acquire
the set-lock in the meantime, and thus is now forbidden. The
testAddRemove unit test is fixed for this new behavior, and includes a...

d4803c24 09/11/2008 12:43 pm Guido Trotter

Fix LockSet._names() to work with the set-lock

If the set-lock is acquired, currently, the _names function will fail on
a double acquire of a non-recursive lock. This patch fixes the behavior,
and some lines of code added to the testAcquireSetLock test check that...

d4f6a91c 08/18/2008 03:51 pm Guido Trotter

A few more locking unit tests

A few more tests written while bug-hunting. One of them shows a real
issue, at last. :)

Reviewed-by: imsnah

90c942d1 08/18/2008 03:50 pm Guido Trotter

Add lock-all-through-GLM unit test

I was hunting for a bug in my code and thought the culprit was in the
locking library, so I added a test to check. Unfortunately turns out it
wasn't. :( Committing the test anyway, while still trying to figure out
what's wrong......

04e1bfaf 07/23/2008 05:23 pm Guido Trotter

Invert nodes/instances locking order

An implementation mistake from the original design caused nodes to be
locked before instances, rather than after. This patch inverts the level
numbering, changing also the relevant unittests and the recursive
locking function starting point....

b10b9d74 07/08/2008 07:32 pm Guido Trotter

Add a more comment lines to testLockingConstants

This is to discourage even more whoever may think that this requirement
is not really useful and can be lifted, and to at least know where it's
used before trying to break it.

Reviewed-by: imsnah

2e1d6d96 07/08/2008 07:31 pm Guido Trotter

Add a new LockSet unittest

This test checks the LockSet behaviour when an empty list is passed.
The current behaviour is expected, but since this is a corner case,
we're safer to keep it under a check, and if we need a different one
monitor that everything is as we expect it to be....

08a6c581 07/08/2008 11:41 am Guido Trotter

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....

42a999d1 07/08/2008 11:40 am Guido Trotter

Locking: add ssynchronized decorator

This patch creates a new decorator function ssynchronized in the locking
library, which takes as input a SharedLock, and synchronizes access to
the decorated functions using it. The usual SharedLock semantics apply,
so it's possible to call more than one synchronized function at the same...

dcf315e2 05/01/2008 02:15 pm Guido Trotter

locking: remove obsolete comment

Reviewed-by: iustinp

b2dabfd6 03/04/2008 07:12 pm Guido Trotter

LockSet: handle empty case

A LockSet is mostly useful when it has some locks in it. On the other hand
there are cases in which it must function even when empty. For example if a
cluster has no instances in it there's no reason why locking all of them
shouldn't work anyway. This patch adds test code for that situation and...

b5c0e9d9 03/04/2008 07:12 pm Guido Trotter

LockSet: add missing check code

This check that no operation had been performed before release() was missing in
the test code. Adding it.

Reviewed-by: imsnah

cdb08f44 03/04/2008 04:46 pm Michael Hanselmann

Codestyle updates for locking code

Reviewed-by: ultrotter

3b7ed473 03/04/2008 03:18 pm Guido Trotter

LockSet: make acquire() able to get the whole set

This new functionality makes it possible to acquire a whole set, by passing
"None" to the acquire() function as the list of elements. This will avoid new
additions to the set, and then acquire all the current elements. The list of...

3f404fc5 03/04/2008 03:17 pm Guido Trotter

LockSet: improve remove() api

Lockset's remove() function used to return a list of locks we failed to remove.
Rather than doing this we'll return a list of removed locks, so it's more
similar to how acquire() behaves. This patch also fixes the relevant unit tests....

0cc00929 03/04/2008 03:17 pm Guido Trotter

LockSet: make acquire() return the set of names

In a LockSet acquire() returned True on success. This code changes that to
return a set containing the names of the elements acquired. This is still a
true value if we acquired any lock but is slightly more useful (because if...

7ee7c0c7 03/04/2008 12:09 pm Guido Trotter

Initial GanetiLockManager implementation

Includes some locking-related constants and explanations on how the
LockManager should be used, the class itself and its test cases.

The class includes:
- a basic constructor
- functions to acquire and release lists of locks at the same level...

aaae9bc0 02/28/2008 05:06 pm Guido Trotter

LockSet implementation and unit tests

A LockSet represents locking for a set of resources of the same type. A thread
can acquire multiple resources at the same time, and release some or all of
them, but cannot acquire more resources incrementally at different times...

84152b96 02/21/2008 03:45 pm Guido Trotter

Add a few SharedLock delete() tests

- Check that even a shared acquire() fails on a deleted lock
- Check that delete() fails on a lock you share (must own it or nothing)

These are assumptions I build on in future code, so better check for them.
Currently no code change is necessary for them to be valid....

4354ab03 02/20/2008 03:47 pm Guido Trotter

SharedLock: fix a wrong unit-test helper code

The _doItDelete helper code was supposed to be used to dispatch threads that
deleted the SharedLock. It actually just acquired it exclusively. This remained
unnoticed as the helper thread is just used to test interaction, not the delete...

a95fd5d7 02/19/2008 03:50 pm Guido Trotter

Add the delete() operation to SharedLock

This new operation lets a lock be cleanly deleted. The lock will be exclusively
held before deletion, and after it pending and future acquires will raise an
exception. Other SharedLock operations are modify to deal with delete() and to...

d6646186 02/18/2008 06:58 pm Guido Trotter

Fix a couple of SharedLock docstrings

Use the actual class name rather than a spaced version of it.

Reviewed-by: iustinp

162c1c1f 02/08/2008 01:23 pm Guido Trotter

Shared Lock implementation and unit tests.

Adding a locking.py file for the ganeti locking library. Its first component is
the implementation of a non-recursive blocking shared lock complete with a
testing library.

Reviewed-by: imsnah, iustinp