Skip to content

Commit 6f68e12

Browse files
committed
Fix lock path management
The way we were managing the locking mechanism was wrong, as we cannot use the set_override method for this. We can pass our lock_path to the decorator directly. Fixes #55
1 parent 4f475f3 commit 6f68e12

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

caso/manager.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
CONF.register_opts(opts)
6363
CONF.register_cli_opts(cli_opts)
6464

65-
CONF.set_override("lock_path", override_lock, group="oslo_concurrency")
66-
6765

6866
class Manager(object):
6967
def __init__(self):
@@ -73,6 +71,8 @@ def __init__(self):
7371
self.extractor_manager = caso.extract.manager.Manager()
7472
self.messenger = caso.messenger.Manager()
7573

74+
self.lock_path = CONF.lock_path
75+
7676
@property
7777
def lastrun(self):
7878
if os.path.exists(self.last_run_file):
@@ -88,10 +88,14 @@ def lastrun(self):
8888
raise
8989
return date
9090

91-
@lockutils.synchronized("caso_should_not_run_in_parallel", external=True)
9291
def run(self):
93-
records = self.extractor_manager.get_records(lastrun=self.lastrun)
94-
if not CONF.dry_run:
95-
self.messenger.push_to_all(records)
96-
with open(self.last_run_file, "w") as fd:
97-
fd.write(str(datetime.datetime.now(tz.tzutc())))
92+
@lockutils.synchronized("caso_should_not_run_in_parallel",
93+
lock_path=self.lock_path, external=True)
94+
def synchronized():
95+
records = self.extractor_manager.get_records(lastrun=self.lastrun)
96+
if not CONF.dry_run:
97+
self.messenger.push_to_all(records)
98+
with open(self.last_run_file, "w") as fd:
99+
fd.write(str(datetime.datetime.now(tz.tzutc())))
100+
101+
return synchronized()

caso/tests/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import os
1919

2020
import fixtures
21+
from oslo_concurrency import lockutils
2122
from oslo_config import cfg
23+
from oslo_config import fixture as config_fixture
2224
import six
2325
import testtools
2426

@@ -31,6 +33,8 @@ class TestCase(testtools.TestCase):
3133

3234
"""Test case base class for all unit tests."""
3335

36+
REQUIRES_LOCKING = False
37+
3438
def setUp(self):
3539
"""Run before each test method to initialize test environment."""
3640

@@ -56,6 +60,12 @@ def setUp(self):
5660

5761
self.log_fixture = self.useFixture(fixtures.FakeLogger())
5862

63+
if self.REQUIRES_LOCKING:
64+
lock_path = self.useFixture(fixtures.TempDir()).path
65+
self.fixture = self.useFixture(
66+
config_fixture.Config(lockutils.CONF))
67+
self.fixture.config(lock_path=lock_path)
68+
5969
def flags(self, **kw):
6070
"""Override flag variables for a test."""
6171
group = kw.pop('group', None)

caso/tests/test_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929

3030
class TestCasoManager(base.TestCase):
31+
32+
REQUIRES_LOCKING = True
33+
3134
def setUp(self):
3235
self.useFixture(lock_fixture.ExternalLockFixture())
3336
super(TestCasoManager, self).setUp()

etc/caso/caso-config-generator.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ wrap_width = 79
44
namespace = caso
55
namespace = caso.config
66
namespace = oslo.log
7-
namespace = oslo.concurrency

etc/caso/caso.conf.sample

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,22 +286,6 @@
286286
#port = 5000
287287

288288

289-
[oslo_concurrency]
290-
291-
#
292-
# From oslo.concurrency
293-
#
294-
295-
# Enables or disables inter-process locks. (boolean value)
296-
#disable_process_locking = false
297-
298-
# Directory to use for lock files. For security, the specified directory
299-
# should only be writable by the user running the processes that need locking.
300-
# Defaults to environment variable OSLO_LOCK_PATH. If external locks are used,
301-
# a lock path must be set. (string value)
302-
#lock_path = <None>
303-
304-
305289
[ssm]
306290

307291
#

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# process, which may cause wedges in the gate later.
44
pbr>=1.6
55
oslo.config>=2.3.0 # Apache-2.0
6-
oslo.concurrency
6+
oslo.concurrency>=3.20.0 # Apache-2.0
77
oslo.log>=1.8.0 # Apache-2.0
88
oslo.utils!=2.6.0,>=2.0.0 # Apache-2.0
99

0 commit comments

Comments
 (0)