diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-09-07 17:17:00 +0000 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-09-07 17:17:00 +0000 |
| commit | 67f74991f73fa2c8350c434a7f67c85bf50e4934 (patch) | |
| tree | 0ce173076e1f33fe70f1b085ead4b4a69c7d47c3 | |
| parent | 37cc45b8fdaa199b248a7ef5f683d514733b8387 (diff) | |
| download | nova-67f74991f73fa2c8350c434a7f67c85bf50e4934.tar.gz nova-67f74991f73fa2c8350c434a7f67c85bf50e4934.tar.xz nova-67f74991f73fa2c8350c434a7f67c85bf50e4934.zip | |
Stop lock decorator from leaving tempdirs in tests
In some versions of python 2.7, we must use the nonlocal keyword to
give an inline function access to a variable in the enclosing scope.
This leads to a tempdir not beaing cleaned up because a boolean in
the synchronized decorator doesn't get set properly. Since we are
still supporting python 2.6, this patch removes the method call
completely so we don't have to worry about locality.
The patch also moves acquiring the lock inside the try, except to
make sure the tempdir is still cleaned even if there is some issue
with getting the lock.
Fixes bug 1047530
Change-Id: Ie3da18262e67de076b1e474c24edd2e4e5208646
| -rw-r--r-- | nova/utils.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/nova/utils.py b/nova/utils.py index 889138d89..31d62a611 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -717,14 +717,14 @@ def synchronized(name, external=False, lock_path=None): {'lock': name, 'method': f.__name__}) cleanup_dir = False - def wrap_mkdtemp(): - cleanup_dir = True - return tempfile.mkdtemp() - # We need a copy of lock_path because it is non-local local_lock_path = lock_path if not local_lock_path: - local_lock_path = FLAGS.lock_path or wrap_mkdtemp() + local_lock_path = FLAGS.lock_path + + if not local_lock_path: + cleanup_dir = True + local_lock_path = tempfile.mkdtemp() if not os.path.exists(local_lock_path): cleanup_dir = True @@ -735,8 +735,8 @@ def synchronized(name, external=False, lock_path=None): safe_name = name.replace(os.sep, '_') lock_file_path = os.path.join(local_lock_path, 'nova-%s' % safe_name) - lock = InterProcessLock(lock_file_path) try: + lock = InterProcessLock(lock_file_path) with lock: LOG.debug(_('Got file lock "%(lock)s" for ' 'method "%(method)s"...'), |
