From 46fcdd3aca9b4d42d93df8a05e3845e302675ef7 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 11 Mar 2015 19:05:32 +0000 Subject: [PATCH] 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 --- oslo_concurrency/lockutils.py | 16 +++++++++++++++- oslo_concurrency/tests/unit/test_lockutils.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) 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))