Merge lp:~newell-jensen/maas/bulk-node-actions-messages-bug-1387968 into lp:~maas-committers/maas/trunk

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: no longer in the source branch.
Merged at revision: 3327
Proposed branch: lp:~newell-jensen/maas/bulk-node-actions-messages-bug-1387968
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 53 lines (+10/-6)
2 files modified
src/maasserver/views/nodes.py (+5/-4)
src/maasserver/views/tests/test_nodes.py (+5/-2)
To merge this branch: bzr merge lp:~newell-jensen/maas/bulk-node-actions-messages-bug-1387968
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+240217@code.launchpad.net

Commit message

This branch gives the bulk node action message(s) the correct color for the given message(s).

Description of the change

Currently, some action messages should be yellow for warnings or red for errors, but instead are blue. This branch takes the highest severity (precedence) out of all the concatenated messages and uses this color. If we were going to make it so each message was going to have its own color instead of concatenating the messages as `message_from_form_stats` currently does, we would need to have specific node information (such as hostnames), to distinguish them, instead of just the number of nodes as how it is done now. If further distinguishing is desired, this branch could potentially be modified to do that.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

No tests?

Also the commit message is a little long. I would give exactly what this does or fixes. Explaining the better way in the description.

review: Needs Fixing
Revision history for this message
Newell Jensen (newell-jensen) wrote :

No new separate test but I did update a test that was already there for the
functionality that I introduced.

On Mon, Nov 3, 2014 at 10:44 AM, Blake Rouse <email address hidden>
wrote:

> Review: Needs Fixing
>
> No tests?
>
> Also the commit message is a little long. I would give exactly what this
> does or fixes. Explaining the better way in the description.
> --
>
> https://code.launchpad.net/~newell-jensen/maas/bulk-node-actions-messages-bug-1387968/+merge/240217
> You are the owner of
> lp:~newell-jensen/maas/bulk-node-actions-messages-bug-1387968.
>

Revision history for this message
Blake Rouse (blake-rouse) wrote :

Okay. Looks good.

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Monday 03 November 2014 18:44:02 you wrote:
> Also the commit message is a little long.

There is no such thing as a commit message that is too long, we're not using
CVS. This format is fine:

"""
Short sentence describing overall change.

Longer sentence
possibly going over
multiple lines to
explain why this change
is needed.
"""

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/views/nodes.py'
2--- src/maasserver/views/nodes.py 2014-10-24 23:45:33 +0000
3+++ src/maasserver/views/nodes.py 2014-10-31 07:22:03 +0000
4@@ -146,7 +146,7 @@
5 (not_actionable, not_actionable_templates),
6 (not_permitted, not_permitted_templates)]
7 message = []
8- for number, message_templates in number_message:
9+ for index, (number, message_templates) in enumerate(number_message):
10 singular, plural = message_templates
11 if number != 0:
12 message_template = singular if number == 1 else plural
13@@ -154,7 +154,8 @@
14 # Override the action name so that only the first sentence will
15 # contain the full name of the action.
16 action_name = 'It'
17- return ' '.join(message)
18+ level = index
19+ return ' '.join(message), ('info', 'warning', 'error')[level]
20
21
22 def prefetch_nodes_listing(nodes_query):
23@@ -293,8 +294,8 @@
24 action_class = SetZoneBulkAction
25 else:
26 action_class = ACTIONS_DICT[form.cleaned_data['action']]
27- message = message_from_form_stats(action_class, *stats)
28- messages.info(self.request, message)
29+ message, level = message_from_form_stats(action_class, *stats)
30+ getattr(messages, level)(self.request, message)
31 return super(NodeListView, self).form_valid(form)
32
33 def _compose_sort_order(self):
34
35=== modified file 'src/maasserver/views/tests/test_nodes.py'
36--- src/maasserver/views/tests/test_nodes.py 2014-10-29 04:34:42 +0000
37+++ src/maasserver/views/tests/test_nodes.py 2014-10-31 07:22:03 +0000
38@@ -1827,10 +1827,13 @@
39 % Delete.display_bulk,),
40 ),
41 ]
42- for params, snippets in params_and_snippets:
43- message = message_from_form_stats(*params)
44+ # level precedence is worst-case for the concantenation of messages
45+ levels = ['error', 'info', 'error', 'error']
46+ for index, (params, snippets) in enumerate(params_and_snippets):
47+ message, level = message_from_form_stats(*params)
48 for snippet in snippets:
49 self.assertIn(snippet, message)
50+ self.assertEqual(level, levels[index])
51
52
53 class NodeEnlistmentPreseedViewTest(MAASServerTestCase):