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
diff --git a/src/maasserver/static/js/angular/directives/machines_table.js b/src/maasserver/static/js/angular/directives/machines_table.js
index e1c0d8d..2d38442 100644
--- a/src/maasserver/static/js/angular/directives/machines_table.js
+++ b/src/maasserver/static/js/angular/directives/machines_table.js
@@ -53,27 +53,6 @@ angular.module('MAAS').directive('maasMachinesTable', [
53 21 // testing53 21 // testing
54 ];54 ];
5555
56 const actionMap = new Map([
57 ["abort", "abort action in progress"],
58 ["acquire", "acquire machine"],
59 ["check", "check machine's power state"],
60 ["commission", "commission machine"],
61 ["deploy", "deploy machine"],
62 ["exit-rescue-mode", "exit rescue mode"],
63 ["lock", "lock machine"],
64 ["mark-broken", "mark machine as broken"],
65 ["mark-fixed", "mark machine as fixed"],
66 ["off", "power machine off"],
67 ["on", "power machine on"],
68 ["override-failed-testing", "override failed testing"],
69 ["release", "release machine"],
70 ["rescue-mode", "enter rescue mode"],
71 ["set-pool", "set machine's pool"],
72 ["set-zone", "set machine's zone"],
73 ["test", "test machine"],
74 ["unlock", "unlock machine"],
75 ]);
76
77 // Scope variables.56 // Scope variables.
78 scope.table = {57 scope.table = {
79 column: 'fqdn',58 column: 'fqdn',
@@ -99,6 +78,55 @@ angular.module('MAAS').directive('maasMachinesTable', [
99 ];78 ];
100 scope.openMenu = "";79 scope.openMenu = "";
10180
81 scope.getActionSentence = (action, machine) => {
82 let name = "machine";
83 if (machine && machine.hostname) {
84 name = machine.hostname;
85 }
86 switch (action) {
87 case "abort":
88 return `abort current action of ${name}`;
89 case "acquire":
90 return `acquire ${name}`;
91 case "check":
92 return `check power state of ${name}`;
93 case "commission":
94 return `commission ${name}`;
95 case "deploy":
96 return `deploy ${name}`;
97 case "exit-rescue-mode":
98 return `exit rescue mode of ${name}`;
99 case "lock":
100 return `lock ${name}`;
101 case "mark-broken":
102 return `mark ${name} as broken`;
103 case "mark-fixed":
104 return `mark ${name} as fixed`;
105 case "off":
106 return `power off ${name}`;
107 case "on":
108 return `power on ${name}`;
109 case "override-failed-testing":
110 return `override failed testing of ${name}`;
111 case "release":
112 return `release ${name}`;
113 case "rescue-mode":
114 return `enter rescue mode of ${name}`;
115 case "release":
116 return `release ${name}`;
117 case "set-pool":
118 return `set pool of ${name}`;
119 case "set-zone":
120 return `set zone of ${name}`;
121 case "test":
122 return `test ${name}`;
123 case "unlock":
124 return `unlock ${name}`;
125 default:
126 return "perform action";
127 }
128 };
129
102 // Ensures that the checkbox for select all is the correct value.130 // Ensures that the checkbox for select all is the correct value.
103 scope.updateAllChecked = function() {131 scope.updateAllChecked = function() {
104 // Not checked when the filtered machines are empty.132 // Not checked when the filtered machines are empty.
@@ -346,7 +374,7 @@ angular.module('MAAS').directive('maasMachinesTable', [
346 machine.powerTransition = undefined;374 machine.powerTransition = undefined;
347 },375 },
348 error => {376 error => {
349 scope.createErrorNotification(action, error);377 scope.createErrorNotification(machine, action, error);
350 machine.action_failed = true;378 machine.action_failed = true;
351 machine.powerTransition = undefined;379 machine.powerTransition = undefined;
352 }380 }
@@ -357,7 +385,7 @@ angular.module('MAAS').directive('maasMachinesTable', [
357 machine.action_failed = false;385 machine.action_failed = false;
358 },386 },
359 error => {387 error => {
360 scope.createErrorNotification(action, error);388 scope.createErrorNotification(machine, action, error);
361 machine.action_failed = true;389 machine.action_failed = true;
362 machine.powerTransition = undefined;390 machine.powerTransition = undefined;
363 }391 }
@@ -376,7 +404,7 @@ angular.module('MAAS').directive('maasMachinesTable', [
376 MachinesManager.performAction(machine, action, extra).then(() => {404 MachinesManager.performAction(machine, action, extra).then(() => {
377 machine.action_failed = false;405 machine.action_failed = false;
378 }, error => {406 }, error => {
379 scope.createErrorNotification(action, error);407 scope.createErrorNotification(machine, action, error);
380 machine.action_failed = true;408 machine.action_failed = true;
381 machine[`${action}-transition`] = undefined;409 machine[`${action}-transition`] = undefined;
382 });410 });
@@ -404,11 +432,13 @@ angular.module('MAAS').directive('maasMachinesTable', [
404432
405 scope.closeMenu = () => scope.openMenu = "";433 scope.closeMenu = () => scope.openMenu = "";
406434
407 scope.createErrorNotification = (action, error) => {435 scope.createErrorNotification = (machine, action, error) => {
408 const authUser = UsersManager.getAuthUser();436 const authUser = UsersManager.getAuthUser();
409 if (angular.isObject(authUser)) {437 if (angular.isObject(authUser)) {
410 NotificationsManager.createItem({438 NotificationsManager.createItem({
411 message: `Unable to ${actionMap.get(action)}: ${error}`,439 message: `Unable to ${
440 scope.getActionSentence(action, machine)
441 }: ${error}`,
412 category: "error",442 category: "error",
413 user: authUser.id443 user: authUser.id
414 });444 });
diff --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
index f0ed447..12b273e 100644
--- a/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
+++ b/src/maasserver/static/js/angular/directives/tests/test_machines_table.js
@@ -39,6 +39,7 @@ describe("maasMachinesTable", function() {
39 function makeMachine() {39 function makeMachine() {
40 var machine = {40 var machine = {
41 system_id: makeName("system_id"),41 system_id: makeName("system_id"),
42 hostname: makeName("name"),
42 $selected: false43 $selected: false
43 };44 };
44 MachinesManager._items.push(machine);45 MachinesManager._items.push(machine);
@@ -618,9 +619,9 @@ describe("maasMachinesTable", function() {
618 scope.$digest();619 scope.$digest();
619 expect(NotificationsManager.createItem)620 expect(NotificationsManager.createItem)
620 .toHaveBeenCalledWith({621 .toHaveBeenCalledWith({
621 message: (622 message: `Unable to check power state of ${
622 `Unable to check machine's power state: ${errorMsg}`623 machine.hostname
623 ),624 }: ${errorMsg}`,
624 category: "error",625 category: "error",
625 user: user.id626 user: user.id
626 });627 });
@@ -660,7 +661,8 @@ describe("maasMachinesTable", function() {
660 scope.$digest();661 scope.$digest();
661 expect(NotificationsManager.createItem)662 expect(NotificationsManager.createItem)
662 .toHaveBeenCalledWith({663 .toHaveBeenCalledWith({
663 message: `Unable to power machine on: ${errorMsg}`,664 message:
665 `Unable to power on ${machine.hostname}: ${errorMsg}`,
664 category: "error",666 category: "error",
665 user: user.id667 user: user.id
666 });668 });
@@ -759,4 +761,29 @@ describe("maasMachinesTable", function() {
759 expect(scope.getStatusActions(machine)).toEqual(["action2"]);761 expect(scope.getStatusActions(machine)).toEqual(["action2"]);
760 });762 });
761 });763 });
764
765 describe("getActionSentence", () => {
766 it("returns generic sentence if no action param present", () => {
767 const directive = compileDirective();
768 const scope = directive.isolateScope();
769
770 expect(scope.getActionSentence()).toEqual("perform action");
771 });
772
773 it("returns correctly formatted sentence without machine param", () => {
774 const directive = compileDirective();
775 const scope = directive.isolateScope();
776
777 expect(scope.getActionSentence("on")).toEqual("power on machine");
778 });
779
780 it("returns correctly formatted sentence with machine param", () => {
781 const directive = compileDirective();
782 const scope = directive.isolateScope();
783 const machine = makeMachine();
784
785 expect(scope.getActionSentence("on", machine))
786 .toEqual(`power on ${machine.hostname}`);
787 });
788 });
762});789});

Subscribers

People subscribed via source and target branches