Merge ~caleb-ellis/maas:name-in-notification into maas:master

Proposed by Caleb Ellis
Status: Merged
Approved by: Caleb Ellis
Approved revision: b4b6a4104f7f7dd7870bbc94375773adc09be3b4
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~caleb-ellis/maas:name-in-notification
Merge into: maas:master
Diff against target: 196 lines (+87/-30)
2 files modified
src/maasserver/static/js/angular/directives/machines_table.js (+56/-26)
src/maasserver/static/js/angular/directives/tests/test_machines_table.js (+31/-4)
Reviewer Review Type Date Requested Status
Martin Storey (community) Approve
Steve Rydz (community) Approve
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+364453@code.launchpad.net

Commit message

Add machine hostname to error notifications in machine list

Description of the change

## Done
- Added machine hostname to error notifications. Note that in some cases where the api returns the hostname already, the name will be mentioned twice.

## Screenshot
https://user-images.githubusercontent.com/25733845/54378083-696bb200-467e-11e9-8a9c-fd17650bc9a3.png

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

UNIT TESTS
-b name-in-notification lp:~caleb-ellis/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: b4b6a4104f7f7dd7870bbc94375773adc09be3b4

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

lgtm, +1

review: Approve
Revision history for this message
Steve Rydz (steverydz) wrote :

lgtm +1

