← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~igor-brovtsin/maas:report-bulk-action-errors into maas:master

 

Igor Brovtsin has proposed merging ~igor-brovtsin/maas:report-bulk-action-errors into maas:master.

Commit message:
Report reasons for failure for machine bulk actions
    
Fixes LP#2009045

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~igor-brovtsin/maas/+git/maas/+merge/441297

This MP adds `failure_details` dict field to the bulk action response. Having this field, we now can show the actual failure reasons in the UI for bulk actions.
-- 
Your team MAAS Committers is subscribed to branch maas:master.
diff --git a/src/maasserver/websockets/handlers/machine.py b/src/maasserver/websockets/handlers/machine.py
index 63b181f..d150cb5 100644
--- a/src/maasserver/websockets/handlers/machine.py
+++ b/src/maasserver/websockets/handlers/machine.py
@@ -1012,25 +1012,28 @@ class MachineHandler(NodeHandler):
 
     def _bulk_action(
         self, filter_params, action_name, extra_params
-    ) -> tuple[int, list[str]]:
+    ) -> tuple[int, list[str], dict[list[str]]]:
         """Find nodes that match the filter, then apply the given action to them."""
         machines = self._filter(
             self.get_queryset(for_list=True), None, filter_params
         )
         success_count = 0
         failed_system_ids = []
+        failure_details = {}
         for machine in machines:
             try:
                 self._action(machine, action_name, extra_params)
             except NodeActionError as e:
                 failed_system_ids.append(machine.system_id)
+                failure_details.setdefault(str(e), [])
+                failure_details[str(e)].append(machine.system_id)
                 log.error(
                     f"Bulk action ({action_name}) for {machine.system_id} failed: {e}"
                 )
             else:
                 success_count += 1
 
-        return success_count, failed_system_ids
+        return success_count, failed_system_ids, failure_details
 
     def _bulk_clone(self, source, filter_params, extra_params):
         """Bulk clone - special case of bulk_action."""
@@ -1054,12 +1057,15 @@ class MachineHandler(NodeHandler):
                 self.get_object(params), params["filter"], extra_params
             )
         if "filter" in params:
-            success_count, failed_system_ids = self._bulk_action(
-                params["filter"], action_name, extra_params
-            )
+            (
+                success_count,
+                failed_system_ids,
+                failure_details,
+            ) = self._bulk_action(params["filter"], action_name, extra_params)
             return {
                 "success_count": success_count,
                 "failed_system_ids": failed_system_ids,
+                "failure_details": failure_details,
             }
         obj = self.get_object(params)
         return self._action(obj, action_name, extra_params)
diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
index 6b86917..b3d2327 100644
--- a/src/maasserver/websockets/handlers/tests/test_machine.py
+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
@@ -6071,6 +6071,11 @@ class TestMachineHandlerNewSchema(MAASServerTestCase):
             {
                 "success_count": 2,
                 "failed_system_ids": [deployed_zone1_machine.system_id],
+                "failure_details": {
+                    "acquire action is not available for this node.": [
+                        deployed_zone1_machine.system_id
+                    ]
+                },
             },
         )
         self.assertIn(

Follow ups