Browse Source

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
Alexander Kislitsky 2 years ago
parent
commit
e46b57befc

+ 8
- 4
nailgun/nailgun/api/v1/handlers/node.py View File

@@ -85,7 +85,8 @@ class NodeHandler(SingleHandler):
85 85
                * 202 (node is successfully scheduled for deletion)
86 86
                * 400 (data validation failed)
87 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 92
         node = self.get_object_or_404(self.single, obj_id)
@@ -93,7 +94,8 @@ class NodeHandler(SingleHandler):
93 94
 
94 95
         try:
95 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 99
             raise self.http(403, e.message)
98 100
 
99 101
         self.raise_task(task)
@@ -170,7 +172,8 @@ class NodeCollectionHandler(CollectionHandler):
170 172
                * 202 (nodes are successfully scheduled for deletion)
171 173
                * 400 (data validation failed)
172 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 178
         # TODO(pkaminski): web.py does not support parsing of array arguments
176 179
         # in the queryset so we specify the input as comma-separated list
@@ -187,7 +190,8 @@ class NodeCollectionHandler(CollectionHandler):
187 190
         # NOTE(aroma): ditto as in comments for NodeHandler's PUT method;
188 191
         try:
189 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 195
             raise self.http(403, e.message)
192 196
 
193 197
         self.raise_task(task)

+ 1
- 1
nailgun/nailgun/task/manager.py View File

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

+ 38
- 0
nailgun/nailgun/test/integration/test_node_deletion.py View File

@@ -88,6 +88,44 @@ class TestNodeDeletion(BaseIntegrationTest):
88 88
         node_query = self.db.query(Node).filter_by(cluster_id=self.cluster.id)
89 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 129
     @mock_rpc(pass_mock=True)
92 130
     def test_mclient_remove_is_false_on_node_deletion(self, mrpc):
93 131
         url = reverse(

+ 1
- 1
nailgun/nailgun/test/integration/test_task_managers.py View File

@@ -1226,7 +1226,7 @@ class TestTaskManagers(BaseIntegrationTest):
1226 1226
 
1227 1227
         self.task_manager.execute(self.env.nodes)
1228 1228
         self.assertRaisesRegexp(
1229
-            errors.DeploymentAlreadyStarted,
1229
+            errors.TaskAlreadyRunning,
1230 1230
             'Cannot perform the actions because there are running tasks',
1231 1231
             self.task_manager.execute,
1232 1232
             self.env.nodes)

Loading…
Cancel
Save