Skip to content

Commit 1ea774c

Browse files
author
Caleb Ellis
committed
Fix edit bond form not saving all values. (#1247)
1 parent c188f58 commit 1ea774c

File tree

3 files changed

+125
-38
lines changed

3 files changed

+125
-38
lines changed

legacy/src/app/controllers/node_details_networking.js

+52-14
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ export function filterSelectedInterfaces() {
154154

155155
return (
156156
selectedInterfaces.indexOf(itemKey) === -1 &&
157+
item.fabric &&
158+
item.vlan &&
159+
newBondInterface.fabric &&
160+
newBondInterface.vlan &&
157161
item.fabric.name === newBondInterface.fabric.name &&
158162
item.vlan.id === newBondInterface.vlan.id
159163
);
@@ -1158,12 +1162,13 @@ export function NodeNetworkingController(
11581162
bridge_stp: nic.params.bridge_stp,
11591163
bridge_type: nic.params.bridge_type,
11601164
bond_mode: nic.params.bond_mode,
1161-
xmitHashPolicy: nic.params.bond_xmit_hash_policy,
1162-
lacpRate: nic.params.bond_lacp_rate,
1165+
bond_xmit_hash_policy: nic.params.bond_xmit_hash_policy,
1166+
bond_lacp_rate: nic.params.bond_lacp_rate,
11631167
bond_downdelay: nic.params.bond_downdelay,
11641168
bond_updelay: nic.params.bond_updelay,
11651169
bond_miimon: nic.params.bond_miimon
11661170
};
1171+
$scope.editInterfaceLinkMonitoring = nic.params.bond_miimon ? "mii" : "";
11671172
if (angular.isDefined(nic.subnet) && nic.subnet !== null) {
11681173
$scope.editInterface.defaultSubnet = nic.subnet;
11691174
} else {
@@ -1193,13 +1198,13 @@ export function NodeNetworkingController(
11931198
bridge_stp: nic.params.bridge_stp,
11941199
bridge_type: nic.params.bridge_type,
11951200
bond_mode: nic.params.bond_mode,
1196-
xmitHashPolicy: nic.params.bond_xmit_hash_policy,
1197-
lacpRate: nic.params.bond_lacp_rate,
1201+
bond_xmit_hash_policy: nic.params.bond_xmit_hash_policy,
1202+
bond_lacp_rate: nic.params.bond_lacp_rate,
11981203
bond_downdelay: nic.params.bond_downdelay,
11991204
bond_updelay: nic.params.bond_updelay,
12001205
bond_miimon: nic.params.bond_miimon
12011206
};
1202-
1207+
$scope.editInterfaceLinkMonitoring = nic.params.bond_miimon ? "mii" : "";
12031208
$scope.editInterface.parents = nic.parents;
12041209
$scope.editInterface.members = nic.members;
12051210
if (nic.members && nic.members.length) {
@@ -1842,11 +1847,11 @@ export function NodeNetworkingController(
18421847
vlan: vlan,
18431848
subnet: subnet,
18441849
bond_mode: "active-backup",
1845-
lacpRate: "fast",
1846-
xmitHashPolicy: "layer2",
1850+
bond_lacp_rate: "fast",
1851+
bond_xmit_hash_policy: "layer2",
18471852
bond_updelay: 0,
18481853
bond_downdelay: 0,
1849-
bond_miimon: 100
1854+
bond_miimon: 0,
18501855
};
18511856
}
18521857
};
@@ -1901,14 +1906,14 @@ export function NodeNetworkingController(
19011906
if ($scope.editInterface) {
19021907
return (
19031908
$scope.editInterface.bond_mode === "802.3ad" &&
1904-
($scope.editInterface.xmitHashPolicy === "layer3+4" ||
1905-
$scope.editInterface.xmitHashPolicy === "encap3+4")
1909+
($scope.editInterface.bond_xmit_hash_policy === "layer3+4" ||
1910+
$scope.editInterface.bond_xmit_hash_policy === "encap3+4")
19061911
);
19071912
} else {
19081913
return (
19091914
$scope.newBondInterface.bond_mode === "802.3ad" &&
1910-
($scope.newBondInterface.xmitHashPolicy === "layer3+4" ||
1911-
$scope.newBondInterface.xmitHashPolicy === "encap3+4")
1915+
($scope.newBondInterface.bond_xmit_hash_policy === "layer3+4" ||
1916+
$scope.newBondInterface.bond_xmit_hash_policy === "encap3+4")
19121917
);
19131918
}
19141919
};
@@ -1988,8 +1993,8 @@ export function NodeNetworkingController(
19881993
}),
19891994
parents: parents,
19901995
bond_mode: $scope.newBondInterface.bond_mode,
1991-
bond_lacp_rate: $scope.newBondInterface.lacpRate,
1992-
bond_xmit_hash_policy: $scope.newBondInterface.xmitHashPolicy,
1996+
bond_lacp_rate: $scope.newBondInterface.bond_lacp_rate,
1997+
bond_xmit_hash_policy: $scope.newBondInterface.bond_xmit_hash_policy,
19931998
vlan: vlan_id,
19941999
subnet: subnet_id,
19952000
mode: $scope.newBondInterface.mode,
@@ -2366,6 +2371,35 @@ export function NodeNetworkingController(
23662371
$scope.showEditWarning = true;
23672372
};
23682373

2374+
// Set defaults or clear form fields depending on selected link monitoring.
2375+
$scope.handleEditLinkMonitoring = (linkMonitoring) => {
2376+
$scope.editInterfaceLinkMonitoring = linkMonitoring;
2377+
$scope.editInterface.bond_downdelay = 0;
2378+
$scope.editInterface.bond_updelay = 0;
2379+
2380+
if (linkMonitoring === "mii") {
2381+
$scope.editInterface.bond_miimon = 100;
2382+
} else {
2383+
$scope.editInterface.bond_miimon = 0;
2384+
}
2385+
};
2386+
2387+
// Set defaults or clear form fields depending on selected bond mode.
2388+
$scope.handleEditBondMode = (bondMode) => {
2389+
$scope.editInterface.bond_mode = bondMode;
2390+
if ($scope.showLACPRate()) {
2391+
$scope.editInterface.bond_lacp_rate = "fast";
2392+
} else {
2393+
$scope.editInterface.bond_lacp_rate = "";
2394+
}
2395+
2396+
if ($scope.showXMITHashPolicy()) {
2397+
$scope.editInterface.bond_xmit_hash_policy = "layer2";
2398+
} else {
2399+
$scope.editInterface.bond_xmit_hash_policy = "";
2400+
}
2401+
};
2402+
23692403
$scope.getNetworkTestingStatus = nic => {
23702404
const results = $scope.networkTestingResults;
23712405
const resultKey = `${nic.name} (${nic.mac_address})`;
@@ -2425,6 +2459,10 @@ export function NodeNetworkingController(
24252459
};
24262460

24272461
$scope.isInterfaceConnected = (nic) => {
2462+
if (!nic) {
2463+
return;
2464+
}
2465+
24282466
if (nic.type === 'alias' && nic.members.length) {
24292467
return nic.members.some((member) => member.link_connected);
24302468
}

legacy/src/app/controllers/tests/test_node_details_networking.js

+49-8
Original file line numberDiff line numberDiff line change
@@ -3691,11 +3691,11 @@ describe("NodeNetworkingController", function() {
36913691
fabric: "",
36923692
vlan: {},
36933693
subnet: "",
3694-
lacpRate: "fast",
3695-
xmitHashPolicy: "layer2",
3694+
bond_lacp_rate: "fast",
3695+
bond_xmit_hash_policy: "layer2",
36963696
bond_updelay: 0,
36973697
bond_downdelay: 0,
3698-
bond_miimon: 100
3698+
bond_miimon: 0
36993699
});
37003700
});
37013701
});
@@ -3844,14 +3844,14 @@ describe("NodeNetworkingController", function() {
38443844
it("returns true if policy is layer3+4", function() {
38453845
makeController();
38463846
$scope.newBondInterface.bond_mode = "802.3ad";
3847-
$scope.newBondInterface.xmitHashPolicy = "layer3+4";
3847+
$scope.newBondInterface.bond_xmit_hash_policy = "layer3+4";
38483848
expect($scope.showLACPRate()).toBe(true);
38493849
});
38503850

38513851
it("returns true if policy is encap3+4", function() {
38523852
makeController();
38533853
$scope.newBondInterface.bond_mode = "802.3ad";
3854-
$scope.newBondInterface.xmitHashPolicy = "encap3+4";
3854+
$scope.newBondInterface.bond_xmit_hash_policy = "encap3+4";
38553855
expect($scope.showLACPRate()).toBe(true);
38563856
});
38573857

@@ -3862,7 +3862,7 @@ describe("NodeNetworkingController", function() {
38623862
link_id: -1
38633863
};
38643864
$scope.newBondInterface.bond_mode = "802.3ad";
3865-
$scope.newBondInterface.xmitHashPolicy = "layer2+3";
3865+
$scope.newBondInterface.bond_xmit_hash_policy = "layer2+3";
38663866
expect($scope.showLACPRate()).toBe(false);
38673867
});
38683868
});
@@ -4008,7 +4008,7 @@ describe("NodeNetworkingController", function() {
40084008
subnet: subnet.id,
40094009
mode: "static",
40104010
ip_address: "192.168.1.100",
4011-
bond_miimon: 100,
4011+
bond_miimon: 0,
40124012
bond_updelay: 0,
40134013
bond_downdelay: 0
40144014
});
@@ -4061,7 +4061,7 @@ describe("NodeNetworkingController", function() {
40614061
subnet: null,
40624062
mode: undefined,
40634063
ip_address: undefined,
4064-
bond_miimon: 100,
4064+
bond_miimon: 0,
40654065
bond_updelay: 0,
40664066
bond_downdelay: 0
40674067
});
@@ -5197,6 +5197,47 @@ describe("NodeNetworkingController", function() {
51975197
});
51985198
});
51995199

