135d5443e3
lockutils: included commits: 8b2b0b7 Use hacking import_exceptions for gettextutils._ 6d0a6c3 Correct invalid docstrings 12bcdb7 Remove vim header 79e6bc6 fix lockutils.lock() to make it thread-safe ace5120 Add main() to lockutils that creates temp dir for locks 537d8e2 Allow lockutils to get lock_path conf from envvar 371fa42 Move LockFixture into a fixtures module d498c42 Fix to properly log when we release a semaphore 29d387c Add LockFixture to lockutils 3e3ac0c Modify lockutils.py due to dispose of eventlet 90b6a65 Fix locking bug 27d4b41 Move synchronized body to a first-class function 15c17fb Make lock_file_prefix optional 1a2df89 Enable H302 hacking check fixture: created, included commits: 45658e2 Fix violations of H302:import only modules 12bcdb7 Remove vim header 3970d46 Fix typos in oslo 371fa42 Move LockFixture into a fixtures module f4a4855 Consolidate the use of stubs 6111131 Make openstack.common.fixture.config Py3 compliant 3906979 Add a fixture for dealing with config d332cca Add a fixture for dealing with mock patching. 1bc3ecf Start adding reusable test fixtures. Also tox.ini was corrected to let lockutils work in tests. This change is needed for work on bp: db-sync-models-with-migrations Closes-Bug: #1065531 Change-Id: I139f30b4767ff2c9d1f01ee728823859c09b3859
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
# Copyright 2011 OpenStack Foundation.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import fixtures
|
|
|
|
from neutron.openstack.common import lockutils
|
|
|
|
|
|
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 = lockutils.lock(name, lock_file_prefix, True)
|
|
|
|
def setUp(self):
|
|
super(LockFixture, self).setUp()
|
|
self.addCleanup(self.mgr.__exit__, None, None, None)
|
|
self.mgr.__enter__()
|