Message format on node(-s) deletion error changed

In case of already running task we are returning JSON instead
of plain text.

Change-Id: Ic3998b8e534b2fa67813faf033335e849abe55af
Closes-Bug: #1657350
(cherry picked from commit e46b57befc)
This commit is contained in:
Alexander Kislitsky 2017-01-26 16:11:10 +03:00 committed by Denis V. Meltsaykin
parent 11430473db
commit e6c922a82a
4 changed files with 48 additions and 6 deletions

View File

@ -91,7 +91,8 @@ class NodeHandler(SingleHandler):
* 202 (node is successfully scheduled for deletion)
* 400 (data validation failed)
* 404 (node not found in db)
* 403 (on of the controllers is in error state)
* 403 (one of the controllers is in error state or task can't
be started due to already running tasks)
"""
node = self.get_object_or_404(self.single, obj_id)
@ -99,7 +100,8 @@ class NodeHandler(SingleHandler):
try:
task = task_manager.execute([node], mclient_remove=False)
except errors.ControllerInErrorState as e:
except (errors.TaskAlreadyRunning,
errors.ControllerInErrorState) as e:
raise self.http(403, e.message)
self.raise_task(task)
@ -176,7 +178,8 @@ class NodeCollectionHandler(CollectionHandler):
* 202 (nodes are successfully scheduled for deletion)
* 400 (data validation failed)
* 404 (nodes not found in db)
* 403 (on of the controllers is in error state)
* 403 (one of the controllers is in error state or task can't
be started due to already running tasks)
"""
# TODO(pkaminski): web.py does not support parsing of array arguments
# in the queryset so we specify the input as comma-separated list
@ -193,7 +196,8 @@ class NodeCollectionHandler(CollectionHandler):
# NOTE(aroma): ditto as in comments for NodeHandler's PUT method;
try:
task = task_manager.execute(nodes, mclient_remove=False)
except errors.ControllerInErrorState as e:
except (errors.TaskAlreadyRunning,
errors.ControllerInErrorState) as e:
raise self.http(403, e.message)
self.raise_task(task)

View File

@ -1258,7 +1258,7 @@ class NodeDeletionTaskManager(BaseDeploymentTaskManager):
try:
self.check_running_task()
except errors.TaskAlreadyRunning:
raise errors.DeploymentAlreadyStarted(
raise errors.TaskAlreadyRunning(
'Cannot perform the actions because there are running tasks.'
)

View File

@ -87,6 +87,44 @@ class TestNodeDeletion(BaseIntegrationTest):
node_query = self.db.query(Node).filter_by(cluster_id=self.cluster.id)
self.assertEquals(node_query.count(), 0)
@fake_tasks(fake_rpc=False, mock_rpc=True)
def test_delete_nodes_error_message(self, _):
url = reverse('NodeCollectionHandler')
query_str = 'ids={0}'.format(','.join(map(str, self.node_ids)))
self.app.delete(
'{0}?{1}'.format(url, query_str),
headers=self.default_headers
)
resp = self.app.delete(
'{0}?{1}'.format(url, query_str),
headers=self.default_headers,
expect_errors=True
)
self.assertIn('message', resp.json_body)
self.assertEqual(403, resp.status_code)
self.assertEqual(
resp.json_body['message'],
'Cannot perform the actions because there are running tasks.'
)
@fake_tasks(fake_rpc=False, mock_rpc=True)
def test_delete_node_error_message(self, _):
self.app.delete(
reverse('NodeHandler', {'obj_id': self.node_ids[0]}),
headers=self.default_headers
)
resp = self.app.delete(
reverse('NodeHandler', {'obj_id': self.node_ids[0]}),
headers=self.default_headers,
expect_errors=True
)
self.assertIn('message', resp.json_body)
self.assertEqual(403, resp.status_code)
self.assertEqual(
resp.json_body['message'],
'Cannot perform the actions because there are running tasks.'
)
@fake_tasks(fake_rpc=False, mock_rpc=True)
def test_mclient_remove_is_false_on_node_deletion(self, mrpc):
url = reverse(

View File

@ -1249,7 +1249,7 @@ class TestTaskManagers(BaseIntegrationTest):
self.task_manager.execute(self.env.nodes)
self.assertRaisesRegexp(
errors.DeploymentAlreadyStarted,
errors.TaskAlreadyRunning,
'Cannot perform the actions because there are running tasks',
self.task_manager.execute,
self.env.nodes)