Skip to content

Commit

Permalink
Fix edit bond form not saving all values. (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Ellis committed Jun 12, 2020
1 parent c188f58 commit 1ea774c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 38 deletions.
66 changes: 52 additions & 14 deletions legacy/src/app/controllers/node_details_networking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
};
}
};
Expand Down Expand Up @@ -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")
);
}
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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})`;
Expand Down Expand Up @@ -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);
}
Expand Down
57 changes: 49 additions & 8 deletions legacy/src/app/controllers/tests/test_node_details_networking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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();
Expand Down
40 changes: 24 additions & 16 deletions legacy/src/app/partials/node-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -1855,9 +1855,12 @@ <h3 class="p-heading--five">Bond details</h3>
<div class="p-form__group row">
<label for="bond-mode" class="p-form__label col-2">Bond mode</label>
<div class="p-form__control col-4">
<select name="bond-mode"
data-ng-model="editInterface.bond_mode"
data-ng-options="mode[0] as mode[1] for mode in bondOptions.modes">
<select
name="bond-mode"
ng-change="handleEditBondMode(editInterface.bond_mode)"
ng-model="editInterface.bond_mode"
ng-options="mode[0] as mode[1] for mode in bondOptions.modes"
>
</select>
</div>
</div>
Expand All @@ -1867,7 +1870,7 @@ <h3 class="p-heading--five">Bond details</h3>
<div class="p-form__control col-4">
<select name="xmit-hash-policy"
class="p-form-validation__input"
data-ng-model="editInterface.xmitHashPolicy"
data-ng-model="editInterface.bond_xmit_hash_policy"
data-ng-options="xmit[0] as xmit[1] for xmit in bondOptions.xmit_hash_policies">
</select>
<p class="p-form-validation__message" data-ng-if="showLACPRate() && modeAndPolicyCompliant()">
Expand All @@ -1879,7 +1882,7 @@ <h3 class="p-heading--five">Bond details</h3>
<label for="lacp-rate" class="p-form__label col-2">LACP rate</label>
<div class="p-form__control col-4">
<select name="lacp-rate"
data-ng-model="editInterface.lacpRate"
data-ng-model="editInterface.bond_lacp_rate"
data-ng-options="rate[0] as rate[1] for rate in bondOptions.lacp_rates">
</select>
</div>
Expand Down Expand Up @@ -1981,7 +1984,12 @@ <h3 class="p-heading--five">Advanced options</h3>
<div class="p-form__group row">
<label for="link-monitoring" class="p-form__label col-2">Link monitoring</label>
<div class="p-form__control col-4">
<select name="link-monitoring" id="link-monitoring" data-ng-model="editInterfaceLinkMonitoring">
<select
id="link-monitoring"
name="link-monitoring"
ng-change="handleEditLinkMonitoring(editInterfaceLinkMonitoring)"
ng-model="editInterfaceLinkMonitoring"
>
<option value="">No link monitoring</option>
<option value="mii">MII link monitoring</option>
</select>
Expand Down Expand Up @@ -2137,32 +2145,32 @@ <h2 class="p-heading--four">Create bond</h2>
</td>
<td class="p-table__col--status p-double-row" aria-label="Link and interface speed">
<div class="p-double-row__icon-container">
<span ng-if="!isBond(interface) && !isBridge(interface)">
<span ng-if="!isBond(parent) && !isBridge(parent)">
<span
aria-describedby="not-connected-tooltip"
class="p-tooltip--top-left"
ng-if="!isInterfaceConnected(interface)"
ng-if="!isInterfaceConnected(parent)"
>
<i class="p-icon--error"></i>
<span class="p-tooltip__message" role="tooltip" id="not-connected-tooltip">This interface is disconnected.</span>
</span>
<span
aria-describedby="link-speed-tooltip"
class="p-tooltip--top-left"
ng-if="isInterfaceConnected(interface) && interface.link_speed < interface.interface_speed"
ng-if="isInterfaceConnected(parent) && parent.link_speed < parent.interface_speed"
>
<i class="p-icon--warning"></i>
<span class="p-tooltip__message" role="tooltip" id="link-speed-tooltip">Link connected to slow interface.</span>
</span>
<i
class="p-icon--placeholder"
ng-if="isInterfaceConnected(interface) && interface.link_speed === interface.interface_speed">
ng-if="isInterfaceConnected(parent) && parent.link_speed === parent.interface_speed">
</i>
</span>
</div>
<div class="p-double-row__rows-container--icon">
<span ng-if="!isBond(interface) && !isBridge(interface)">
{$ formatSpeedUnits(interface.link_speed) $}/{$ formatSpeedUnits(interface.interface_speed) $}
<span ng-if="!isBond(parent) && !isBridge(parent)">
{$ formatSpeedUnits(parent.link_speed) $}/{$ formatSpeedUnits(parent.interface_speed) $}
</span>
</div>
</td>
Expand Down Expand Up @@ -2370,7 +2378,7 @@ <h3 class="p-heading--five">Bond details</h3>
<div class="p-form__control col-4">
<select name="xmit-hash-policy"
class="p-form-validation__input"
data-ng-model="newBondInterface.xmitHashPolicy"
data-ng-model="newBondInterface.bond_xmit_hash_policy"
data-ng-options="xmit[0] as xmit[1] for xmit in bondOptions.xmit_hash_policies">
</select>
<p class="p-form-validation__message" data-ng-if="showLACPRate() && modeAndPolicyCompliant()">
Expand All @@ -2382,7 +2390,7 @@ <h3 class="p-heading--five">Bond details</h3>
<label for="lacp-rate" class="p-form__label col-2">LACP rate</label>
<div class="p-form__control col-4">
<select name="lacp-rate"
data-ng-model="newBondInterface.lacpRate"
data-ng-model="newBondInterface.bond_lacp_rate"
data-ng-options="rate[0] as rate[1] for rate in bondOptions.lacp_rates">
</select>
</div>
Expand Down Expand Up @@ -3228,7 +3236,7 @@ <h2 class="u-float--left">Create bond</h2>
<label for="lacp-rate" class="p-form__label">LACP rate</label>
<div class="p-form__control">
<select name="lacp-rate"
data-ng-model="newBondInterface.lacpRate"
data-ng-model="newBondInterface.bond_lacp_rate"
data-ng-options="rate[0] as rate[1] for rate in bondOptions.lacp_rates">
</select>
</div>
Expand All @@ -3237,7 +3245,7 @@ <h2 class="u-float--left">Create bond</h2>
<label for="xmit-hash-policy" class="p-form__label">XMIT hash policy</label>
<div class="p-form__control">
<select name="xmit-hash-policy"
data-ng-model="newBondInterface.xmitHashPolicy"
data-ng-model="newBondInterface.bond_xmit_hash_policy"
data-ng-options="xmit[0] as xmit[1] for xmit in bondOptions.xmit_hash_policies">
</select>
</div>
Expand Down

0 comments on commit 1ea774c

Please sign in to comment.