summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2015-03-11 19:05:32 +0000
committerDoug Hellmann <doug@doughellmann.com>2015-03-11 19:51:54 +0000
commit46fcdd3aca9b4d42d93df8a05e3845e302675ef7 (patch)
treed2e5f5b777edd2f31b41d807796356b696315a32
parente3656e7b975418e8de42b08048aafda52e2d0f3a (diff)
downloadoslo-concurrency-46fcdd3aca9b4d42d93df8a05e3845e302675ef7.tar.gz
Add lockutils.get_lock_path() function
Provide an API to discover the path being used to store external lock files. Tempest will use this to set up some additional locking and to test its own behavior. Other projects might use it for error reporting or other purposes. Change-Id: Iad40c67072333cc25a6d3e39d7535ff14b573504
-rw-r--r--oslo_concurrency/lockutils.py16
-rw-r--r--oslo_concurrency/tests/unit/test_lockutils.py17
2 files changed, 32 insertions, 1 deletions
diff --git a/oslo_concurrency/lockutils.py b/oslo_concurrency/lockutils.py
index 6b514df..b2e96a2 100644
--- a/oslo_concurrency/lockutils.py
+++ b/oslo_concurrency/lockutils.py
@@ -53,8 +53,12 @@ _opts = [
]
+def _register_opts(conf):
+ conf.register_opts(_opts, group='oslo_concurrency')
+
+
CONF = cfg.CONF
-CONF.register_opts(_opts, group='oslo_concurrency')
+_register_opts(CONF)
def set_defaults(lock_path):
@@ -65,6 +69,16 @@ def set_defaults(lock_path):
cfg.set_defaults(_opts, lock_path=lock_path)
+def get_lock_path(conf):
+ """Return the path used for external file-based locks.
+
+ :param conf: Configuration object
+ :type conf: oslo_config.cfg.ConfigOpts
+ """
+ _register_opts(conf)
+ return conf.oslo_concurrency.lock_path
+
+
class _Hourglass(object):
"""A hourglass like periodic timer."""
diff --git a/oslo_concurrency/tests/unit/test_lockutils.py b/oslo_concurrency/tests/unit/test_lockutils.py
index 258592d..e163078 100644
--- a/oslo_concurrency/tests/unit/test_lockutils.py
+++ b/oslo_concurrency/tests/unit/test_lockutils.py
@@ -898,3 +898,20 @@ class TestLockFixture(test_base.BaseTestCase):
fixture = fixtures.LockFixture('test-lock')
self.useFixture(fixture)
self.lock = fixture.lock
+
+
+class TestGetLockPath(test_base.BaseTestCase):
+
+ def setUp(self):
+ super(TestGetLockPath, self).setUp()
+ self.conf = self.useFixture(config.Config(lockutils.CONF)).conf
+
+ def test_get_default(self):
+ lockutils.set_defaults(lock_path='/the/path')
+ self.assertEqual('/the/path', lockutils.get_lock_path(self.conf))
+
+ def test_get_override(self):
+ lockutils._register_opts(self.conf)
+ self.conf.set_override('lock_path', '/alternate/path',
+ group='oslo_concurrency')
+ self.assertEqual('/alternate/path', lockutils.get_lock_path(self.conf))