diff options
| author | gongysh <gongysh@cn.ibm.com> | 2012-11-21 12:11:11 +0800 |
|---|---|---|
| committer | gongysh <gongysh@cn.ibm.com> | 2012-11-23 08:13:36 +0800 |
| commit | 68fe32580ea4f7058bb15821566fa8ff10876ec5 (patch) | |
| tree | ccab91f654f2cd48d96238c78eca5b2c12fe9692 | |
| parent | b8cc160fb76c72b922a4394de8c5e70f5e8ea7b4 (diff) | |
| download | oslo-68fe32580ea4f7058bb15821566fa8ff10876ec5.tar.gz oslo-68fe32580ea4f7058bb15821566fa8ff10876ec5.tar.xz oslo-68fe32580ea4f7058bb15821566fa8ff10876ec5.zip | |
raise_on_error parameter shouldn't be passed to task function
Modify the run_periodic_tasks() so that It has known parameters.
Task function has the only parameter 'context'
Bug #1081428
Change-Id: Ibc3da521df3dc47f8c136ade1070112fd5ea1039
| -rw-r--r-- | openstack/common/periodic_task.py | 5 | ||||
| -rw-r--r-- | tests/unit/test_periodic.py | 23 |
2 files changed, 11 insertions, 17 deletions
diff --git a/openstack/common/periodic_task.py b/openstack/common/periodic_task.py index edfee9b..8a32162 100644 --- a/openstack/common/periodic_task.py +++ b/openstack/common/periodic_task.py @@ -87,9 +87,8 @@ class _PeriodicTasksMeta(type): class PeriodicTasks(object): __metaclass__ = _PeriodicTasksMeta - def run_periodic_tasks(self, *args, **kwargs): + def run_periodic_tasks(self, context, raise_on_error=False): """Tasks to be run at a periodic interval.""" - raise_on_error = kwargs.get('raise_on_error', False) for task_name, task in self._periodic_tasks: full_task_name = '.'.join([self.__class__.__name__, task_name]) @@ -104,7 +103,7 @@ class PeriodicTasks(object): LOG.debug(_("Running periodic task %(full_task_name)s"), locals()) try: - task(self, *args, **kwargs) + task(self, context) except Exception as e: if raise_on_error: raise diff --git a/tests/unit/test_periodic.py b/tests/unit/test_periodic.py index fea83a2..c39d085 100644 --- a/tests/unit/test_periodic.py +++ b/tests/unit/test_periodic.py @@ -29,22 +29,17 @@ class AService(periodic_task.PeriodicTasks): self.called = {} @periodic_task.periodic_task - def doit(self, *args, **kwargs): + def doit(self, context): self.called['doit'] = True @periodic_task.periodic_task - def crashit(self, *args, **kwargs): + def crashit(self, context): + self.called['urg'] = True raise Exception('urg') - @periodic_task.periodic_task - def doit_with_kwargs(self, *args, **kwargs): - for n, v in kwargs.iteritems(): - self.called[n] = v - @periodic_task.periodic_task(ticks_between_runs=1) - def doit_with_kwargs_odd(self, *args, **kwargs): - for n, v in kwargs.iteritems(): - self.called[n] = v + def doit_with_kwargs_odd(self, context): + self.called['ticks'] = True class PeriodicTasksTestCase(utils.BaseTestCase): @@ -52,14 +47,14 @@ class PeriodicTasksTestCase(utils.BaseTestCase): def test_is_called(self): serv = AService() - serv.run_periodic_tasks(this='works') + serv.run_periodic_tasks(None) self.assertTrue(serv.called['doit']) self.assertTrue(len(serv.called) == 2) def test_called_twice(self): serv = AService() - serv.run_periodic_tasks(this='works') - serv.run_periodic_tasks(that='works') + serv.run_periodic_tasks(None) + serv.run_periodic_tasks(None) # expect doit_with_kwargs to be called twice # and doit_with_kwargs_odd to be called once. self.assertTrue(len(serv.called) == 3) @@ -68,4 +63,4 @@ class PeriodicTasksTestCase(utils.BaseTestCase): serv = AService() self.assertRaises(Exception, serv.run_periodic_tasks, - raise_on_error=True) + None, raise_on_error=True) |
