Merge lp:~trapnine/maas/fix-1576267 into lp:~maas-committers/maas/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
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
Blake Rouse (blake-rouse) wrote :

Looks good. Very well test that is really nice to see. I do have a few comments.

review: Approve
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
=== modified file 'src/maasserver/static/js/angular/controllers/node_details_networking.js'
--- src/maasserver/static/js/angular/controllers/node_details_networking.js 2016-03-28 13:54:47 +0000
+++ src/maasserver/static/js/angular/controllers/node_details_networking.js 2016-05-04 16:20:37 +0000
@@ -279,7 +279,8 @@
279 var vlanRecord = {279 var vlanRecord = {
280 "fabric": nic.fabric,280 "fabric": nic.fabric,
281 "vlan": nic.vlan,281 "vlan": nic.vlan,
282 "subnets": VLANsManager.getSubnets(nic.vlan),282 "subnets": $filter('filter')(
283 $scope.subnets, {vlan:nic.vlan.id}, true),
283 "primary_rack": null,284 "primary_rack": null,
284 "secondary_rack": null,285 "secondary_rack": null,
285 "sort_key": nic.fabric.name + "|" +286 "sort_key": nic.fabric.name + "|" +
@@ -502,7 +503,10 @@
502 // Called by $parent when the node has been loaded.503 // Called by $parent when the node has been loaded.
503 $scope.nodeLoaded = function() {504 $scope.nodeLoaded = function() {
504 $scope.$watch("node.interfaces", updateInterfaces);505 $scope.$watch("node.interfaces", updateInterfaces);
505 $scope.$watchCollection($scope.subnets, updateInterfaces);506 // Watch subnets for the served VLANs section.
507 if ($scope.$parent.isController) {
508 $scope.$watch("subnets", updateInterfaces, true);
509 }
506 $scope.nodeHasLoaded = true;510 $scope.nodeHasLoaded = true;
507 updateLoaded();511 updateLoaded();
508 };512 };
@@ -955,7 +959,8 @@
955 // Alias used defaults based from its parent.959 // Alias used defaults based from its parent.
956 if(type === INTERFACE_TYPE.ALIAS) {960 if(type === INTERFACE_TYPE.ALIAS) {
957 defaultVLAN = nic.vlan;961 defaultVLAN = nic.vlan;
958 defaultSubnet = VLANsManager.getSubnets(defaultVLAN)[0];962 defaultSubnet = $filter('filter')(
963 $scope.subnets, {vlan:defaultVLAN.id}, true)[0];
959 defaultMode = LINK_MODE.AUTO;964 defaultMode = LINK_MODE.AUTO;
960 }965 }
961966
@@ -996,8 +1001,9 @@
996 $scope.addTypeChanged = function() {1001 $scope.addTypeChanged = function() {
997 if($scope.newInterface.type === INTERFACE_TYPE.ALIAS) {1002 if($scope.newInterface.type === INTERFACE_TYPE.ALIAS) {
998 $scope.newInterface.vlan = $scope.newInterface.parent.vlan;1003 $scope.newInterface.vlan = $scope.newInterface.parent.vlan;
999 $scope.newInterface.subnet = VLANsManager.getSubnets(1004 $scope.newInterface.subnet = $filter('filter')(
1000 $scope.newInterface.vlan)[0];1005 $scope.subnets,
1006 {vlan:$scope.newInterface.vlan.id}, true)[0];
1001 $scope.newInterface.mode = LINK_MODE.AUTO;1007 $scope.newInterface.mode = LINK_MODE.AUTO;
1002 } else if($scope.newInterface.type === INTERFACE_TYPE.VLAN) {1008 } else if($scope.newInterface.type === INTERFACE_TYPE.VLAN) {
1003 var vlans = getUnusedVLANs($scope.newInterface.parent);1009 var vlans = getUnusedVLANs($scope.newInterface.parent);
10041010
=== modified file 'src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js'
--- src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js 2016-04-27 03:53:55 +0000
+++ src/maasserver/static/js/angular/controllers/tests/test_fabric_details.js 2016-05-04 16:20:37 +0000
@@ -182,7 +182,6 @@
182 ];182 ];
183 fabric.vlan_ids = [1];183 fabric.vlan_ids = [1];
184 spaces[0].subnet_ids = [0];184 spaces[0].subnet_ids = [0];
185 vlans[0].subnet_ids = [0];
186 SpacesManager._items.push(spaces[0]);185 SpacesManager._items.push(spaces[0]);
187 VLANsManager._items.push(vlans[0]);186 VLANsManager._items.push(vlans[0]);
188 SubnetsManager._items.push(subnets[0]);187 SubnetsManager._items.push(subnets[0]);
189188
=== modified file 'src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js'
--- src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js 2016-03-28 13:54:47 +0000
+++ src/maasserver/static/js/angular/controllers/tests/test_node_details_networking.js 2016-05-04 16:20:37 +0000
@@ -420,7 +420,29 @@
420 }420 }
421421
422 expect(watches).toEqual(["node.interfaces"]);422 expect(watches).toEqual(["node.interfaces"]);
423 expect(watchCollections).toEqual([ $scope.subnets ]);423 expect(watchCollections).toEqual([]);
424 });
425
426 it("watches interfaces and subnets once nodeLoaded called", function() {
427 var controller = makeController();
428 spyOn($scope, "$watch");
429 spyOn($scope, "$watchCollection");
430 $parentScope.isController = true;
431 $scope.nodeLoaded();
432
433 var watches = [];
434 var i, calls = $scope.$watch.calls.allArgs();
435 for(i = 0; i < calls.length; i++) {
436 watches.push(calls[i][0]);
437 }
438 var watchCollections = [];
439 calls = $scope.$watchCollection.calls.allArgs();
440 for(i = 0; i < calls.length; i++) {
441 watchCollections.push(calls[i][0]);
442 }
443
444 expect(watches).toEqual(["node.interfaces", "subnets"]);
445 expect(watchCollections).toEqual([]);
424 });446 });
425447
426 describe("updateInterfaces", function() {448 describe("updateInterfaces", function() {
@@ -799,7 +821,6 @@
799 vlan_id: 0821 vlan_id: 0
800 };822 };
801 SubnetsManager._items = [];823 SubnetsManager._items = [];
802 spyOn(VLANsManager, "getSubnets").and.returnValue([]);
803 FabricsManager._items = [fabric0];824 FabricsManager._items = [fabric0];
804 VLANsManager._items = [vlan0];825 VLANsManager._items = [vlan0];
805 node.interfaces = [nic0];826 node.interfaces = [nic0];
@@ -819,14 +840,13 @@
819 });840 });
820841
821 it("renders single entry vlanTable", function() {842 it("renders single entry vlanTable", function() {
822 var subnet0 = { id: 0 };843 var subnet0 = { id: 0, vlan: 0 };
823 var fabric0 = {844 var fabric0 = {
824 id: 0845 id: 0
825 };846 };
826 var vlan0 = {847 var vlan0 = {
827 id: 0,848 id: 0,
828 fabric: 0,849 fabric: 0
829 subnet_ids: [0]
830 };850 };
831 var nic0 = {851 var nic0 = {
832 id: 0,852 id: 0,
@@ -857,27 +877,27 @@
857 ]);877 ]);
858 });878 });
859879
860 it("renders multi-entry vlanTable", function() {880 var makeInterestingNetwork = function() {
861 var subnet0 = { id: 0 };881 var net = {};
862 var subnet1 = { id: 1 };882 net.space0 = { id: 0 };
863 var subnet2 = { id: 2 };883 net.subnet0 = { id: 0, vlan:0, cidr: "10.0.0.0/16" };
864 var fabric0 = {884 net.subnet1 = { id: 1, vlan:0, cidr: "10.10.0.0/16" };
885 net.subnet2 = { id: 2, vlan:1, cidr: "10.20.0.0/16" };
886 net.fabric0 = {
865 id: 0887 id: 0
866 };888 };
867 var fabric1 = {889 net.fabric1 = {
868 id: 1890 id: 1
869 };891 };
870 var vlan0 = {892 net.vlan0 = {
871 id: 0,893 id: 0,
872 fabric: 0,894 fabric: 0
873 subnet_ids: [0, 1]
874 };895 };
875 var vlan1 = {896 net.vlan1 = {
876 id: 1,897 id: 1,
877 fabric: 1,898 fabric: 1
878 subnet_ids: [2]
879 };899 };
880 var nic0 = {900 net.nic0 = {
881 id: 0,901 id: 0,
882 name: "eth0",902 name: "eth0",
883 type: "physical",903 type: "physical",
@@ -886,7 +906,7 @@
886 links: [],906 links: [],
887 vlan_id: 0907 vlan_id: 0
888 };908 };
889 var nic1 = {909 net.nic1 = {
890 id: 1,910 id: 1,
891 name: "eth1",911 name: "eth1",
892 type: "physical",912 type: "physical",
@@ -895,30 +915,37 @@
895 links: [],915 links: [],
896 vlan_id: 1916 vlan_id: 1
897 };917 };
898 SubnetsManager._items = [subnet0, subnet1, subnet2];918 //SpacesManager._items = [net.space0];
899 FabricsManager._items = [fabric0, fabric1];919 SubnetsManager._items = [net.subnet0, net.subnet1, net.subnet2];
900 VLANsManager._items = [vlan0, vlan1];920 FabricsManager._items = [net.fabric0, net.fabric1];
901 node.interfaces = [nic0, nic1];921 VLANsManager._items = [net.vlan0, net.vlan1];
922 node.interfaces = [net.nic0, net.nic1];
923 return net;
924 };
902925
926 it("renders multi-entry vlanTable", function() {
927 var net = makeInterestingNetwork();
903 // Should not blank for a controller.928 // Should not blank for a controller.
904 $parentScope.isController = true;929 $parentScope.isController = true;
905 updateInterfaces();930 updateInterfaces();
906 expect($scope.vlanTable).toEqual([931 expect($scope.vlanTable).toEqual([
907 {932 {
908 fabric: fabric0,933 fabric: net.fabric0,
909 vlan: vlan0,934 vlan: net.vlan0,
910 subnets: [subnet0, subnet1],935 subnets: [net.subnet0, net.subnet1],
911 primary_rack: null,936 primary_rack: null,
912 secondary_rack: null,937 secondary_rack: null,
913 sort_key: fabric0.name + "|" + $scope.getVLANText(vlan0)938 sort_key: net.fabric0.name + "|" +
939 $scope.getVLANText(net.vlan0)
914 },940 },
915 {941 {
916 fabric: fabric1,942 fabric: net.fabric1,
917 vlan: vlan1,943 vlan: net.vlan1,
918 subnets: [subnet2],944 subnets: [net.subnet2],
919 primary_rack: null,945 primary_rack: null,
920 secondary_rack: null,946 secondary_rack: null,
921 sort_key: fabric0.name + "|" + $scope.getVLANText(vlan1)947 sort_key: net.fabric0.name + "|" +
948 $scope.getVLANText(net.vlan1)
922 }949 }
923 ]);950 ]);
924 });951 });
@@ -926,14 +953,13 @@
926 it("no duplicate vlans", function() {953 it("no duplicate vlans", function() {
927 // Regression for https://bugs.launchpad.net/maas/+bug/1559332.954 // Regression for https://bugs.launchpad.net/maas/+bug/1559332.
928 // Same vlan on two nics shouldn't result in two vlans in table.955 // Same vlan on two nics shouldn't result in two vlans in table.
929 var subnet0 = { id: 0 };956 var subnet0 = { id: 0, vlan:0 };
930 var fabric0 = {957 var fabric0 = {
931 id: 0958 id: 0
932 };959 };
933 var vlan0 = {960 var vlan0 = {
934 id: 0,961 id: 0,
935 fabric: 0,962 fabric: 0
936 subnet_ids: [0, 1]
937 };963 };
938 var nic0 = {964 var nic0 = {
939 id: 0,965 id: 0,
@@ -973,6 +999,117 @@
973 ]);999 ]);
974 });1000 });
9751001
1002 // Regression for https://bugs.launchpad.net/maas/+bug/1576267.
1003 it("updates vlanTable when add subnet", function() {
1004 var net = makeInterestingNetwork();
1005
1006 // Should not blank for a controller.
1007 $parentScope.isController = true;
1008 updateInterfaces();
1009 expect($scope.vlanTable).toEqual([
1010 {
1011 fabric: net.fabric0,
1012 vlan: net.vlan0,
1013 subnets: [net.subnet0, net.subnet1],
1014 primary_rack: null,
1015 secondary_rack: null,
1016 sort_key: net.fabric0.name + "|" +
1017 $scope.getVLANText(net.vlan0)
1018 },
1019 {
1020 fabric: net.fabric1,
1021 vlan: net.vlan1,
1022 subnets: [net.subnet2],
1023 primary_rack: null,
1024 secondary_rack: null,
1025 sort_key: net.fabric0.name + "|" +
1026 $scope.getVLANText(net.vlan1)
1027 }
1028 ]);
1029
1030 // Add subnet and make sure it shows up in vlanTable.
1031 var subnet = {
1032 id: 3, name:"subnet3", vlan: 0, space: 0, cidr: "10.30.0.0/16"
1033 };
1034 SubnetsManager._items.push(subnet);
1035 $scope.$digest();
1036 expect($scope.vlanTable).toEqual([
1037 {
1038 fabric: net.fabric0,
1039 vlan: net.vlan0,
1040 subnets: [net.subnet0, net.subnet1, subnet],
1041 primary_rack: null,
1042 secondary_rack: null,
1043 sort_key: net.fabric0.name + "|" +
1044 $scope.getVLANText(net.vlan0)
1045 },
1046 {
1047 fabric: net.fabric1,
1048 vlan: net.vlan1,
1049 subnets: [net.subnet2],
1050 primary_rack: null,
1051 secondary_rack: null,
1052 sort_key: net.fabric0.name + "|" +
1053 $scope.getVLANText(net.vlan1)
1054 }
1055 ]);
1056 });
1057
1058 // Regression for https://bugs.launchpad.net/maas/+bug/1576267.
1059 it("updates empty vlanTable when add subnet", function() {
1060 var fabric0 = {
1061 id: 0,
1062 name: 'fabric0'
1063 };
1064 var vlan0 = {
1065 id: 0,
1066 fabric: 0,
1067 name: 'vlan0'
1068 };
1069 var nic0 = {
1070 id: 0,
1071 name: "eth0",
1072 type: "physical",
1073 parents: [],
1074 children: [],
1075 links: [],
1076 vlan_id: 0
1077 };
1078 SubnetsManager._items = [];
1079 FabricsManager._items = [fabric0];
1080 VLANsManager._items = [vlan0];
1081 node.interfaces = [nic0];
1082
1083 $parentScope.isController = true;
1084 updateInterfaces();
1085 expect($scope.vlanTable).toEqual([
1086 {
1087 fabric: fabric0,
1088 vlan: vlan0,
1089 subnets: [],
1090 primary_rack: null,
1091 secondary_rack: null,
1092 sort_key: fabric0.name + "|" + $scope.getVLANText(vlan0)
1093 }
1094 ]);
1095 // Add subnet and make sure it shows up in vlanTable.
1096 var subnet = {
1097 id: 3, name:"subnet3", vlan: 0, space: 0, cidr: "10.30.0.0/16"
1098 };
1099 SubnetsManager._items.push(subnet);
1100 $scope.$digest();
1101 expect($scope.vlanTable).toEqual([
1102 {
1103 fabric: fabric0,
1104 vlan: vlan0,
1105 subnets: [subnet],
1106 primary_rack: null,
1107 secondary_rack: null,
1108 sort_key: fabric0.name + "|" + $scope.getVLANText(vlan0)
1109 }
1110 ]);
1111 });
1112
976 it("creates interfaceLinksMap", function() {1113 it("creates interfaceLinksMap", function() {
977 var links = [1114 var links = [
978 {1115 {
@@ -2679,7 +2816,9 @@
26792816
2680 it("sets up newInterface for alias", function() {2817 it("sets up newInterface for alias", function() {
2681 var controller = makeController();2818 var controller = makeController();
2682 var vlan = {};2819 var vlan = {id:0};
2820 var subnet = {id:0, vlan:0};
2821 $scope.subnets = [subnet];
2683 var nic = {2822 var nic = {
2684 id: makeInteger(0, 100),2823 id: makeInteger(0, 100),
2685 type: "physical",2824 type: "physical",
@@ -2687,9 +2826,6 @@
2687 vlan: vlan2826 vlan: vlan
2688 };2827 };
26892828
2690 var subnet = {};
2691 spyOn(VLANsManager, "getSubnets").and.returnValue([subnet]);
2692
2693 $scope.add('alias', nic);2829 $scope.add('alias', nic);
2694 expect($scope.newInterface).toEqual({2830 expect($scope.newInterface).toEqual({
2695 type: "alias",2831 type: "alias",
@@ -2847,15 +2983,15 @@
28472983
2848 it("reset properties based on the new type alias", function() {2984 it("reset properties based on the new type alias", function() {
2849 var controller = makeController();2985 var controller = makeController();
2850 var vlan = {};2986 var vlan = {id:0};
2851 var subnet = {};2987 var subnet = {id:0, vlan:0};
2988 $scope.subnets = [subnet];
2852 var parent = {2989 var parent = {
2853 id: makeInteger(0, 100),2990 id: makeInteger(0, 100),
2854 name: name,2991 name: name,
2855 link_id: makeInteger(0, 100),2992 link_id: makeInteger(0, 100),
2856 vlan: vlan2993 vlan: vlan
2857 };2994 };
2858 spyOn(VLANsManager, "getSubnets").and.returnValue([subnet]);
2859 $scope.newInterface = {2995 $scope.newInterface = {
2860 type: "alias",2996 type: "alias",
2861 parent: parent2997 parent: parent
28622998
=== modified file 'src/maasserver/static/js/angular/factories/tests/test_vlans.js'
--- src/maasserver/static/js/angular/factories/tests/test_vlans.js 2016-04-22 17:28:15 +0000
+++ src/maasserver/static/js/angular/factories/tests/test_vlans.js 2016-05-04 16:20:37 +0000
@@ -31,31 +31,6 @@
31 expect(VLANsManager._handler).toBe("vlan");31 expect(VLANsManager._handler).toBe("vlan");
32 });32 });
3333
34 describe("getSubnets", function() {
35
36 it("returns subnet objects", function() {
37 var i, subnets = [], vlan_subnets = [];
38 for(i = 0; i < 6; i++) {
39 var subnet = makeSubnet();
40 subnets.push(subnet);
41 if(i < 3) {
42 vlan_subnets.push(subnet);
43 }
44 }
45
46 var subnet_ids = [];
47 angular.forEach(vlan_subnets, function(subnet) {
48 subnet_ids.push(subnet.id);
49 });
50
51 SubnetsManager._items = subnets;
52 var vlan = {
53 "subnet_ids": subnet_ids
54 };
55 expect(vlan_subnets).toEqual(VLANsManager.getSubnets(vlan));
56 });
57 });
58
59 describe("configureDHCP", function() {34 describe("configureDHCP", function() {
6035
61 it("calls the region with expected parameters", function() {36 it("calls the region with expected parameters", function() {
6237
=== modified file 'src/maasserver/static/js/angular/factories/vlans.js'
--- src/maasserver/static/js/angular/factories/vlans.js 2016-03-28 13:54:47 +0000
+++ src/maasserver/static/js/angular/factories/vlans.js 2016-05-04 16:20:37 +0000
@@ -29,20 +29,6 @@
2929
30 VLANsManager.prototype = new Manager();30 VLANsManager.prototype = new Manager();
3131
32 // Return the Subnet objects that are part of this VLAN. The returned
33 // array is calculated on each call, you should not watch this array,
34 // instead you should watch this function.
35 VLANsManager.prototype.getSubnets = function(vlan) {
36 var subnets = [];
37 angular.forEach(vlan.subnet_ids, function(subnet_id) {
38 var subnet = SubnetsManager.getItemFromList(subnet_id);
39 if(angular.isObject(subnet)) {
40 subnets.push(subnet);
41 }
42 });
43 return subnets;
44 };
45
46 VLANsManager.prototype.getName = function(vlan) {32 VLANsManager.prototype.getName = function(vlan) {
47 var name = vlan.vid;33 var name = vlan.vid;
48 if(vlan.vid === 0) {34 if(vlan.vid === 0) {
4935
=== modified file 'src/maasserver/websockets/handlers/tests/test_vlan.py'
--- src/maasserver/websockets/handlers/tests/test_vlan.py 2016-04-28 13:34:34 +0000
+++ src/maasserver/websockets/handlers/tests/test_vlan.py 2016-05-04 16:20:37 +0000
@@ -36,10 +36,6 @@
36 "external_dhcp": vlan.external_dhcp,36 "external_dhcp": vlan.external_dhcp,
37 "primary_rack": vlan.primary_rack,37 "primary_rack": vlan.primary_rack,
38 "secondary_rack": vlan.secondary_rack,38 "secondary_rack": vlan.secondary_rack,
39 "subnet_ids": sorted([
40 subnet.id
41 for subnet in vlan.subnet_set.all()
42 ]),
43 }39 }
44 data['rack_sids'] = sorted(list({40 data['rack_sids'] = sorted(list({
45 interface.node.system_id41 interface.node.system_id
4642
=== modified file 'src/maasserver/websockets/handlers/vlan.py'
--- src/maasserver/websockets/handlers/vlan.py 2016-03-28 13:54:47 +0000
+++ src/maasserver/websockets/handlers/vlan.py 2016-05-04 16:20:37 +0000
@@ -58,10 +58,6 @@
58 data["primary_rack_sid"] = obj.primary_rack.system_id58 data["primary_rack_sid"] = obj.primary_rack.system_id
59 if obj.secondary_rack is not None:59 if obj.secondary_rack is not None:
60 data["secondary_rack_sid"] = obj.secondary_rack.system_id60 data["secondary_rack_sid"] = obj.secondary_rack.system_id
61 data["subnet_ids"] = sorted([
62 subnet.id
63 for subnet in obj.subnet_set.all()
64 ])
65 nodes = {61 nodes = {
66 interface.node62 interface.node
67 for interface in obj.interface_set.all()63 for interface in obj.interface_set.all()