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 edc3594 commit c165eef
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 38 deletions.
62 changes: 48 additions & 14 deletions legacy/src/app/controllers/node_details_networking.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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 @@ -1156,12 +1160,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 @@ -1191,13 +1196,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 @@ -1840,11 +1845,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 @@ -1899,14 +1904,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 @@ -1986,8 +1991,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 @@ -2349,6 +2354,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
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 @@ -3690,11 +3690,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 @@ -3843,14 +3843,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 @@ -3861,7 +3861,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 @@ -4007,7 +4007,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 @@ -4060,7 +4060,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 @@ -5181,6 +5181,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 @@ -1807,9 +1807,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 @@ -1819,7 +1822,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 @@ -1831,7 +1834,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 @@ -1933,7 +1936,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 @@ -2089,27 +2097,27 @@ <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 class="p-tooltip--top-left" data-ng-if="!interface.link_connected"
<span ng-if="!isBond(parent) && !isBridge(parent)">
<span class="p-tooltip--top-left" data-ng-if="!parent.link_connected"
aria-describedby="not-connected-tooltip">
<i class="p-icon--error"></i>
<span class="p-tooltip__message" role="tooltip" id="not-connected-tooltip">This interface is
disconnected.</span>
</span>
<span class="p-tooltip--top-left"
data-ng-if="interface.link_connected && interface.link_speed < interface.interface_speed"
data-ng-if="parent.link_connected && parent.link_speed < parent.interface_speed"
aria-describedby="link-speed-tooltip">
<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 data-ng-if="interface.link_connected && interface.link_speed === interface.interface_speed"
<i data-ng-if="parent.link_connected && parent.link_speed === parent.interface_speed"
class="p-icon--placeholder"></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 @@ -2300,7 +2308,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 @@ -2312,7 +2320,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 @@ -3147,7 +3155,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 @@ -3156,7 +3164,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 c165eef

Please sign in to comment.