Merge lp:~trapnine/maas/fix-1576267 into lp:~maas-committers/maas/trunk
- fix-1576267
- Merge into trunk
Proposed by
Jeffrey C Jones
Status: | Merged |
---|---|
Approved by: | Jeffrey C Jones |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4988 |
Proposed branch: | lp:~trapnine/maas/fix-1576267 |
Merge into: | lp:~maas-committers/maas/trunk |
Diff against target: |
485 lines (+188/-94) 7 files modified
src/maasserver/static/js/angular/controllers/node_details_networking.js (+11/-5) src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js (+0/-1) src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js (+177/-41) src/maasserver/static/js/angular/factories/tests/test_vlans.js (+0/-25) src/maasserver/static/js/angular/factories/vlans.js (+0/-14) src/maasserver/websockets/handlers/tests/test_vlan.py (+0/-4) src/maasserver/websockets/handlers/vlan.py (+0/-4) |
To merge this branch: | bzr merge lp:~trapnine/maas/fix-1576267 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jeffrey C Jones (community) | Approve | ||
Blake Rouse (community) | Approve | ||
Review via email: mp+293706@code.launchpad.net |
Commit message
Adding new subnets now auto-updates controller details 'Served VLANs' Table.
Description of the change
Adding new subnets now auto-updates controller details 'Served VLANs' Table.
To post a comment you must log in.
Revision history for this message
Jeffrey C Jones (trapnine) : | # |
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_networking.js' |
2 | --- src/maasserver/static/js/angular/controllers/node_details_networking.js 2016-03-28 13:54:47 +0000 |
3 | +++ src/maasserver/static/js/angular/controllers/node_details_networking.js 2016-05-04 16:20:37 +0000 |
4 | @@ -279,7 +279,8 @@ |
5 | var vlanRecord = { |
6 | "fabric": nic.fabric, |
7 | "vlan": nic.vlan, |
8 | - "subnets": VLANsManager.getSubnets(nic.vlan), |
9 | + "subnets": $filter('filter')( |
10 | + $scope.subnets, {vlan:nic.vlan.id}, true), |
11 | "primary_rack": null, |
12 | "secondary_rack": null, |
13 | "sort_key": nic.fabric.name + "|" + |
14 | @@ -502,7 +503,10 @@ |
15 | // Called by $parent when the node has been loaded. |
16 | $scope.nodeLoaded = function() { |
17 | $scope.$watch("node.interfaces", updateInterfaces); |
18 | - $scope.$watchCollection($scope.subnets, updateInterfaces); |
19 | + // Watch subnets for the served VLANs section. |
20 | + if ($scope.$parent.isController) { |
21 | + $scope.$watch("subnets", updateInterfaces, true); |
22 | + } |
23 | $scope.nodeHasLoaded = true; |
24 | updateLoaded(); |
25 | }; |
26 | @@ -955,7 +959,8 @@ |
27 | // Alias used defaults based from its parent. |
28 | if(type === INTERFACE_TYPE.ALIAS) { |
29 | defaultVLAN = nic.vlan; |
30 | - defaultSubnet = VLANsManager.getSubnets(defaultVLAN)[0]; |
31 | + defaultSubnet = $filter('filter')( |
32 | + $scope.subnets, {vlan:defaultVLAN.id}, true)[0]; |
33 | defaultMode = LINK_MODE.AUTO; |
34 | } |
35 | |
36 | @@ -996,8 +1001,9 @@ |
37 | $scope.addTypeChanged = function() { |
38 | if($scope.newInterface.type === INTERFACE_TYPE.ALIAS) { |
39 | $scope.newInterface.vlan = $scope.newInterface.parent.vlan; |
40 | - $scope.newInterface.subnet = VLANsManager.getSubnets( |
41 | - $scope.newInterface.vlan)[0]; |
42 | + $scope.newInterface.subnet = $filter('filter')( |
43 | + $scope.subnets, |
44 | + {vlan:$scope.newInterface.vlan.id}, true)[0]; |
45 | $scope.newInterface.mode = LINK_MODE.AUTO; |
46 | } else if($scope.newInterface.type === INTERFACE_TYPE.VLAN) { |
47 | var vlans = getUnusedVLANs($scope.newInterface.parent); |
48 | |
49 | === modified file 'src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js' |
50 | --- src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js 2016-04-27 03:53:55 +0000 |
51 | +++ src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js 2016-05-04 16:20:37 +0000 |
52 | @@ -182,7 +182,6 @@ |
53 | ]; |
54 | fabric.vlan_ids = [1]; |
55 | spaces[0].subnet_ids = [0]; |
56 | - vlans[0].subnet_ids = [0]; |
57 | SpacesManager._items.push(spaces[0]); |
58 | VLANsManager._items.push(vlans[0]); |
59 | SubnetsManager._items.push(subnets[0]); |
60 | |
61 | === modified file 'src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js' |
62 | --- src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js 2016-03-28 13:54:47 +0000 |
63 | +++ src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js 2016-05-04 16:20:37 +0000 |
64 | @@ -420,7 +420,29 @@ |
65 | } |
66 | |
67 | expect(watches).toEqual(["node.interfaces"]); |
68 | - expect(watchCollections).toEqual([ $scope.subnets ]); |
69 | + expect(watchCollections).toEqual([]); |
70 | + }); |
71 | + |
72 | + it("watches interfaces and subnets once nodeLoaded called", function() { |
73 | + var controller = makeController(); |
74 | + spyOn($scope, "$watch"); |
75 | + spyOn($scope, "$watchCollection"); |
76 | + $parentScope.isController = true; |
77 | + $scope.nodeLoaded(); |
78 | + |
79 | + var watches = []; |
80 | + var i, calls = $scope.$watch.calls.allArgs(); |
81 | + for(i = 0; i < calls.length; i++) { |
82 | + watches.push(calls[i][0]); |
83 | + } |
84 | + var watchCollections = []; |
85 | + calls = $scope.$watchCollection.calls.allArgs(); |
86 | + for(i = 0; i < calls.length; i++) { |
87 | + watchCollections.push(calls[i][0]); |
88 | + } |
89 | + |
90 | + expect(watches).toEqual(["node.interfaces", "subnets"]); |
91 | + expect(watchCollections).toEqual([]); |
92 | }); |
93 | |
94 | describe("updateInterfaces", function() { |
95 | @@ -799,7 +821,6 @@ |
96 | vlan_id: 0 |
97 | }; |
98 | SubnetsManager._items = []; |
99 | - spyOn(VLANsManager, "getSubnets").and.returnValue([]); |
100 | FabricsManager._items = [fabric0]; |
101 | VLANsManager._items = [vlan0]; |
102 | node.interfaces = [nic0]; |
103 | @@ -819,14 +840,13 @@ |
104 | }); |
105 | |
106 | it("renders single entry vlanTable", function() { |
107 | - var subnet0 = { id: 0 }; |
108 | + var subnet0 = { id: 0, vlan: 0 }; |
109 | var fabric0 = { |
110 | id: 0 |
111 | }; |
112 | var vlan0 = { |
113 | id: 0, |
114 | - fabric: 0, |
115 | - subnet_ids: [0] |
116 | + fabric: 0 |
117 | }; |
118 | var nic0 = { |
119 | id: 0, |
120 | @@ -857,27 +877,27 @@ |
121 | ]); |
122 | }); |
123 | |
124 | - it("renders multi-entry vlanTable", function() { |
125 | - var subnet0 = { id: 0 }; |
126 | - var subnet1 = { id: 1 }; |
127 | - var subnet2 = { id: 2 }; |
128 | - var fabric0 = { |
129 | + var makeInterestingNetwork = function() { |
130 | + var net = {}; |
131 | + net.space0 = { id: 0 }; |
132 | + net.subnet0 = { id: 0, vlan:0, cidr: "10.0.0.0/16" }; |
133 | + net.subnet1 = { id: 1, vlan:0, cidr: "10.10.0.0/16" }; |
134 | + net.subnet2 = { id: 2, vlan:1, cidr: "10.20.0.0/16" }; |
135 | + net.fabric0 = { |
136 | id: 0 |
137 | }; |
138 | - var fabric1 = { |
139 | + net.fabric1 = { |
140 | id: 1 |
141 | }; |
142 | - var vlan0 = { |
143 | + net.vlan0 = { |
144 | id: 0, |
145 | - fabric: 0, |
146 | - subnet_ids: [0, 1] |
147 | + fabric: 0 |
148 | }; |
149 | - var vlan1 = { |
150 | + net.vlan1 = { |
151 | id: 1, |
152 | - fabric: 1, |
153 | - subnet_ids: [2] |
154 | + fabric: 1 |
155 | }; |
156 | - var nic0 = { |
157 | + net.nic0 = { |
158 | id: 0, |
159 | name: "eth0", |
160 | type: "physical", |
161 | @@ -886,7 +906,7 @@ |
162 | links: [], |
163 | vlan_id: 0 |
164 | }; |
165 | - var nic1 = { |
166 | + net.nic1 = { |
167 | id: 1, |
168 | name: "eth1", |
169 | type: "physical", |
170 | @@ -895,30 +915,37 @@ |
171 | links: [], |
172 | vlan_id: 1 |
173 | }; |
174 | - SubnetsManager._items = [subnet0, subnet1, subnet2]; |
175 | - FabricsManager._items = [fabric0, fabric1]; |
176 | - VLANsManager._items = [vlan0, vlan1]; |
177 | - node.interfaces = [nic0, nic1]; |
178 | + //SpacesManager._items = [net.space0]; |
179 | + SubnetsManager._items = [net.subnet0, net.subnet1, net.subnet2]; |
180 | + FabricsManager._items = [net.fabric0, net.fabric1]; |
181 | + VLANsManager._items = [net.vlan0, net.vlan1]; |
182 | + node.interfaces = [net.nic0, net.nic1]; |
183 | + return net; |
184 | + }; |
185 | |
186 | + it("renders multi-entry vlanTable", function() { |
187 | + var net = makeInterestingNetwork(); |
188 | // Should not blank for a controller. |
189 | $parentScope.isController = true; |
190 | updateInterfaces(); |
191 | expect($scope.vlanTable).toEqual([ |
192 | { |
193 | - fabric: fabric0, |
194 | - vlan: vlan0, |
195 | - subnets: [subnet0, subnet1], |
196 | + fabric: net.fabric0, |
197 | + vlan: net.vlan0, |
198 | + subnets: [net.subnet0, net.subnet1], |
199 | primary_rack: null, |
200 | secondary_rack: null, |
201 | - sort_key: fabric0.name + "|" + $scope.getVLANText(vlan0) |
202 | + sort_key: net.fabric0.name + "|" + |
203 | + $scope.getVLANText(net.vlan0) |
204 | }, |
205 | { |
206 | - fabric: fabric1, |
207 | - vlan: vlan1, |
208 | - subnets: [subnet2], |
209 | + fabric: net.fabric1, |
210 | + vlan: net.vlan1, |
211 | + subnets: [net.subnet2], |
212 | primary_rack: null, |
213 | secondary_rack: null, |
214 | - sort_key: fabric0.name + "|" + $scope.getVLANText(vlan1) |
215 | + sort_key: net.fabric0.name + "|" + |
216 | + $scope.getVLANText(net.vlan1) |
217 | } |
218 | ]); |
219 | }); |
220 | @@ -926,14 +953,13 @@ |
221 | it("no duplicate vlans", function() { |
222 | // Regression for https://bugs.launchpad.net/maas/+bug/1559332. |
223 | // Same vlan on two nics shouldn't result in two vlans in table. |
224 | - var subnet0 = { id: 0 }; |
225 | + var subnet0 = { id: 0, vlan:0 }; |
226 | var fabric0 = { |
227 | id: 0 |
228 | }; |
229 | var vlan0 = { |
230 | id: 0, |
231 | - fabric: 0, |
232 | - subnet_ids: [0, 1] |
233 | + fabric: 0 |
234 | }; |
235 | var nic0 = { |
236 | id: 0, |
237 | @@ -973,6 +999,117 @@ |
238 | ]); |
239 | }); |
240 | |
241 | + // Regression for https://bugs.launchpad.net/maas/+bug/1576267. |
242 | + it("updates vlanTable when add subnet", function() { |
243 | + var net = makeInterestingNetwork(); |
244 | + |
245 | + // Should not blank for a controller. |
246 | + $parentScope.isController = true; |
247 | + updateInterfaces(); |
248 | + expect($scope.vlanTable).toEqual([ |
249 | + { |
250 | + fabric: net.fabric0, |
251 | + vlan: net.vlan0, |
252 | + subnets: [net.subnet0, net.subnet1], |
253 | + primary_rack: null, |
254 | + secondary_rack: null, |
255 | + sort_key: net.fabric0.name + "|" + |
256 | + $scope.getVLANText(net.vlan0) |
257 | + }, |
258 | + { |
259 | + fabric: net.fabric1, |
260 | + vlan: net.vlan1, |
261 | + subnets: [net.subnet2], |
262 | + primary_rack: null, |
263 | + secondary_rack: null, |
264 | + sort_key: net.fabric0.name + "|" + |
265 | + $scope.getVLANText(net.vlan1) |
266 | + } |
267 | + ]); |
268 | + |
269 | + // Add subnet and make sure it shows up in vlanTable. |
270 | + var subnet = { |
271 | + id: 3, name:"subnet3", vlan: 0, space: 0, cidr: "10.30.0.0/16" |
272 | + }; |
273 | + SubnetsManager._items.push(subnet); |
274 | + $scope.$digest(); |
275 | + expect($scope.vlanTable).toEqual([ |
276 | + { |
277 | + fabric: net.fabric0, |
278 | + vlan: net.vlan0, |
279 | + subnets: [net.subnet0, net.subnet1, subnet], |
280 | + primary_rack: null, |
281 | + secondary_rack: null, |
282 | + sort_key: net.fabric0.name + "|" + |
283 | + $scope.getVLANText(net.vlan0) |
284 | + }, |
285 | + { |
286 | + fabric: net.fabric1, |
287 | + vlan: net.vlan1, |
288 | + subnets: [net.subnet2], |
289 | + primary_rack: null, |
290 | + secondary_rack: null, |
291 | + sort_key: net.fabric0.name + "|" + |
292 | + $scope.getVLANText(net.vlan1) |
293 | + } |
294 | + ]); |
295 | + }); |
296 | + |
297 | + // Regression for https://bugs.launchpad.net/maas/+bug/1576267. |
298 | + it("updates empty vlanTable when add subnet", function() { |
299 | + var fabric0 = { |
300 | + id: 0, |
301 | + name: 'fabric0' |
302 | + }; |
303 | + var vlan0 = { |
304 | + id: 0, |
305 | + fabric: 0, |
306 | + name: 'vlan0' |
307 | + }; |
308 | + var nic0 = { |
309 | + id: 0, |
310 | + name: "eth0", |
311 | + type: "physical", |
312 | + parents: [], |
313 | + children: [], |
314 | + links: [], |
315 | + vlan_id: 0 |
316 | + }; |
317 | + SubnetsManager._items = []; |
318 | + FabricsManager._items = [fabric0]; |
319 | + VLANsManager._items = [vlan0]; |
320 | + node.interfaces = [nic0]; |
321 | + |
322 | + $parentScope.isController = true; |
323 | + updateInterfaces(); |
324 | + expect($scope.vlanTable).toEqual([ |
325 | + { |
326 | + fabric: fabric0, |
327 | + vlan: vlan0, |
328 | + subnets: [], |
329 | + primary_rack: null, |
330 | + secondary_rack: null, |
331 | + sort_key: fabric0.name + "|" + $scope.getVLANText(vlan0) |
332 | + } |
333 | + ]); |
334 | + // Add subnet and make sure it shows up in vlanTable. |
335 | + var subnet = { |
336 | + id: 3, name:"subnet3", vlan: 0, space: 0, cidr: "10.30.0.0/16" |
337 | + }; |
338 | + SubnetsManager._items.push(subnet); |
339 | + $scope.$digest(); |
340 | + expect($scope.vlanTable).toEqual([ |
341 | + { |
342 | + fabric: fabric0, |
343 | + vlan: vlan0, |
344 | + subnets: [subnet], |
345 | + primary_rack: null, |
346 | + secondary_rack: null, |
347 | + sort_key: fabric0.name + "|" + $scope.getVLANText(vlan0) |
348 | + } |
349 | + ]); |
350 | + }); |
351 | + |
352 | it("creates interfaceLinksMap", function() { |
353 | var links = [ |
354 | { |
355 | @@ -2679,7 +2816,9 @@ |
356 | |
357 | it("sets up newInterface for alias", function() { |
358 | var controller = makeController(); |
359 | - var vlan = {}; |
360 | + var vlan = {id:0}; |
361 | + var subnet = {id:0, vlan:0}; |
362 | + $scope.subnets = [subnet]; |
363 | var nic = { |
364 | id: makeInteger(0, 100), |
365 | type: "physical", |
366 | @@ -2687,9 +2826,6 @@ |
367 | vlan: vlan |
368 | }; |
369 | |
370 | - var subnet = {}; |
371 | - spyOn(VLANsManager, "getSubnets").and.returnValue([subnet]); |
372 | - |
373 | $scope.add('alias', nic); |
374 | expect($scope.newInterface).toEqual({ |
375 | type: "alias", |
376 | @@ -2847,15 +2983,15 @@ |
377 | |
378 | it("reset properties based on the new type alias", function() { |
379 | var controller = makeController(); |
380 | - var vlan = {}; |
381 | - var subnet = {}; |
382 | + var vlan = {id:0}; |
383 | + var subnet = {id:0, vlan:0}; |
384 | + $scope.subnets = [subnet]; |
385 | var parent = { |
386 | id: makeInteger(0, 100), |
387 | name: name, |
388 | link_id: makeInteger(0, 100), |
389 | vlan: vlan |
390 | }; |
391 | - spyOn(VLANsManager, "getSubnets").and.returnValue([subnet]); |
392 | $scope.newInterface = { |
393 | type: "alias", |
394 | parent: parent |
395 | |
396 | === modified file 'src/maasserver/static/js/angular/factories/tests/test_vlans.js' |
397 | --- src/maasserver/static/js/angular/factories/tests/test_vlans.js 2016-04-22 17:28:15 +0000 |
398 | +++ src/maasserver/static/js/angular/factories/tests/test_vlans.js 2016-05-04 16:20:37 +0000 |
399 | @@ -31,31 +31,6 @@ |
400 | expect(VLANsManager._handler).toBe("vlan"); |
401 | }); |
402 | |
403 | - describe("getSubnets", function() { |
404 | - |
405 | - it("returns subnet objects", function() { |
406 | - var i, subnets = [], vlan_subnets = []; |
407 | - for(i = 0; i < 6; i++) { |
408 | - var subnet = makeSubnet(); |
409 | - subnets.push(subnet); |
410 | - if(i < 3) { |
411 | - vlan_subnets.push(subnet); |
412 | - } |
413 | - } |
414 | - |
415 | - var subnet_ids = []; |
416 | - angular.forEach(vlan_subnets, function(subnet) { |
417 | - subnet_ids.push(subnet.id); |
418 | - }); |
419 | - |
420 | - SubnetsManager._items = subnets; |
421 | - var vlan = { |
422 | - "subnet_ids": subnet_ids |
423 | - }; |
424 | - expect(vlan_subnets).toEqual(VLANsManager.getSubnets(vlan)); |
425 | - }); |
426 | - }); |
427 | - |
428 | describe("configureDHCP", function() { |
429 | |
430 | it("calls the region with expected parameters", function() { |
431 | |
432 | === modified file 'src/maasserver/static/js/angular/factories/vlans.js' |
433 | --- src/maasserver/static/js/angular/factories/vlans.js 2016-03-28 13:54:47 +0000 |
434 | +++ src/maasserver/static/js/angular/factories/vlans.js 2016-05-04 16:20:37 +0000 |
435 | @@ -29,20 +29,6 @@ |
436 | |
437 | VLANsManager.prototype = new Manager(); |
438 | |
439 | - // Return the Subnet objects that are part of this VLAN. The returned |
440 | - // array is calculated on each call, you should not watch this array, |
441 | - // instead you should watch this function. |
442 | - VLANsManager.prototype.getSubnets = function(vlan) { |
443 | - var subnets = []; |
444 | - angular.forEach(vlan.subnet_ids, function(subnet_id) { |
445 | - var subnet = SubnetsManager.getItemFromList(subnet_id); |
446 | - if(angular.isObject(subnet)) { |
447 | - subnets.push(subnet); |
448 | - } |
449 | - }); |
450 | - return subnets; |
451 | - }; |
452 | - |
453 | VLANsManager.prototype.getName = function(vlan) { |
454 | var name = vlan.vid; |
455 | if(vlan.vid === 0) { |
456 | |
457 | === modified file 'src/maasserver/websockets/handlers/tests/test_vlan.py' |
458 | --- src/maasserver/websockets/handlers/tests/test_vlan.py 2016-04-28 13:34:34 +0000 |
459 | +++ src/maasserver/websockets/handlers/tests/test_vlan.py 2016-05-04 16:20:37 +0000 |
460 | @@ -36,10 +36,6 @@ |
461 | "external_dhcp": vlan.external_dhcp, |
462 | "primary_rack": vlan.primary_rack, |
463 | "secondary_rack": vlan.secondary_rack, |
464 | - "subnet_ids": sorted([ |
465 | - subnet.id |
466 | - for subnet in vlan.subnet_set.all() |
467 | - ]), |
468 | } |
469 | data['rack_sids'] = sorted(list({ |
470 | interface.node.system_id |
471 | |
472 | === modified file 'src/maasserver/websockets/handlers/vlan.py' |
473 | --- src/maasserver/websockets/handlers/vlan.py 2016-03-28 13:54:47 +0000 |
474 | +++ src/maasserver/websockets/handlers/vlan.py 2016-05-04 16:20:37 +0000 |
475 | @@ -58,10 +58,6 @@ |
476 | data["primary_rack_sid"] = obj.primary_rack.system_id |
477 | if obj.secondary_rack is not None: |
478 | data["secondary_rack_sid"] = obj.secondary_rack.system_id |
479 | - data["subnet_ids"] = sorted([ |
480 | - subnet.id |
481 | - for subnet in obj.subnet_set.all() |
482 | - ]) |
483 | nodes = { |
484 | interface.node |
485 | for interface in obj.interface_set.all() |
Looks good. Very well test that is really nice to see. I do have a few comments.