review: Approve
Revision history for this message
Martin Storey (cassiocassio) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/static/js/angular/directives/machines_table.js b/src/maasserver/static/js/angular/directives/machines_table.js
2index e1c0d8d..2d38442 100644
3--- a/src/maasserver/static/js/angular/directives/machines_table.js
4+++ b/src/maasserver/static/js/angular/directives/machines_table.js
5@@ -53,27 +53,6 @@ angular.module('MAAS').directive('maasMachinesTable', [
6 21 // testing
7 ];
8
9- const actionMap = new Map([
10- ["abort", "abort action in progress"],
11- ["acquire", "acquire machine"],
12- ["check", "check machine's power state"],
13- ["commission", "commission machine"],
14- ["deploy", "deploy machine"],
15- ["exit-rescue-mode", "exit rescue mode"],
16- ["lock", "lock machine"],
17- ["mark-broken", "mark machine as broken"],
18- ["mark-fixed", "mark machine as fixed"],
19- ["off", "power machine off"],
20- ["on", "power machine on"],
21- ["override-failed-testing", "override failed testing"],
22- ["release", "release machine"],
23- ["rescue-mode", "enter rescue mode"],
24- ["set-pool", "set machine's pool"],
25- ["set-zone", "set machine's zone"],
26- ["test", "test machine"],
27- ["unlock", "unlock machine"],
28- ]);
29-
30 // Scope variables.
31 scope.table = {
32 column: 'fqdn',
33@@ -99,6 +78,55 @@ angular.module('MAAS').directive('maasMachinesTable', [
34 ];
35 scope.openMenu = "";
36
37+ scope.getActionSentence = (action, machine) => {
38+ let name = "machine";
39+ if (machine && machine.hostname) {
40+ name = machine.hostname;
41+ }
42+ switch (action) {
43+ case "abort":
44+ return `abort current action of ${name}`;
45+ case "acquire":
46+ return `acquire ${name}`;
47+ case "check":
48+ return `check power state of ${name}`;
49+ case "commission":
50+ return `commission ${name}`;
51+ case "deploy":
52+ return `deploy ${name}`;
53+ case "exit-rescue-mode":
54+ return `exit rescue mode of ${name}`;
55+ case "lock":
56+ return `lock ${name}`;
57+ case "mark-broken":
58+ return `mark ${name} as broken`;
59+ case "mark-fixed":
60+ return `mark ${name} as fixed`;
61+ case "off":
62+ return `power off ${name}`;
63+ case "on":
64+ return `power on ${name}`;
65+ case "override-failed-testing":
66+ return `override failed testing of ${name}`;
67+ case "release":
68+ return `release ${name}`;
69+ case "rescue-mode":
70+ return `enter rescue mode of ${name}`;
71+ case "release":
72+ return `release ${name}`;
73+ case "set-pool":
74+ return `set pool of ${name}`;
75+ case "set-zone":
76+ return `set zone of ${name}`;
77+ case "test":
78+ return `test ${name}`;
79+ case "unlock":
80+ return `unlock ${name}`;
81+ default:
82+ return "perform action";
83+ }
84+ };
85+
86 // Ensures that the checkbox for select all is the correct value.
87 scope.updateAllChecked = function() {
88 // Not checked when the filtered machines are empty.
89@@ -346,7 +374,7 @@ angular.module('MAAS').directive('maasMachinesTable', [
90 machine.powerTransition = undefined;
91 },
92 error => {
93- scope.createErrorNotification(action, error);
94+ scope.createErrorNotification(machine, action, error);
95 machine.action_failed = true;
96 machine.powerTransition = undefined;
97 }
98@@ -357,7 +385,7 @@ angular.module('MAAS').directive('maasMachinesTable', [
99 machine.action_failed = false;
100 },
101 error => {
102- scope.createErrorNotification(action, error);
103+ scope.createErrorNotification(machine, action, error);
104 machine.action_failed = true;
105 machine.powerTransition = undefined;
106 }
107@@ -376,7 +404,7 @@ angular.module('MAAS').directive('maasMachinesTable', [
108 MachinesManager.performAction(machine, action, extra).then(() => {
109 machine.action_failed = false;
110 }, error => {
111- scope.createErrorNotification(action, error);
112+ scope.createErrorNotification(machine, action, error);
113 machine.action_failed = true;
114 machine[`${action}-transition`] = undefined;
115 });
116@@ -404,11 +432,13 @@ angular.module('MAAS').directive('maasMachinesTable', [
117
118 scope.closeMenu = () => scope.openMenu = "";
119
120- scope.createErrorNotification = (action, error) => {
121+ scope.createErrorNotification = (machine, action, error) => {
122 const authUser = UsersManager.getAuthUser();
123 if (angular.isObject(authUser)) {
124 NotificationsManager.createItem({
125- message: `Unable to ${actionMap.get(action)}: ${error}`,
126+ message: `Unable to ${
127+ scope.getActionSentence(action, machine)
128+ }: ${error}`,
129 category: "error",
130 user: authUser.id
131 });
132diff --git a/src/maasserver/static/js/angular/directives/tests/test_machines_table.js b/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
133index f0ed447..12b273e 100644
134--- a/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
135+++ b/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
136@@ -39,6 +39,7 @@ describe("maasMachinesTable", function() {
137 function makeMachine() {
138 var machine = {
139 system_id: makeName("system_id"),
140+ hostname: makeName("name"),
141 $selected: false
142 };
143 MachinesManager._items.push(machine);
144@@ -618,9 +619,9 @@ describe("maasMachinesTable", function() {
145 scope.$digest();
146 expect(NotificationsManager.createItem)
147 .toHaveBeenCalledWith({
148- message: (
149- `Unable to check machine's power state: ${errorMsg}`
150- ),
151+ message: `Unable to check power state of ${
152+ machine.hostname
153+ }: ${errorMsg}`,
154 category: "error",
155 user: user.id
156 });
157@@ -660,7 +661,8 @@ describe("maasMachinesTable", function() {
158 scope.$digest();
159 expect(NotificationsManager.createItem)
160 .toHaveBeenCalledWith({
161- message: `Unable to power machine on: ${errorMsg}`,
162+ message:
163+ `Unable to power on ${machine.hostname}: ${errorMsg}`,
164 category: "error",
165 user: user.id
166 });
167@@ -759,4 +761,29 @@ describe("maasMachinesTable", function() {
168 expect(scope.getStatusActions(machine)).toEqual(["action2"]);
169 });
170 });
171+
172+ describe("getActionSentence", () => {
173+ it("returns generic sentence if no action param present", () => {
174+ const directive = compileDirective();
175+ const scope = directive.isolateScope();
176+
177+ expect(scope.getActionSentence()).toEqual("perform action");
178+ });
179+
180+ it("returns correctly formatted sentence without machine param", () => {
181+ const directive = compileDirective();
182+ const scope = directive.isolateScope();
183+
184+ expect(scope.getActionSentence("on")).toEqual("power on machine");
185+ });
186+
187+ it("returns correctly formatted sentence with machine param", () => {
188+ const directive = compileDirective();
189+ const scope = directive.isolateScope();
190+ const machine = makeMachine();
191+
192+ expect(scope.getActionSentence("on", machine))
193+ .toEqual(`power on ${machine.hostname}`);
194+ });
195+ });
196 });

Subscribers

People subscribed via source and target branches