diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-17 18:24:21 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-17 18:24:21 +0000 |
| commit | 9315004a3cb96c50d5a915ba67e9f9be2f02aa3e (patch) | |
| tree | 9cbbcb67cb70c65662da16b56d582e1a1ced84af /nova/utils.py | |
| parent | 460ba0416eaa66e751358cd0c4cdccc1c908f591 (diff) | |
| parent | 10e25db4befe1173af516a053ac01f0f7b6dac56 (diff) | |
Merge "Makes sure tests don't leave lockfiles around"
Diffstat (limited to 'nova/utils.py')
| -rw-r--r-- | nova/utils.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/nova/utils.py b/nova/utils.py index 180210dc8..6360f9133 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -715,14 +715,21 @@ def synchronized(name, external=False): LOG.debug(_('Attempting to grab file lock "%(lock)s" for ' 'method "%(method)s"...'), {'lock': name, 'method': f.__name__}) - lock_file_path = os.path.join(FLAGS.lock_path, - 'nova-%s' % name) + lock_path = FLAGS.lock_path or tempfile.mkdtemp() + lock_file_path = os.path.join(lock_path, 'nova-%s' % name) lock = InterProcessLock(lock_file_path) - with lock: - LOG.debug(_('Got file lock "%(lock)s" for ' - 'method "%(method)s"...'), - {'lock': name, 'method': f.__name__}) - retval = f(*args, **kwargs) + try: + with lock: + LOG.debug(_('Got file lock "%(lock)s" for ' + 'method "%(method)s"...'), + {'lock': name, 'method': f.__name__}) + retval = f(*args, **kwargs) + finally: + # 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 not FLAGS.lock_path: + shutil.rmtree(lock_path) else: retval = f(*args, **kwargs) |
