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
This commit is contained in:
parent
e3656e7b97
commit
46fcdd3aca
@ -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."""
|
||||
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user