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

Proposed by Igor Brovtsin
Status: Merged
Approved by: Igor Brovtsin
Approved revision: 9fdea1a4926fc1f3521467e335c5a3b14f0d7c39
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~igor-brovtsin/maas:report-bulk-action-errors
Merge into: maas:master
Diff against target: 77 lines (+16/-5)
2 files modified
src/maasserver/websockets/handlers/machine.py (+11/-5)
src/maasserver/websockets/handlers/tests/test_machine.py (+5/-0)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Approve
Review via email: mp+441297@code.launchpad.net

Commit message

Report reasons for failure for machine bulk actions

Fixes LP:2009045

Description of the change

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.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b report-bulk-action-errors lp:~igor-brovtsin/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 429cb2a54d05709dd1631c2519af7a70f6711bc2

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b report-bulk-action-errors lp:~igor-brovtsin/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 9fdea1a4926fc1f3521467e335c5a3b14f0d7c39

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b report-bulk-action-errors lp:~igor-brovtsin/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas-tester/2333/consoleText

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/websockets/handlers/machine.py b/src/maasserver/websockets/handlers/machine.py
2index 63b181f..ec02bf9 100644
3--- a/src/maasserver/websockets/handlers/machine.py
4+++ b/src/maasserver/websockets/handlers/machine.py
5@@ -4,6 +4,7 @@
6 """The machine handler for the WebSocket connection."""
7
8
9+from collections import defaultdict
10 from functools import partial
11 import logging
12 from operator import itemgetter
13@@ -1012,25 +1013,27 @@ class MachineHandler(NodeHandler):
14
15 def _bulk_action(
16 self, filter_params, action_name, extra_params
17- ) -> tuple[int, list[str]]:
18+ ) -> tuple[int, list[str], dict[list[str]]]:
19 """Find nodes that match the filter, then apply the given action to them."""
20 machines = self._filter(
21 self.get_queryset(for_list=True), None, filter_params
22 )
23 success_count = 0
24 failed_system_ids = []
25+ failure_details = defaultdict(list)
26 for machine in machines:
27 try:
28 self._action(machine, action_name, extra_params)
29 except NodeActionError as e:
30 failed_system_ids.append(machine.system_id)
31+ failure_details[str(e)].append(machine.system_id)
32 log.error(
33 f"Bulk action ({action_name}) for {machine.system_id} failed: {e}"
34 )
35 else:
36 success_count += 1
37
38- return success_count, failed_system_ids
39+ return success_count, failed_system_ids, failure_details
40
41 def _bulk_clone(self, source, filter_params, extra_params):
42 """Bulk clone - special case of bulk_action."""
43@@ -1054,12 +1057,15 @@ class MachineHandler(NodeHandler):
44 self.get_object(params), params["filter"], extra_params
45 )
46 if "filter" in params:
47- success_count, failed_system_ids = self._bulk_action(
48- params["filter"], action_name, extra_params
49- )
50+ (
51+ success_count,
52+ failed_system_ids,
53+ failure_details,
54+ ) = self._bulk_action(params["filter"], action_name, extra_params)
55 return {
56 "success_count": success_count,
57 "failed_system_ids": failed_system_ids,
58+ "failure_details": failure_details,
59 }
60 obj = self.get_object(params)
61 return self._action(obj, action_name, extra_params)
62diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
63index 6b86917..b3d2327 100644
64--- a/src/maasserver/websockets/handlers/tests/test_machine.py
65+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
66@@ -6071,6 +6071,11 @@ class TestMachineHandlerNewSchema(MAASServerTestCase):
67 {
68 "success_count": 2,
69 "failed_system_ids": [deployed_zone1_machine.system_id],
70+ "failure_details": {
71+ "acquire action is not available for this node.": [
72+ deployed_zone1_machine.system_id
73+ ]
74+ },
75 },
76 )
77 self.assertIn(

Subscribers

People subscribed via source and target branches