5200+
describe("handleEditLinkMonitoring", () => {
5201+
it("clears bond monitoring frequency value if MII not selected", () => {
5202+
makeController();
5203+
$scope.editInterface = {
5204+
bond_miimon: 0,
5205+
bond_downdelay: 0,
5206+
bond_updelay: 0,
5207+
};
5208+
$scope.handleEditLinkMonitoring("mii");
5209+
expect($scope.editInterface.bond_miimon).toBe(100);
5210+
$scope.handleEditLinkMonitoring("");
5211+
expect($scope.editInterface.bond_miimon).toBe(0);
5212+
});
5213+
});
5214+
5215+
describe("handleEditBondMode", () => {
5216+
it("clears LACP rate if bond mode does not support it", () => {
5217+
makeController();
5218+
$scope.editInterface = {
5219+
bond_lacp_rate: "",
5220+
bond_mode: "balance-rr",
5221+
};
5222+
$scope.handleEditBondMode("802.3ad");
5223+
expect($scope.editInterface.bond_lacp_rate).toBe("fast");
5224+
$scope.handleEditBondMode("balance-rr");
5225+
expect($scope.editInterface.bond_lacp_rate).toBe("");
5226+
});
5227+
5228+
it("clears hash policy if bond mode does not support it", () => {
5229+
makeController();
5230+
$scope.editInterface = {
5231+
bond_xmit_hash_policy: "",
5232+
bond_mode: "balance-rr",
5233+
};
5234+
$scope.handleEditBondMode("802.3ad");
5235+
expect($scope.editInterface.bond_xmit_hash_policy).toBe("layer2");
5236+
$scope.handleEditBondMode("balance-rr");
5237+
expect($scope.editInterface.bond_xmit_hash_policy).toBe("");
5238+
});
5239+
});
5240+
52005241
describe("canMarkAsDisconnected", () => {
52015242
it("returns false if nic type is not physical", () => {
52025243
makeController();

legacy/src/app/partials/node-details.html

+24-16
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,12 @@ <h3 class="p-heading--five">Bond details</h3>
18551855
<div class="p-form__group row">
18561856
<label for="bond-mode" class="p-form__label col-2">Bond mode</label>
18571857
<div class="p-form__control col-4">
1858-
<select name="bond-mode"
1859-
data-ng-model="editInterface.bond_mode"
1860-
data-ng-options="mode[0] as mode[1] for mode in bondOptions.modes">
1858+
<select
1859+
name="bond-mode"
1860+
ng-change="handleEditBondMode(editInterface.bond_mode)"
1861+
ng-model="editInterface.bond_mode"
1862+
ng-options="mode[0] as mode[1] for mode in bondOptions.modes"
1863+
>
18611864
</select>
18621865
</div>
18631866
</div>
@@ -1867,7 +1870,7 @@ <h3 class="p-heading--five">Bond details</h3>
18671870
<div class="p-form__control col-4">
18681871
<select name="xmit-hash-policy"
18691872
class="p-form-validation__input"
1870-
data-ng-model="editInterface.xmitHashPolicy"
1873+
data-ng-model="editInterface.bond_xmit_hash_policy"
18711874
data-ng-options="xmit[0] as xmit[1] for xmit in bondOptions.xmit_hash_policies">
18721875
</select>
18731876
<p class="p-form-validation__message" data-ng-if="showLACPRate() && modeAndPolicyCompliant()">
@@ -1879,7 +1882,7 @@ <h3 class="p-heading--five">Bond details</h3>
18791882
<label for="lacp-rate" class="p-form__label col-2">LACP rate</label>
18801883
<div class="p-form__control col-4">
18811884
<select name="lacp-rate"
1882-
data-ng-model="editInterface.lacpRate"
1885+
data-ng-model="editInterface.bond_lacp_rate"
18831886
data-ng-options="rate[0] as rate[1] for rate in bondOptions.lacp_rates">
18841887
</select>
18851888
</div>
@@ -1981,7 +1984,12 @@ <h3 class="p-heading--five">Advanced options</h3>
19811984
<div class="p-form__group row">
19821985
<label for="link-monitoring" class="p-form__label col-2">Link monitoring</label>
19831986
<div class="p-form__control col-4">
1984-
<select name="link-monitoring" id="link-monitoring" data-ng-model="editInterfaceLinkMonitoring">
1987+
<select
1988+
id="link-monitoring"
1989+
name="link-monitoring"
1990+
ng-change="handleEditLinkMonitoring(editInterfaceLinkMonitoring)"
1991+
ng-model="editInterfaceLinkMonitoring"
1992+
>
19851993
<option value="">No link monitoring</option>
19861994
<option value="mii">MII link monitoring</option>
19871995
</select>
@@ -2137,32 +2145,32 @@ <h2 class="p-heading--four">Create bond</h2>
21372145
</td>
21382146
<td class="p-table__col--status p-double-row" aria-label="Link and interface speed">
21392147
<div class="p-double-row__icon-container">
2140-
<span ng-if="!isBond(interface) && !isBridge(interface)">
2148+
<span ng-if="!isBond(parent) && !isBridge(parent)">
21412149
<span
21422150
aria-describedby="not-connected-tooltip"
21432151
class="p-tooltip--top-left"
2144-
ng-if="!isInterfaceConnected(interface)"
2152+
ng-if="!isInterfaceConnected(parent)"
21452153
>
21462154
<i class="p-icon--error"></i>
21472155
<span class="p-tooltip__message" role="tooltip" id="not-connected-tooltip">This interface is disconnected.</span>
21482156
</span>
21492157
<span
21502158
aria-describedby="link-speed-tooltip"
21512159
class="p-tooltip--top-left"
2152-
ng-if="isInterfaceConnected(interface) && interface.link_speed < interface.interface_speed"
2160+
ng-if="isInterfaceConnected(parent) && parent.link_speed < parent.interface_speed"
21532161
>
21542162
<i class="p-icon--warning"></i>
21552163
<span class="p-tooltip__message" role="tooltip" id="link-speed-tooltip">Link connected to slow interface.</span>
21562164
</span>
21572165
<i
21582166
class="p-icon--placeholder"
2159-
ng-if="isInterfaceConnected(interface) && interface.link_speed === interface.interface_speed">
2167+
ng-if="isInterfaceConnected(parent) && parent.link_speed === parent.interface_speed">
21602168
</i>
21612169
</span>
21622170
</div>
21632171
<div class="p-double-row__rows-container--icon">
2164-
<span ng-if="!isBond(interface) && !isBridge(interface)">
2165-
{$ formatSpeedUnits(interface.link_speed) $}/{$ formatSpeedUnits(interface.interface_speed) $}
2172+
<span ng-if="!isBond(parent) && !isBridge(parent)">
2173+
{$ formatSpeedUnits(parent.link_speed) $}/{$ formatSpeedUnits(parent.interface_speed) $}
21662174
</span>
21672175
</div>
21682176
</td>
@@ -2370,7 +2378,7 @@ <h3 class="p-heading--five">Bond details</h3>
23702378
<div class="p-form__control col-4">
23712379
<select name="xmit-hash-policy"
23722380
class="p-form-validation__input"
2373-
data-ng-model="newBondInterface.xmitHashPolicy"
2381+
data-ng-model="newBondInterface.bond_xmit_hash_policy"
23742382
data-ng-options="xmit[0] as xmit[1] for xmit in bondOptions.xmit_hash_policies">
23752383
</select>
23762384
<p class="p-form-validation__message" data-ng-if="showLACPRate() && modeAndPolicyCompliant()">
@@ -2382,7 +2390,7 @@ <h3 class="p-heading--five">Bond details</h3>
23822390
<label for="lacp-rate" class="p-form__label col-2">LACP rate</label>
23832391
<div class="p-form__control col-4">
23842392
<select name="lacp-rate"
2385-
data-ng-model="newBondInterface.lacpRate"
2393+
data-ng-model="newBondInterface.bond_lacp_rate"
23862394
data-ng-options="rate[0] as rate[1] for rate in bondOptions.lacp_rates">
23872395
</select>
23882396
</div>
@@ -3228,7 +3236,7 @@ <h2 class="u-float--left">Create bond</h2>
32283236
<label for="lacp-rate" class="p-form__label">LACP rate</label>
32293237
<div class="p-form__control">
32303238
<select name="lacp-rate"
3231-
data-ng-model="newBondInterface.lacpRate"
3239+
data-ng-model="newBondInterface.bond_lacp_rate"
32323240
data-ng-options="rate[0] as rate[1] for rate in bondOptions.lacp_rates">
32333241
</select>
32343242
</div>
@@ -3237,7 +3245,7 @@ <h2 class="u-float--left">Create bond</h2>
32373245
<label for="xmit-hash-policy" class="p-form__label">XMIT hash policy</label>
32383246
<div class="p-form__control">
32393247
<select name="xmit-hash-policy"
3240-
data-ng-model="newBondInterface.xmitHashPolicy"
3248+
data-ng-model="newBondInterface.bond_xmit_hash_policy"
32413249
data-ng-options="xmit[0] as xmit[1] for xmit in bondOptions.xmit_hash_policies">
32423250
</select>
32433251
</div>

0 commit comments

Comments
 (0)