Skip to content

Commit b9c1ebe

Browse files
authored
MGMT-19389: nmstate not generated well with bonds - 2.36 (#2722)
* Solving problems with nmstate with VLAN+bonds * Solving problems with nmstate with VLAN+bonds-followup * Adjusting tests for static ip
1 parent 2cf99be commit b9c1ebe

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

Diff for: libs/ui-lib-tests/cypress/integration/static-ip/2-configure-static-ip-host-specific.cy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ describe(`Assisted Installer Static IP Host specific Configuration`, () => {
2222

2323
staticIpPage.getFormViewSelect().should('be.checked');
2424
staticIpPage.getAddMoreHosts().should('be.disabled');
25-
staticIpPage.hostSpecificMacAddress(0).type('00:00:5e:00:53:af');
25+
staticIpPage.hostSpecificMacAddress(0).clear().type('00:00:5e:00:53:af');
2626
staticIpPage.hostSpecificIpv4Address(0).type('192.168.2.38');
2727

2828
staticIpPage.hostSpecificMacAddress(1).should('not.exist');
2929
staticIpPage.getAddMoreHosts().should('be.enabled');
3030
staticIpPage.getAddMoreHosts().click();
31-
staticIpPage.hostSpecificMacAddress(1).type('00:00:5e:00:53:ae');
31+
staticIpPage.hostSpecificMacAddress(1).clear().type('00:00:5e:00:53:ae');
3232
staticIpPage.hostSpecificIpv4Address(1).type('192.168.2.39');
3333

3434
commonActions.verifyNextIsEnabled();

Diff for: libs/ui-lib/lib/ocm/components/clusterConfiguration/staticIp/data/formDataFromInfraEnvField.ts

+28-10
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@ type ParsedFormViewYaml = {
4040
nmstate: Nmstate;
4141
};
4242

43-
const findFirstRealInterface = (interfaces: NmstateInterface[]): NmstateInterface | undefined => {
44-
return interfaces.find(
45-
(currentInterface) => !isDummyInterface(currentInterface.name),
46-
) as unknown as NmstateInterface | undefined;
43+
const findAllRealInterfaces = (interfaces: NmstateInterface[]): NmstateInterface[] => {
44+
return interfaces.filter((currentInterface) => !isDummyInterface(currentInterface.name));
4745
};
48-
4946
const parseYaml = (yaml: string): ParsedFormViewYaml => {
5047
const lines = yaml.split('\n');
5148
const lastCommentIdx = findLastIndex(lines, (line) => line.startsWith(YAML_COMMENT_CHAR));
@@ -133,9 +130,26 @@ const getFormViewHost = (
133130
}
134131

135132
const { nmstate } = parseYaml(infraEnvHost.networkYaml);
136-
const realInterface = findFirstRealInterface(nmstate.interfaces);
137133

138-
if (!realInterface) {
134+
const realInterfaces = findAllRealInterfaces(nmstate.interfaces);
135+
const firstInterface = realInterfaces[0];
136+
const secondInterface = realInterfaces[1]; // Puede ser undefined
137+
138+
let bondInterface: NmstateInterface | undefined;
139+
let nonBondInterface: NmstateInterface | undefined;
140+
141+
if (firstInterface) {
142+
if (firstInterface.type === NmstateInterfaceType.BOND) {
143+
bondInterface = firstInterface;
144+
nonBondInterface = secondInterface;
145+
} else {
146+
nonBondInterface = firstInterface;
147+
bondInterface =
148+
secondInterface?.type === NmstateInterfaceType.BOND ? secondInterface : undefined;
149+
}
150+
}
151+
152+
if (!realInterfaces) {
139153
//handle case 2
140154
return null;
141155
}
@@ -153,16 +167,20 @@ const getFormViewHost = (
153167
useBond: false,
154168
};
155169

156-
if (realInterface.type === NmstateInterfaceType.BOND) {
170+
if (bondInterface?.type === NmstateInterfaceType.BOND) {
157171
ret.useBond = true;
158-
ret.bondType = realInterface['link-aggregation'].mode;
172+
ret.bondType = bondInterface['link-aggregation'].mode;
159173
ret.bondPrimaryInterface = infraEnvHost.macInterfaceMap[0].macAddress ?? '';
160174
ret.bondSecondaryInterface = infraEnvHost.macInterfaceMap[1].macAddress ?? '';
161175
}
162176

163177
for (const protocolVersion of getShownProtocolVersions(protocolType)) {
164-
ret.ips[protocolVersion] = getIpAddress(realInterface, protocolVersion);
178+
const interfaceToUse = nonBondInterface || bondInterface;
179+
if (interfaceToUse) {
180+
ret.ips[protocolVersion] = getIpAddress(interfaceToUse, protocolVersion);
181+
}
165182
}
183+
166184
return ret;
167185
};
168186

Diff for: libs/ui-lib/lib/ocm/components/clusterConfiguration/staticIp/data/formDataToInfraEnvField.ts

+28
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ const getNmstateObject = (
7474
hostIp,
7575
getPrefixLength(networkWide, protocolVersion),
7676
);
77+
if (networkWide.useVlan && networkWide.vlanId) {
78+
if (bondType && hasBondsConfigured) {
79+
interfaces.push(
80+
getInterface(
81+
BOND_NIC_NAME,
82+
realProtocolConfigs,
83+
networkWide,
84+
bondType,
85+
hasBondsConfigured,
86+
true,
87+
),
88+
);
89+
}
90+
}
7791
} else {
7892
//this happens when a host was particall configured, or not configured at all
7993
const protocolConfigs = {
@@ -86,6 +100,20 @@ const getNmstateObject = (
86100
interfaces.push(
87101
getInterface(nicName, protocolConfigs, networkWide, bondType, hasBondsConfigured),
88102
);
103+
if (bondType && hasBondsConfigured) {
104+
interfaces.push(
105+
getInterface(
106+
BOND_NIC_NAME,
107+
protocolConfigs,
108+
networkWide,
109+
bondType,
110+
hasBondsConfigured,
111+
true,
112+
),
113+
);
114+
}
115+
// eslint-disable-next-line no-console
116+
console.log(interfaces);
89117
}
90118

91119
routeConfigs.push(

Diff for: libs/ui-lib/lib/ocm/components/clusterConfiguration/staticIp/data/nmstateYaml.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ export const getInterface = (
104104
networkWide: FormViewNetworkWideValues,
105105
bondType?: string,
106106
hasBondsConfigured?: boolean,
107+
createBondInterface?: boolean,
107108
): NmstateInterface => {
108-
if (networkWide.useVlan && networkWide.vlanId) {
109+
if (networkWide.useVlan && networkWide.vlanId && !createBondInterface) {
109110
return {
110111
name: getVlanNicName(nicName, networkWide.vlanId),
111112
type: NmstateInterfaceType.VLAN,

0 commit comments

Comments
 (0)