From f0c3e796cdbab9c563e910eee32acd7bd73d3358 Mon Sep 17 00:00:00 2001 From: Caleb Ellis Date: Fri, 12 Jun 2020 17:57:54 +1000 Subject: [PATCH] Fix edit bond form not saving all values. (#1247) --- .../controllers/node_details_networking.js | 66 +++++++++++++++---- .../tests/test_node_details_networking.js | 57 +++++++++++++--- legacy/src/app/partials/node-details.html | 40 ++++++----- 3 files changed, 125 insertions(+), 38 deletions(-) diff --git a/legacy/src/app/controllers/node_details_networking.js b/legacy/src/app/controllers/node_details_networking.js index 79db9f4b0e..730fef487f 100644 --- a/legacy/src/app/controllers/node_details_networking.js +++ b/legacy/src/app/controllers/node_details_networking.js @@ -154,6 +154,10 @@ export function filterSelectedInterfaces() { return ( selectedInterfaces.indexOf(itemKey) === -1 && + item.fabric && + item.vlan && + newBondInterface.fabric && + newBondInterface.vlan && item.fabric.name === newBondInterface.fabric.name && item.vlan.id === newBondInterface.vlan.id ); @@ -1158,12 +1162,13 @@ export function NodeNetworkingController( bridge_stp: nic.params.bridge_stp, bridge_type: nic.params.bridge_type, bond_mode: nic.params.bond_mode, - xmitHashPolicy: nic.params.bond_xmit_hash_policy, - lacpRate: nic.params.bond_lacp_rate, + bond_xmit_hash_policy: nic.params.bond_xmit_hash_policy, + bond_lacp_rate: nic.params.bond_lacp_rate, bond_downdelay: nic.params.bond_downdelay, bond_updelay: nic.params.bond_updelay, bond_miimon: nic.params.bond_miimon }; + $scope.editInterfaceLinkMonitoring = nic.params.bond_miimon ? "mii" : ""; if (angular.isDefined(nic.subnet) && nic.subnet !== null) { $scope.editInterface.defaultSubnet = nic.subnet; } else { @@ -1193,13 +1198,13 @@ export function NodeNetworkingController( bridge_stp: nic.params.bridge_stp, bridge_type: nic.params.bridge_type, bond_mode: nic.params.bond_mode, - xmitHashPolicy: nic.params.bond_xmit_hash_policy, - lacpRate: nic.params.bond_lacp_rate, + bond_xmit_hash_policy: nic.params.bond_xmit_hash_policy, + bond_lacp_rate: nic.params.bond_lacp_rate, bond_downdelay: nic.params.bond_downdelay, bond_updelay: nic.params.bond_updelay, bond_miimon: nic.params.bond_miimon }; - + $scope.editInterfaceLinkMonitoring = nic.params.bond_miimon ? "mii" : ""; $scope.editInterface.parents = nic.parents; $scope.editInterface.members = nic.members; if (nic.members && nic.members.length) { @@ -1842,11 +1847,11 @@ export function NodeNetworkingController( vlan: vlan, subnet: subnet, bond_mode: "active-backup", - lacpRate: "fast", - xmitHashPolicy: "layer2", + bond_lacp_rate: "fast", + bond_xmit_hash_policy: "layer2", bond_updelay: 0, bond_downdelay: 0, - bond_miimon: 100 + bond_miimon: 0, }; } }; @@ -1901,14 +1906,14 @@ export function NodeNetworkingController( if ($scope.editInterface) { return ( $scope.editInterface.bond_mode === "802.3ad" && - ($scope.editInterface.xmitHashPolicy === "layer3+4" || - $scope.editInterface.xmitHashPolicy === "encap3+4") + ($scope.editInterface.bond_xmit_hash_policy === "layer3+4" || + $scope.editInterface.bond_xmit_hash_policy === "encap3+4") ); } else { return ( $scope.newBondInterface.bond_mode === "802.3ad" && - ($scope.newBondInterface.xmitHashPolicy === "layer3+4" || - $scope.newBondInterface.xmitHashPolicy === "encap3+4") + ($scope.newBondInterface.bond_xmit_hash_policy === "layer3+4" || + $scope.newBondInterface.bond_xmit_hash_policy === "encap3+4") ); } }; @@ -1988,8 +1993,8 @@ export function NodeNetworkingController( }), parents: parents, bond_mode: $scope.newBondInterface.bond_mode, - bond_lacp_rate: $scope.newBondInterface.lacpRate, - bond_xmit_hash_policy: $scope.newBondInterface.xmitHashPolicy, + bond_lacp_rate: $scope.newBondInterface.bond_lacp_rate, + bond_xmit_hash_policy: $scope.newBondInterface.bond_xmit_hash_policy, vlan: vlan_id, subnet: subnet_id, mode: $scope.newBondInterface.mode, @@ -2366,6 +2371,35 @@ export function NodeNetworkingController( $scope.showEditWarning = true; }; + // Set defaults or clear form fields depending on selected link monitoring. + $scope.handleEditLinkMonitoring = (linkMonitoring) => { + $scope.editInterfaceLinkMonitoring = linkMonitoring; + $scope.editInterface.bond_downdelay = 0; + $scope.editInterface.bond_updelay = 0; + + if (linkMonitoring === "mii") { + $scope.editInterface.bond_miimon = 100; + } else { + $scope.editInterface.bond_miimon = 0; + } + }; + + // Set defaults or clear form fields depending on selected bond mode. + $scope.handleEditBondMode = (bondMode) => { + $scope.editInterface.bond_mode = bondMode; + if ($scope.showLACPRate()) { + $scope.editInterface.bond_lacp_rate = "fast"; + } else { + $scope.editInterface.bond_lacp_rate = ""; + } + + if ($scope.showXMITHashPolicy()) { + $scope.editInterface.bond_xmit_hash_policy = "layer2"; + } else { + $scope.editInterface.bond_xmit_hash_policy = ""; + } + }; + $scope.getNetworkTestingStatus = nic => { const results = $scope.networkTestingResults; const resultKey = `${nic.name} (${nic.mac_address})`; @@ -2425,6 +2459,10 @@ export function NodeNetworkingController( }; $scope.isInterfaceConnected = (nic) => { + if (!nic) { + return; + } + if (nic.type === 'alias' && nic.members.length) { return nic.members.some((member) => member.link_connected); } diff --git a/legacy/src/app/controllers/tests/test_node_details_networking.js b/legacy/src/app/controllers/tests/test_node_details_networking.js index 57027064ac..947502468b 100644 --- a/legacy/src/app/controllers/tests/test_node_details_networking.js +++ b/legacy/src/app/controllers/tests/test_node_details_networking.js @@ -3691,11 +3691,11 @@ describe("NodeNetworkingController", function() { fabric: "", vlan: {}, subnet: "", - lacpRate: "fast", - xmitHashPolicy: "layer2", + bond_lacp_rate: "fast", + bond_xmit_hash_policy: "layer2", bond_updelay: 0, bond_downdelay: 0, - bond_miimon: 100 + bond_miimon: 0 }); }); }); @@ -3844,14 +3844,14 @@ describe("NodeNetworkingController", function() { it("returns true if policy is layer3+4", function() { makeController(); $scope.newBondInterface.bond_mode = "802.3ad"; - $scope.newBondInterface.xmitHashPolicy = "layer3+4"; + $scope.newBondInterface.bond_xmit_hash_policy = "layer3+4"; expect($scope.showLACPRate()).toBe(true); }); it("returns true if policy is encap3+4", function() { makeController(); $scope.newBondInterface.bond_mode = "802.3ad"; - $scope.newBondInterface.xmitHashPolicy = "encap3+4"; + $scope.newBondInterface.bond_xmit_hash_policy = "encap3+4"; expect($scope.showLACPRate()).toBe(true); }); @@ -3862,7 +3862,7 @@ describe("NodeNetworkingController", function() { link_id: -1 }; $scope.newBondInterface.bond_mode = "802.3ad"; - $scope.newBondInterface.xmitHashPolicy = "layer2+3"; + $scope.newBondInterface.bond_xmit_hash_policy = "layer2+3"; expect($scope.showLACPRate()).toBe(false); }); }); @@ -4008,7 +4008,7 @@ describe("NodeNetworkingController", function() { subnet: subnet.id, mode: "static", ip_address: "192.168.1.100", - bond_miimon: 100, + bond_miimon: 0, bond_updelay: 0, bond_downdelay: 0 }); @@ -4061,7 +4061,7 @@ describe("NodeNetworkingController", function() { subnet: null, mode: undefined, ip_address: undefined, - bond_miimon: 100, + bond_miimon: 0, bond_updelay: 0, bond_downdelay: 0 }); @@ -5197,6 +5197,47 @@ describe("NodeNetworkingController", function() { }); }); + describe("handleEditLinkMonitoring", () => { + it("clears bond monitoring frequency value if MII not selected", () => { + makeController(); + $scope.editInterface = { + bond_miimon: 0, + bond_downdelay: 0, + bond_updelay: 0, + }; + $scope.handleEditLinkMonitoring("mii"); + expect($scope.editInterface.bond_miimon).toBe(100); + $scope.handleEditLinkMonitoring(""); + expect($scope.editInterface.bond_miimon).toBe(0); + }); + }); + + describe("handleEditBondMode", () => { + it("clears LACP rate if bond mode does not support it", () => { + makeController(); + $scope.editInterface = { + bond_lacp_rate: "", + bond_mode: "balance-rr", + }; + $scope.handleEditBondMode("802.3ad"); + expect($scope.editInterface.bond_lacp_rate).toBe("fast"); + $scope.handleEditBondMode("balance-rr"); + expect($scope.editInterface.bond_lacp_rate).toBe(""); + }); + + it("clears hash policy if bond mode does not support it", () => { + makeController(); + $scope.editInterface = { + bond_xmit_hash_policy: "", + bond_mode: "balance-rr", + }; + $scope.handleEditBondMode("802.3ad"); + expect($scope.editInterface.bond_xmit_hash_policy).toBe("layer2"); + $scope.handleEditBondMode("balance-rr"); + expect($scope.editInterface.bond_xmit_hash_policy).toBe(""); + }); + }); + describe("canMarkAsDisconnected", () => { it("returns false if nic type is not physical", () => { makeController(); diff --git a/legacy/src/app/partials/node-details.html b/legacy/src/app/partials/node-details.html index 5c173b72dd..baaf350a1c 100755 --- a/legacy/src/app/partials/node-details.html +++ b/legacy/src/app/partials/node-details.html @@ -1855,9 +1855,12 @@

Bond details

-
@@ -1867,7 +1870,7 @@

Bond details

@@ -1879,7 +1882,7 @@

Bond details

@@ -1981,7 +1984,12 @@

Advanced options

- @@ -2137,11 +2145,11 @@

Create bond

- + This interface is disconnected. @@ -2149,20 +2157,20 @@

Create bond

Link connected to slow interface. + ng-if="isInterfaceConnected(parent) && parent.link_speed === parent.interface_speed">
- - {$ formatSpeedUnits(interface.link_speed) $}/{$ formatSpeedUnits(interface.interface_speed) $} + + {$ formatSpeedUnits(parent.link_speed) $}/{$ formatSpeedUnits(parent.interface_speed) $}
@@ -2370,7 +2378,7 @@

Bond details

@@ -2382,7 +2390,7 @@

Bond details

@@ -3228,7 +3236,7 @@

Create bond

@@ -3237,7 +3245,7 @@

Create bond