summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kislitsky <akislitsky@mirantis.com>2017-01-26 16:11:10 +0300
committerAlexander Kislitsky <akislitsky@mirantis.com>2017-01-26 20:41:56 +0300
commite46b57befc0032448e12581dc64458170280d465 (patch)
treeef97066cfcd5b8fe257d8035e151b9827c22606c
parent0cabf795b5c241e1b529e15fed328a30d2e61dbf (diff)
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
Notes
Notes (review): Code-Review+1: Julia Aranovich <jkirnosova@mirantis.com> Verified+1: Fuel CI <fuel-ci-bot@mirantis.com> Code-Review+2: Aleksey Kasatkin <akasatkin@mirantis.com> Code-Review+2: Ihor Kalnytskyi <ikalnitsky@mirantis.com> Workflow+1: Ihor Kalnytskyi <ikalnitsky@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 27 Jan 2017 21:07:48 +0000 Reviewed-on: https://review.openstack.org/425684 Project: openstack/fuel-web Branch: refs/heads/master
-rw-r--r--nailgun/nailgun/api/v1/handlers/node.py12
-rw-r--r--nailgun/nailgun/task/manager.py2
-rw-r--r--nailgun/nailgun/test/integration/test_node_deletion.py38
-rw-r--r--nailgun/nailgun/test/integration/test_task_managers.py2
4 files changed, 48 insertions, 6 deletions
diff --git a/nailgun/nailgun/api/v1/handlers/node.py b/nailgun/nailgun/api/v1/handlers/node.py
index f44ecfb..eb5a9c7 100644
--- a/nailgun/nailgun/api/v1/handlers/node.py
+++ b/nailgun/nailgun/api/v1/handlers/node.py
@@ -85,7 +85,8 @@ class NodeHandler(SingleHandler):
85 * 202 (node is successfully scheduled for deletion) 85 * 202 (node is successfully scheduled for deletion)
86 * 400 (data validation failed) 86 * 400 (data validation failed)
87 * 404 (node not found in db) 87 * 404 (node not found in db)
88 * 403 (on of the controllers is in error state) 88 * 403 (one of the controllers is in error state or task can't
89 be started due to already running tasks)
89 """ 90 """
90 91
91 node = self.get_object_or_404(self.single, obj_id) 92 node = self.get_object_or_404(self.single, obj_id)
@@ -93,7 +94,8 @@ class NodeHandler(SingleHandler):
93 94
94 try: 95 try:
95 task = task_manager.execute([node], mclient_remove=False) 96 task = task_manager.execute([node], mclient_remove=False)
96 except errors.ControllerInErrorState as e: 97 except (errors.TaskAlreadyRunning,
98 errors.ControllerInErrorState) as e:
97 raise self.http(403, e.message) 99 raise self.http(403, e.message)
98 100
99 self.raise_task(task) 101 self.raise_task(task)
@@ -170,7 +172,8 @@ class NodeCollectionHandler(CollectionHandler):
170 * 202 (nodes are successfully scheduled for deletion) 172 * 202 (nodes are successfully scheduled for deletion)
171 * 400 (data validation failed) 173 * 400 (data validation failed)
172 * 404 (nodes not found in db) 174 * 404 (nodes not found in db)
173 * 403 (on of the controllers is in error state) 175 * 403 (one of the controllers is in error state or task can't
176 be started due to already running tasks)
174 """ 177 """
175 # TODO(pkaminski): web.py does not support parsing of array arguments 178 # TODO(pkaminski): web.py does not support parsing of array arguments
176 # in the queryset so we specify the input as comma-separated list 179 # in the queryset so we specify the input as comma-separated list
@@ -187,7 +190,8 @@ class NodeCollectionHandler(CollectionHandler):
187 # NOTE(aroma): ditto as in comments for NodeHandler's PUT method; 190 # NOTE(aroma): ditto as in comments for NodeHandler's PUT method;
188 try: 191 try:
189 task = task_manager.execute(nodes, mclient_remove=False) 192 task = task_manager.execute(nodes, mclient_remove=False)
190 except errors.ControllerInErrorState as e: 193 except (errors.TaskAlreadyRunning,
194 errors.ControllerInErrorState) as e:
191 raise self.http(403, e.message) 195 raise self.http(403, e.message)
192 196
193 self.raise_task(task) 197 self.raise_task(task)
diff --git a/nailgun/nailgun/task/manager.py b/nailgun/nailgun/task/manager.py
index a905be2..e1648fc 100644
--- a/nailgun/nailgun/task/manager.py
+++ b/nailgun/nailgun/task/manager.py
@@ -1253,7 +1253,7 @@ class NodeDeletionTaskManager(BaseDeploymentTaskManager):
1253 try: 1253 try:
1254 self.check_running_task() 1254 self.check_running_task()
1255 except errors.TaskAlreadyRunning: 1255 except errors.TaskAlreadyRunning:
1256 raise errors.DeploymentAlreadyStarted( 1256 raise errors.TaskAlreadyRunning(
1257 'Cannot perform the actions because there are running tasks.' 1257 'Cannot perform the actions because there are running tasks.'
1258 ) 1258 )
1259 1259
diff --git a/nailgun/nailgun/test/integration/test_node_deletion.py b/nailgun/nailgun/test/integration/test_node_deletion.py
index 23928c8..be70ac3 100644
--- a/nailgun/nailgun/test/integration/test_node_deletion.py
+++ b/nailgun/nailgun/test/integration/test_node_deletion.py
@@ -88,6 +88,44 @@ class TestNodeDeletion(BaseIntegrationTest):
88 node_query = self.db.query(Node).filter_by(cluster_id=self.cluster.id) 88 node_query = self.db.query(Node).filter_by(cluster_id=self.cluster.id)
89 self.assertEquals(node_query.count(), 0) 89 self.assertEquals(node_query.count(), 0)
90 90
91 @fake_tasks(fake_rpc=False, mock_rpc=True)
92 def test_delete_nodes_error_message(self, _):
93 url = reverse('NodeCollectionHandler')
94 query_str = 'ids={0}'.format(','.join(map(str, self.node_ids)))
95 self.app.delete(
96 '{0}?{1}'.format(url, query_str),
97 headers=self.default_headers
98 )
99 resp = self.app.delete(
100 '{0}?{1}'.format(url, query_str),
101 headers=self.default_headers,
102 expect_errors=True
103 )
104 self.assertIn('message', resp.json_body)
105 self.assertEqual(403, resp.status_code)
106 self.assertEqual(
107 resp.json_body['message'],
108 'Cannot perform the actions because there are running tasks.'
109 )
110
111 @fake_tasks(fake_rpc=False, mock_rpc=True)
112 def test_delete_node_error_message(self, _):
113 self.app.delete(
114 reverse('NodeHandler', {'obj_id': self.node_ids[0]}),
115 headers=self.default_headers
116 )
117 resp = self.app.delete(
118 reverse('NodeHandler', {'obj_id': self.node_ids[0]}),
119 headers=self.default_headers,
120 expect_errors=True
121 )
122 self.assertIn('message', resp.json_body)
123 self.assertEqual(403, resp.status_code)
124 self.assertEqual(
125 resp.json_body['message'],
126 'Cannot perform the actions because there are running tasks.'
127 )
128
91 @mock_rpc(pass_mock=True) 129 @mock_rpc(pass_mock=True)
92 def test_mclient_remove_is_false_on_node_deletion(self, mrpc): 130 def test_mclient_remove_is_false_on_node_deletion(self, mrpc):
93 url = reverse( 131 url = reverse(
diff --git a/nailgun/nailgun/test/integration/test_task_managers.py b/nailgun/nailgun/test/integration/test_task_managers.py
index c7fec16..71cddac 100644
--- a/nailgun/nailgun/test/integration/test_task_managers.py
+++ b/nailgun/nailgun/test/integration/test_task_managers.py
@@ -1226,7 +1226,7 @@ class TestTaskManagers(BaseIntegrationTest):
1226 1226
1227 self.task_manager.execute(self.env.nodes) 1227 self.task_manager.execute(self.env.nodes)
1228 self.assertRaisesRegexp( 1228 self.assertRaisesRegexp(
1229 errors.DeploymentAlreadyStarted, 1229 errors.TaskAlreadyRunning,
1230 'Cannot perform the actions because there are running tasks', 1230 'Cannot perform the actions because there are running tasks',
1231 self.task_manager.execute, 1231 self.task_manager.execute,
1232 self.env.nodes) 1232 self.env.nodes)