File tree Expand file tree Collapse file tree 6 files changed +26
-26
lines changed
Expand file tree Collapse file tree 6 files changed +26
-26
lines changed Original file line number Diff line number Diff line change 6262CONF .register_opts (opts )
6363CONF .register_cli_opts (cli_opts )
6464
65- CONF .set_override ("lock_path" , override_lock , group = "oslo_concurrency" )
66-
6765
6866class 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 ()
Original file line number Diff line number Diff line change 1818import os
1919
2020import fixtures
21+ from oslo_concurrency import lockutils
2122from oslo_config import cfg
23+ from oslo_config import fixture as config_fixture
2224import six
2325import 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 )
Original file line number Diff line number Diff line change 2828
2929
3030class TestCasoManager (base .TestCase ):
31+
32+ REQUIRES_LOCKING = True
33+
3134 def setUp (self ):
3235 self .useFixture (lock_fixture .ExternalLockFixture ())
3336 super (TestCasoManager , self ).setUp ()
Original file line number Diff line number Diff line change @@ -4,4 +4,3 @@ wrap_width = 79
44namespace = caso
55namespace = caso.config
66namespace = oslo.log
7- namespace = oslo.concurrency
Original file line number Diff line number Diff line change 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#
Original file line number Diff line number Diff line change 33# process, which may cause wedges in the gate later.
44pbr >= 1.6
55oslo.config >= 2.3.0 # Apache-2.0
6- oslo.concurrency
6+ oslo.concurrency >= 3.20.0 # Apache-2.0
77oslo.log >= 1.8.0 # Apache-2.0
88oslo.utils != 2.6.0 ,>= 2.0.0 # Apache-2.0
99
You can’t perform that action at this time.
0 commit comments