Do not check spacing if periodic disabled
This change allows simple enable/disable periodic and set spacing via one configuration option, like @periodics.periodic(spacing=CONF.task_interval, enabled=CONF.task_interval > 0) Change-Id: I1f00242b49c7646421390c0ff26777aba6d5b6d9 Closes-Bug: #1654035
This commit is contained in:
parent
68557fec45
commit
b8759972cb
|
@ -164,7 +164,7 @@ def periodic(spacing, run_immediately=False, enabled=True):
|
|||
:type enabled: boolean
|
||||
"""
|
||||
|
||||
if spacing <= 0:
|
||||
if spacing <= 0 and enabled:
|
||||
raise ValueError("Periodicity/spacing must be greater than"
|
||||
" zero instead of %s" % spacing)
|
||||
|
||||
|
|
|
@ -323,6 +323,19 @@ class TestPeriodics(testscenarios.TestWithScenarios, base.TestCase):
|
|||
self.assertIsNotNone(w.add(add_me))
|
||||
self.assertEqual(1, len(w))
|
||||
|
||||
def test_interval_checking(self):
|
||||
|
||||
@periodics.periodic(-0.5, enabled=False)
|
||||
def no_add_me():
|
||||
pass
|
||||
|
||||
w = periodics.PeriodicWorker([], **self.worker_kwargs)
|
||||
self.assertEqual(0, len(w))
|
||||
self.assertIsNone(w.add(no_add_me))
|
||||
self.assertEqual(0, len(w))
|
||||
|
||||
self.assertRaises(ValueError, periodics.periodic, -0.5)
|
||||
|
||||
def test_is_periodic(self):
|
||||
|
||||
@periodics.periodic(0.5, enabled=False)
|
||||
|
|
Loading…
Reference in New Issue