summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-07-21 01:31:22 +0000
committerGerrit Code Review <review@openstack.org>2013-07-21 01:31:22 +0000
commit58a3609e80542ab8ddfca81ab4de631b93a9c7a4 (patch)
tree5fb16f422c732d59891854f60e459df28894a271 /openstack/common
parent100a74c17c09c3a90c0f4cbc47a9de78891d6b5d (diff)
parent90b6a65545dd2d41d674dd22f00bcd6dea695239 (diff)
downloadoslo-58a3609e80542ab8ddfca81ab4de631b93a9c7a4.tar.gz
oslo-58a3609e80542ab8ddfca81ab4de631b93a9c7a4.tar.xz
oslo-58a3609e80542ab8ddfca81ab4de631b93a9c7a4.zip
Merge "Fix locking bug"
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/lockutils.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/openstack/common/lockutils.py b/openstack/common/lockutils.py
index 01f6c94..e876be1 100644
--- a/openstack/common/lockutils.py
+++ b/openstack/common/lockutils.py
@@ -20,8 +20,6 @@ import contextlib
import errno
import functools
import os
-import shutil
-import tempfile
import time
import weakref
@@ -41,8 +39,7 @@ util_opts = [
cfg.BoolOpt('disable_process_locking', default=False,
help='Whether to disable inter-process locks'),
cfg.StrOpt('lock_path',
- help=('Directory to use for lock files. Default to a '
- 'temp directory'))
+ help=('Directory to use for lock files.'))
]
@@ -177,19 +174,15 @@ def lock(name, lock_file_prefix=None, external=False, lock_path=None):
if external and not CONF.disable_process_locking:
LOG.debug(_('Attempting to grab file lock "%(lock)s"'),
{'lock': name})
- cleanup_dir = False
# We need a copy of lock_path because it is non-local
- local_lock_path = lock_path
+ local_lock_path = lock_path or CONF.lock_path
if not local_lock_path:
- local_lock_path = CONF.lock_path
-
- if not local_lock_path:
- cleanup_dir = True
- local_lock_path = tempfile.mkdtemp()
+ raise cfg.RequiredOptError('lock_path')
if not os.path.exists(local_lock_path):
fileutils.ensure_tree(local_lock_path)
+ LOG.info(_('Created lock path: %s'), local_lock_path)
def add_prefix(name, prefix):
if not prefix:
@@ -213,12 +206,6 @@ def lock(name, lock_file_prefix=None, external=False, lock_path=None):
finally:
LOG.debug(_('Released file lock "%(lock)s" at %(path)s'),
{'lock': name, 'path': lock_file_path})
- # NOTE(vish): This removes the tempdir if we needed
- # to create one. This is used to
- # cleanup the locks left behind by unit
- # tests.
- if cleanup_dir:
- shutil.rmtree(local_lock_path)
else:
yield sem