This adds support for a non-blocking behavior of the lock : the context-based
lock now raises an AcquireLockFailedException if the lock can't be acquired on
the first try.
At a higher layer, we just caught this exception inside the 'synchronized'
decorator to prevent calling the wrapped function. In which case, we then
trace this acquisition failure.
For now at least, disabling blocking is not supported when using fair locks
because the ReaderWriterLock.write_lock() provided by the fasteners module
doesn't implements this behavior.
Change-Id: I409da79007c9ba4fb8585da881e3d56998b0b98b
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.
Change-Id: I792a17f4b2667713503e6bc10cfabed9905d8535
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
There may be cases were library users want to request the removal of an
external lock that may not have been created and don't want to pollute
the logs when the file is not present.
We raise the log level from info to warning, but we don't log it if the
file didn't exist, since the end result the caller wanted is there.
Change-Id: I5ce8be34c9f2c4c59ea99dabc6760c3300f743a3
Current external lock removal unit tests are not really testing the
removal as they don't bother to check that we are calling os.remove
This patch fixes this situation by mocking the appropriate methods and
checking that they are being called (or not) as expected.
Change-Id: I25efc1638106431ee36e760c0c213a1a675ec908
There's a convenience wrapper around the lockutils.synchronized
decorator that lets oslo.concurrency consumers set up a prefix to use
for all lock files (presumably to obviate collisions with other
consumers when using jejune lock names, like 'lock'). This commit adds
an equivalent wrapper around lockutils.lock, the context manager
counterpart to the lockutils.synchronized decorator.
Note that the unit test added for lock_with_prefix is pretty bare; but
it follows the precedent set by the existing tests. Future commits
should make all these tests more thorough/robust.
Change-Id: I4e723ee3be1e57c543684390b607c84388c6e930
- Tests are based on oslotest.base.BaseTestCase, which uses the
NestedTempFile fixture, which uses the TempDir fixture, which adds a
cleanup routine to remove the base temporary directory it creates.
There's therefore no need for tests to clean up this directory, so all
the code that does that is removed.
- The eventlet incarnation of tests was trying to make use of the `env`
external without whitelisting it, resulting in an ugly red deprecation
warning. This commit adds `env` to whitelist_externals in [testenv].
- A handful of typos in the Beowulf quote are corrected.
Change-Id: I91cc52e00e0a918dadd2a3a771bd322b0f165ed2
This adds support for a "fair" variant of the lock. When there are
multiple entities within a single process that are blocked waiting
for the lock the fair lock will ensure that they acquire the lock
in FIFO order.
For now at least, when fair locks are in use we don't support
the "semaphores" argument.
If external locks are enabled, the inter-process ordering will be
determined by the underlying OS lock ordering and process scheduling.
Change-Id: I37577becff4978bf643c65fa9bc2d78d342ea35a
Some of tests use different method of
assertTrue(isinstance(A, B)) or assertEqual(type(A), B).
The correct way is to use assertIsInstance(A, B) provided
by testtools
Change-Id: Iad2ee275837c28b40c1062386db5a29969ee98dc
At the moment, those tests use fcntl to acquire file locks, which
will fail on Windows.
This change addresses this issue by adding some platform checks,
using the appropriate functions when handling file locks. Note that
we've avoided running private methods from fasteners.
Also, we now avoid using os.fork, which won't work on Windows.
Instead, we spawn new processes using multiprocessing.Process, using
queues for communication between processes.
Change-Id: I9839b9033c814280f6d1b53c5ed2643fd2bf8bf8
Many assertEqual sentences don't follow assertEqual(expected, actual),
These misplaces have 2 impacts:
1, giving confusing messages when some tests failed.
2, mislead other developers, new test modules may follow these wrong pattern.
This patch fix all of them.
Change-Id: I00bb4801c208d0eb8078e8a34ae52f9bcfe0b1a6
Closes-Bug: #1604213
The fasteners library (extracted from this library and a couple other
variations) provides the interprocess lock logic and the reader writer
lock logic so we can remove the local version and we can just use it
from that library instead.
The tests that were ensuring the internals of this file lock have
now moved to the repo where that library is (for the time being),
currently travis is testing that repo against py2.6, py2.7 and py3.4.
https://github.com/harlowja/fasteners/tree/master/fasteners/tests
Docs also exist at:
http://fasteners.readthedocs.org/en/latest/
Change-Id: I98565b22e68358efe28fea62f74f8ebfcc438ff7
Provide an API to discover the path being used to store external lock
files. Tempest will use this to set up some additional locking and to
test its own behavior. Other projects might use it for error reporting
or other purposes.
Change-Id: Iad40c67072333cc25a6d3e39d7535ff14b573504
Taskflow has a reader/writer lock that is likely useful
to other projects; and it seems better at home in this
module.
The class provides a way to create reader/writer locks
where there may be many readers at the same time (but
only one writer). It does not allow (currently) for privilege
escalation (but this could be added with limited support
in the future).
Change-Id: Ie763ef92f31c34869d83a533bc8761b0fbd77217
It can be undesirable to have a globally shared sempahore
container, especially since oslo.concurrency can now be shared
among many disjoint applications and libraries.
When a single container is used it is now possible to have those
disjoint applications/libraries collide on the same sempahore names.
This is not a good pattern to continue with, so in order to move away
from it allow a custom container to be provided (which defaults to the
existing global one) so that users of oslo.concurrency may provide there
own container if they so desire.
Change-Id: I9aab42e21ba0f52997de3e7c9b0fea51db5c7289
Move the public API out of oslo.concurrency to oslo_concurrency. Retain
the ability to import from the old namespace package for backwards
compatibility for this release cycle.
bp/drop-namespace-packages
Change-Id: I20d1647b1c3ef8cab3b69eccfe168eeb01703b72