Merge lp:~blake-rouse/maas/fix-1600198 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5165
Proposed branch: lp:~blake-rouse/maas/fix-1600198
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 238 lines (+150/-15)
3 files modified
src/maasserver/static/js/angular/controllers/node_details_storage.js (+35/-8)
src/maasserver/static/js/angular/controllers/tests/test_node_details_storage.js (+112/-5)
src/maasserver/static/partials/node-details.html (+3/-2)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1600198
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+299567@code.launchpad.net

Commit message

Prevent bcache creation on devices with partitions. Inform the user in the tooltip why bcache creation is disabled.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

The branch overall looks good to me, but I was hoping we can discuss this.

Wouldn't it be better to either:

1. Tell the user that they cannot create a Bcache because there's no partition?
2. Create the partition as part as the bcache creation (I think we did this for LVM, and if we do, we should do the same for Bcache.).

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

I updated the branch to tell the user why bcache creation is disabled.

Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/static/js/angular/controllers/node_details_storage.js'
2--- src/maasserver/static/js/angular/controllers/node_details_storage.js 2016-05-25 15:18:57 +0000
3+++ src/maasserver/static/js/angular/controllers/node_details_storage.js 2016-07-11 13:56:16 +0000
4@@ -1415,20 +1415,47 @@
5 $scope.available.splice(idx, 1);
6 };
7
8+ // Return the reason a bcache device cannot be created.
9+ $scope.getCannotCreateBcacheMsg = function() {
10+ if($scope.cachesets.length === 0) {
11+ return "Create at least one cache set to create bcache";
12+ } else {
13+ var selected = $scope.getSelectedAvailable();
14+ if(selected.length === 1) {
15+ if($scope.hasUnmountedFilesystem(selected[0])) {
16+ return (
17+ "Device is formatted; unformat the " +
18+ "device to create bcache");
19+ } else if(selected[0].type === "lvm-vg") {
20+ return (
21+ "Cannot use a logical volume as a backing " +
22+ "device for bcache.");
23+ } else if(selected[0].has_partitions) {
24+ return (
25+ "Device has already been partitioned; create a " +
26+ "new partition to use as the bcache backing " +
27+ "device");
28+ } else {
29+ return null;
30+ }
31+ } else {
32+ return "Select only one available device to create bcache";
33+ }
34+ }
35+ };
36+
37 // Return true if a bcache can be created.
38 $scope.canCreateBcache = function() {
39- if($scope.isAvailableDisabled() || ! $scope.isSuperUser()) {
40+ if($scope.isAvailableDisabled() || !$scope.isSuperUser()) {
41 return false;
42 }
43
44- var selected = $scope.getSelectedAvailable();
45- if(selected.length === 1) {
46- var allowed = (
47- !$scope.hasUnmountedFilesystem(selected[0]) &&
48- selected[0].type !== "lvm-vg");
49- return allowed && $scope.cachesets.length > 0;
50+ var msg = $scope.getCannotCreateBcacheMsg();
51+ if(msg === null) {
52+ return true;
53+ } else {
54+ return false;
55 }
56- return false;
57 };
58
59 // Enter bcache mode.
60
61=== modified file 'src/maasserver/static/js/angular/controllers/tests/test_node_details_storage.js'
62--- src/maasserver/static/js/angular/controllers/tests/test_node_details_storage.js 2016-03-28 13:54:47 +0000
63+++ src/maasserver/static/js/angular/controllers/tests/test_node_details_storage.js 2016-07-11 13:56:16 +0000
64@@ -3202,6 +3202,92 @@
65 });
66 });
67
68+ describe("getCannotCreateBcacheMsg", function() {
69+
70+ it("returns msg if no cachesets",
71+ function() {
72+ var controller = makeController();
73+ $scope.available = [
74+ {
75+ fstype: null,
76+ $selected: true,
77+ has_partitions: false
78+ }
79+ ];
80+ $scope.cachesets = [];
81+ expect($scope.getCannotCreateBcacheMsg()).toBe(
82+ "Create at least one cache set to create bcache");
83+ });
84+
85+ it("returns msg if two selected", function() {
86+ var controller = makeController();
87+ $scope.cachesets = [{}];
88+ $scope.available = [ { $selected: true }, { $selected: true }];
89+ expect($scope.getCannotCreateBcacheMsg()).toBe(
90+ "Select only one available device to create bcache");
91+ });
92+
93+ it("returns msg if selected has fstype", function() {
94+ var controller = makeController();
95+ $scope.available = [
96+ {
97+ fstype: "ext4",
98+ $selected: true,
99+ has_partitions: false
100+ }
101+ ];
102+ $scope.cachesets = [{}];
103+
104+ expect($scope.getCannotCreateBcacheMsg()).toBe(
105+ "Device is formatted; unformat the device to create bcache");
106+ });
107+
108+ it("returns msg if selected is volume group", function() {
109+ var controller = makeController();
110+ $scope.available = [
111+ {
112+ type: "lvm-vg",
113+ fstype: null,
114+ $selected: true,
115+ has_partitions: false
116+ }
117+ ];
118+ $scope.cachesets = [{}];
119+ expect($scope.getCannotCreateBcacheMsg()).toBe(
120+ "Cannot use a logical volume as a backing device for bcache.");
121+ });
122+
123+ it("returns msg if selected has partitions", function() {
124+ var controller = makeController();
125+ $scope.available = [
126+ {
127+ fstype: null,
128+ $selected: true,
129+ has_partitions: true
130+ }
131+ ];
132+ $scope.cachesets = [{}];
133+ expect($scope.getCannotCreateBcacheMsg()).toBe(
134+ "Device has already been partitioned; create a " +
135+ "new partition to use as the bcache backing " +
136+ "device");
137+ });
138+
139+ it("returns null if selected is valid",
140+ function() {
141+ var controller = makeController();
142+ $scope.available = [
143+ {
144+ fstype: null,
145+ $selected: true,
146+ has_partitions: false
147+ }
148+ ];
149+ $scope.cachesets = [{}];
150+ expect($scope.getCannotCreateBcacheMsg()).toBeNull();
151+ });
152+ });
153+
154 describe("canCreateBcache", function() {
155
156 it("returns false when isAvailableDisabled is true", function() {
157@@ -3227,7 +3313,8 @@
158 $scope.available = [
159 {
160 fstype: "ext4",
161- $selected: true
162+ $selected: true,
163+ has_partitions: false
164 }
165 ];
166 $scope.cachesets = [{}];
167@@ -3243,7 +3330,24 @@
168 {
169 type: "lvm-vg",
170 fstype: null,
171- $selected: true
172+ $selected: true,
173+ has_partitions: false
174+ }
175+ ];
176+ $scope.cachesets = [{}];
177+ $scope.isSuperUser = function() { return true; };
178+
179+ expect($scope.canCreateBcache()).toBe(false);
180+ });
181+
182+ it("returns false if selected has partitions", function() {
183+ var controller = makeController();
184+ spyOn($scope, "isAvailableDisabled").and.returnValue(false);
185+ $scope.available = [
186+ {
187+ fstype: null,
188+ $selected: true,
189+ has_partitions: true
190 }
191 ];
192 $scope.cachesets = [{}];
193@@ -3259,7 +3363,8 @@
194 $scope.available = [
195 {
196 fstype: null,
197- $selected: true
198+ $selected: true,
199+ has_partitions: false
200 }
201 ];
202 $scope.cachesets = [];
203@@ -3275,7 +3380,8 @@
204 $scope.available = [
205 {
206 fstype: null,
207- $selected: true
208+ $selected: true,
209+ has_partitions: false
210 }
211 ];
212 $scope.cachesets = [{}];
213@@ -3291,7 +3397,8 @@
214 $scope.available = [
215 {
216 fstype: null,
217- $selected: true
218+ $selected: true,
219+ has_partitions: false
220 }
221 ];
222 $scope.cachesets = [{}];
223
224=== modified file 'src/maasserver/static/partials/node-details.html'
225--- src/maasserver/static/partials/node-details.html 2016-06-14 21:30:57 +0000
226+++ src/maasserver/static/partials/node-details.html 2016-07-11 13:56:16 +0000
227@@ -1746,8 +1746,9 @@
228 data-ng-disabled="!canCreateCacheSet()"
229 data-ng-hide="isAllStorageDisabled() || !isSuperUser()"
230 data-ng-click="createCacheSet()">Create cache Set</a>
231- <a class="link-cta-ubuntu secondary margin-right tooltip"
232- data-tooltip="Create at least one cache set, then select your backing device to create bcache"
233+ <a class="link-cta-ubuntu secondary margin-right"
234+ data-tooltip="{$ getCannotCreateBcacheMsg() $}"
235+ data-ng-class="{ tooltip: !canCreateBcache() }"
236 data-ng-disabled="!canCreateBcache()"
237 data-ng-hide="isAllStorageDisabled() || !isSuperUser()"
238 data-ng-click="createBcache()">Create bcache</a>