summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorZhongyue Luo <zhongyue.nah@intel.com>2013-05-07 17:25:34 +0900
committerZhongyue Luo <zhongyue.nah@intel.com>2013-05-09 13:20:29 +0900
commitb873454819df6ef35b22b92445bfb8675b7ac7c1 (patch)
tree9ef97b9e93171b283e4544f672c00c2562e57186 /tests
parente523c8c591806454e0e326bbdac57508787f8d24 (diff)
downloadoslo-b873454819df6ef35b22b92445bfb8675b7ac7c1.tar.gz
oslo-b873454819df6ef35b22b92445bfb8675b7ac7c1.tar.xz
oslo-b873454819df6ef35b22b92445bfb8675b7ac7c1.zip
Added convenience APIs for lockutils
The lock_file_prefix for each project doesn't need to be configurable or frequently changed. This patch provides a convenience API which returns a partial object of the synchronized decorator to avoid passing the prefix each time locks are used. The set_defaults method is also provided to change the default value of lock_path when needed. Fixes bug #1065524 Change-Id: I7b67f0a482da4be6d53a70db5bbd22dc91bdc10c
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_lockutils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/unit/test_lockutils.py b/tests/unit/test_lockutils.py
index 1230569..c37b030 100644
--- a/tests/unit/test_lockutils.py
+++ b/tests/unit/test_lockutils.py
@@ -195,3 +195,19 @@ class LockTestCase(utils.BaseTestCase):
finally:
if os.path.exists(lock_dir):
shutil.rmtree(lock_dir, ignore_errors=True)
+
+ def test_synchronized_with_prefix(self):
+ lock_name = 'mylock'
+ lock_pfix = 'mypfix-'
+
+ foo = lockutils.synchronized_with_prefix(lock_pfix)
+
+ @foo(lock_name, external=True)
+ def bar(dirpath, pfix, name):
+ filepath = os.path.join(dirpath, '%s%s' % (pfix, name))
+ return os.path.isfile(filepath)
+
+ lock_dir = tempfile.mkdtemp()
+ self.config(lock_path=lock_dir)
+
+ self.assertTrue(bar(lock_dir, lock_pfix, lock_name))