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))