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
This commit is contained in:
Alexander Kislitsky 2017-01-26 16:11:10 +03:00
parent 0cabf795b5
commit e46b57befc
4 changed files with 48 additions and 6 deletions

View File

@ -85,7 +85,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)
@ -93,7 +94,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)
@ -170,7 +172,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
@ -187,7 +190,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

@ -1253,7 +1253,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

@ -88,6 +88,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.'
)
@mock_rpc(pass_mock=True)
def test_mclient_remove_is_false_on_node_deletion(self, mrpc):
url = reverse(

View File

@ -1226,7 +1226,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)