From 7b78686ca264d4410de68769e148faec5a854fe8 Mon Sep 17 00:00:00 2001 From: Romain Ziba Date: Tue, 2 Jun 2015 15:44:08 +0200 Subject: [PATCH] Task API: Change action restart into start The method restart task was used to start a task that is stopped The term restart means that within the same action we stop and we start back the task. As a result, it's better to call this method Change-Id: Ic6b282fba1957910d64e0dcec6e5160f72435421 --- cerberus/api/v1/controllers/tasks.py | 16 +++++++-------- cerberus/common/errors.py | 12 +++++------ cerberus/manager.py | 20 +++++++++---------- cerberus/tests/functional/api/v1/test_api.py | 2 +- .../tests/functional/test_notifications.py | 2 +- cerberus/tests/unit/test_cerberus_manager.py | 16 +++++++-------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cerberus/api/v1/controllers/tasks.py b/cerberus/api/v1/controllers/tasks.py index bcd69bb..94ecbc4 100644 --- a/cerberus/api/v1/controllers/tasks.py +++ b/cerberus/api/v1/controllers/tasks.py @@ -31,7 +31,7 @@ from cerberus.openstack.common import log LOG = log.getLogger(__name__) -action_kind = ["stop", "restart", "force_delete"] +action_kind = ["stop", "start", "force_delete"] action_kind_enum = wtypes.Enum(str, *action_kind) @@ -39,7 +39,7 @@ class ActionController(base.BaseController): _custom_actions = { 'stop': ['POST'], 'force_delete': ['POST'], - 'restart': ['POST'], + 'start': ['POST'], } @wsme_pecan.wsexpose(None, wtypes.text) @@ -68,14 +68,14 @@ class ActionController(base.BaseController): raise exc.HTTPNotFound(explanation=e.value) @wsme_pecan.wsexpose(None, wtypes.text) - def restart(self, task_id): - """Restart delete task + def start(self, task_id): + """Start task :raises: - HTTPBadRequest: task not found or impossible to restart it + HTTPBadRequest: task not found or impossible to start it """ try: - self.restart_task(task_id) + self.start_task(task_id) except rpc.RemoteError as e: raise exc.HTTPBadRequest(explanation=e.value) @@ -97,11 +97,11 @@ class ActionController(base.BaseController): LOG.exception(e) raise - def restart_task(self, task_id): + def start_task(self, task_id): ctx = pecan.request.context.to_dict() try: self.client.call(ctx, - 'restart_recurrent_task', + 'start_recurrent_task', task_id=task_id) except rpc.RemoteError as e: LOG.exception(e) diff --git a/cerberus/common/errors.py b/cerberus/common/errors.py index 7462edf..80ac654 100644 --- a/cerberus/common/errors.py +++ b/cerberus/common/errors.py @@ -54,18 +54,18 @@ class TaskDeletionNotAllowed(InvalidOperation): ) -class TaskRestartNotAllowed(InvalidOperation): +class TaskStartNotAllowed(InvalidOperation): def __init__(self, _id): - super(TaskRestartNotAllowed, self).__init__( - _("Restarting task %s is not allowed because either it " + super(TaskStartNotAllowed, self).__init__( + _("Starting task %s is not allowed because either it " "does not exist or it is not recurrent") % _id ) -class TaskRestartNotPossible(InvalidOperation): +class TaskStartNotPossible(InvalidOperation): def __init__(self, _id): - super(TaskRestartNotPossible, self).__init__( - _("Restarting task %s is not possible because it is running") % _id + super(TaskStartNotPossible, self).__init__( + _("Starting task %s is not possible because it is running") % _id ) diff --git a/cerberus/manager.py b/cerberus/manager.py index 999e772..9fa0665 100644 --- a/cerberus/manager.py +++ b/cerberus/manager.py @@ -387,7 +387,7 @@ class CerberusManager(service.CerberusService): def _stop_recurrent_task(self, task_id): """Stop the recurrent task but does not remove it from the ThreadGroup. - The task still exists and could be restarted. Plus, if the task is + The task still exists and could be started. Plus, if the task is running, wait for the end of its execution :param task_id: the id of the recurrent task to stop :return: @@ -556,18 +556,18 @@ class CerberusManager(service.CerberusService): return json.dumps(task, cls=base.ThreadEncoder) - def _restart_recurrent_task(self, task_id): + def _start_recurrent_task(self, task_id): """ - Restart the task - :param task_id: the identifier of the task to restart + Start the task + :param task_id: the identifier of the task to start :return: """ recurrent_task = self._get_recurrent_task(task_id) if (recurrent_task is None): - raise errors.TaskRestartNotAllowed(str(task_id)) + raise errors.TaskStartNotAllowed(str(task_id)) period = recurrent_task.kw.get("task_period", None) if recurrent_task._running is True: - raise errors.TaskRestartNotPossible(str(task_id)) + raise errors.TaskStartNotPossible(str(task_id)) else: try: recurrent_task.start(int(period)) @@ -577,16 +577,16 @@ class CerberusManager(service.CerberusService): LOG.exception(e) raise e - def restart_recurrent_task(self, ctx, task_id): + def start_recurrent_task(self, ctx, task_id): ''' This method is designed to be called by an rpc client. E.g: Cerberus-api - Restart a recurrent task after it's being stopped + Start a recurrent task after it's being stopped :param ctx: a request context dict supplied by client - :param task_id: the identifier of the task to restart + :param task_id: the identifier of the task to start ''' try: - self._restart_recurrent_task(task_id) + self._start_recurrent_task(task_id) except errors.InvalidOperation: raise return task_id diff --git a/cerberus/tests/functional/api/v1/test_api.py b/cerberus/tests/functional/api/v1/test_api.py index fab697a..f335310 100644 --- a/cerberus/tests/functional/api/v1/test_api.py +++ b/cerberus/tests/functional/api/v1/test_api.py @@ -220,7 +220,7 @@ class TaskTestsV1(base.TestCase): # Start the task resp, body = self.security_client.post( self.security_client._version + '/tasks/' + task_id + - '/action/restart', json.dumps({}), headers=headers) + '/action/start', json.dumps({}), headers=headers) self.assertEqual(204, resp.status) resp, body = self.security_client.get( diff --git a/cerberus/tests/functional/test_notifications.py b/cerberus/tests/functional/test_notifications.py index c7d5ee1..185e08a 100644 --- a/cerberus/tests/functional/test_notifications.py +++ b/cerberus/tests/functional/test_notifications.py @@ -117,7 +117,7 @@ class NotificationTests(base.TestCase): self.assertEqual(204, resp.status) # Check if a sample has been created in Ceilometer - time.sleep(5) + time.sleep(10) resp = self.mgr.telemetry_client.list_samples( 'security.security_report.store') self.assertEqual(samples_number + 1, len(resp)) diff --git a/cerberus/tests/unit/test_cerberus_manager.py b/cerberus/tests/unit/test_cerberus_manager.py index 7e97f6c..bf331cc 100644 --- a/cerberus/tests/unit/test_cerberus_manager.py +++ b/cerberus/tests/unit/test_cerberus_manager.py @@ -419,7 +419,7 @@ class TestCerberusManager(base.TestBase): assert(recurrent_task.gt.dead is True) assert(len(self.manager.tg.timers) == 0) - def test_restart_recurrent_task(self): + def test_start_recurrent_task(self): ctxt = {'some': 'context'} db_api.update_state_task = mock.MagicMock() task_id = 1 @@ -432,7 +432,7 @@ class TestCerberusManager(base.TestBase): assert(self.manager.tg.timers[0]._running is True) self.manager._stop_recurrent_task(task_id) assert(self.manager.tg.timers[0]._running is False) - self.manager.restart_recurrent_task(ctxt, task_id) + self.manager.start_recurrent_task(ctxt, task_id) assert(self.manager.tg.timers[0]._running is True) @@ -585,7 +585,7 @@ class FaultyTestCerberusManager(base.TestBaseFaulty): assert(recurrent_task.gt.dead is False) assert(len(self.manager.tg.timers) == 1) - def test_restart_recurrent_task_wrong_id(self): + def test_start_recurrent_task_wrong_id(self): ctxt = {"some": "ctx"} db_api.update_state_task = mock.MagicMock() task_id = 1 @@ -596,13 +596,13 @@ class FaultyTestCerberusManager(base.TestBaseFaulty): assert(self.manager.tg.timers[0]._running is True) self.manager._stop_recurrent_task(task_id) assert(self.manager.tg.timers[0]._running is False) - self.assertRaises(errors.TaskRestartNotAllowed, - self.manager.restart_recurrent_task, + self.assertRaises(errors.TaskStartNotAllowed, + self.manager.start_recurrent_task, ctxt, task_id + 1) assert(self.manager.tg.timers[0]._running is False) - def test_restart_recurrent_task_running(self): + def test_start_recurrent_task_running(self): ctxt = {"some": "ctx"} task_id = 1 self.manager._add_recurrent_task( @@ -610,8 +610,8 @@ class FaultyTestCerberusManager(base.TestBaseFaulty): 5, task_id=task_id) assert(self.manager.tg.timers[0]._running is True) - self.assertRaises(errors.TaskRestartNotPossible, - self.manager.restart_recurrent_task, + self.assertRaises(errors.TaskStartNotPossible, + self.manager.start_recurrent_task, ctxt, task_id) assert(self.manager.tg.timers[0]._running is True)