Update lockutils from oslo-incubator
This commit updates lockutils from oslo incubator which adds a LockFixture class. This also converts the tempest LockFixture to wrap the fixture from oslo. Change-Id: I4f5007109fa6ceff868c23d55d9962f9d703bb1f
This commit is contained in:
@@ -15,16 +15,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import fixtures
|
||||
|
||||
from tempest.openstack.common import lockutils
|
||||
|
||||
|
||||
class LockFixture(fixtures.Fixture):
|
||||
class LockFixture(lockutils.LockFixture):
|
||||
def __init__(self, name):
|
||||
self.mgr = lockutils.lock(name, 'tempest-', True)
|
||||
|
||||
def setUp(self):
|
||||
super(LockFixture, self).setUp()
|
||||
self.addCleanup(self.mgr.__exit__, None, None, None)
|
||||
self.mgr.__enter__()
|
||||
super(LockFixture, self).__init__(name, 'tempest-')
|
||||
|
||||
@@ -24,6 +24,7 @@ import threading
|
||||
import time
|
||||
import weakref
|
||||
|
||||
import fixtures
|
||||
from oslo.config import cfg
|
||||
|
||||
from tempest.openstack.common import fileutils
|
||||
@@ -275,3 +276,36 @@ def synchronized_with_prefix(lock_file_prefix):
|
||||
"""
|
||||
|
||||
return functools.partial(synchronized, lock_file_prefix=lock_file_prefix)
|
||||
|
||||
|
||||
class LockFixture(fixtures.Fixture):
|
||||
"""External locking fixture.
|
||||
|
||||
This fixture is basically an alternative to the synchronized decorator with
|
||||
the external flag so that tearDowns and addCleanups will be included in
|
||||
the lock context for locking between tests. The fixture is recommended to
|
||||
be the first line in a test method, like so::
|
||||
|
||||
def test_method(self):
|
||||
self.useFixture(LockFixture)
|
||||
...
|
||||
|
||||
or the first line in setUp if all the test methods in the class are
|
||||
required to be serialized. Something like::
|
||||
|
||||
class TestCase(testtools.testcase):
|
||||
def setUp(self):
|
||||
self.useFixture(LockFixture)
|
||||
super(TestCase, self).setUp()
|
||||
...
|
||||
|
||||
This is because addCleanups are put on a LIFO queue that gets run after the
|
||||
test method exits. (either by completing or raising an exception)
|
||||
"""
|
||||
def __init__(self, name, lock_file_prefix=None):
|
||||
self.mgr = lock(name, lock_file_prefix, True)
|
||||
|
||||
def setUp(self):
|
||||
super(LockFixture, self).setUp()
|
||||
self.addCleanup(self.mgr.__exit__, None, None, None)
|
||||
self.mgr.__enter__()
|
||||
|
||||
Reference in New Issue
Block a user