Skip to content

Commit

Permalink
MGMT-16841: Failed to add host when infraenv has networkType of DHCP …
Browse files Browse the repository at this point in the history
…[BACKPORT 2.9] (#2593)

* Fix BMC form with no nmState

* Use format string for nmState
  • Loading branch information
jgyselov authored Jun 4, 2024
1 parent caeed72 commit 1568eed
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,25 @@ const emptyValues: AddBmcValues = {
bootMACAddress: '',
disableCertificateVerification: true, // TODO(mlibra)
online: true,
nmState:
'interfaces:\n\
- name: <nic1_name>\n\
type: ethernet\n\
state: up\n\
ipv4:\n\
address:\n\
- ip: <ip_address>\n\
prefix-length: 24\n\
enabled: true\n\
dns-resolver:\n\
config:\n\
server:\n\
- <dns_ip_address>\n\
routes:\n\
config:\n\
- destination: 0.0.0.0/0\n\
next-hop-address: <next_hop_ip_address>\n\
next-hop-interface: <next_hop_nic1_name>\n\
',
nmState: `interfaces:
- name: <nic1_name>
type: ethernet
state: up
ipv4:
address:
- ip: <ip_address>
prefix-length: 24
enabled: true
dns-resolver:
config:
server:
- <dns_ip_address>
routes:
config:
- destination: 0.0.0.0/0
next-hop-address: <next_hop_ip_address>
next-hop-interface: <next_hop_nic1_name>
`,
macMapping: [{ macAddress: '', name: '' }],
};

Expand All @@ -212,9 +211,12 @@ const getInitValues = (
nmState?: NMStateK8sResource,
secret?: SecretK8sResource,
isEdit?: boolean,
addNMState?: boolean,
): AddBmcValues => {
let values = emptyValues;

if (isEdit) {
return {
values = {
name: bmh?.metadata?.name || '',
hostname: bmh?.metadata?.annotations?.[BMH_HOSTNAME_ANNOTATION] || '',
bmcAddress: bmh?.spec?.bmc?.address || '',
Expand All @@ -226,9 +228,12 @@ const getInitValues = (
nmState: nmState ? yaml.dump(nmState?.spec?.config) : emptyValues.nmState,
macMapping: nmState?.spec?.interfaces || [{ macAddress: '', name: '' }],
};
} else {
return emptyValues;
}

if (!addNMState) {
values.nmState = '';
}
return values;
};

const BMCForm: React.FC<BMCFormProps> = ({
Expand All @@ -254,12 +259,16 @@ const BMCForm: React.FC<BMCFormProps> = ({
setError(getErrorMessage(e));
}
};

const { t } = useTranslation();
const { initValues, validationSchema } = React.useMemo(() => {
const initValues = getInitValues(bmh, nmState, secret, isEdit);
const addNmState =
infraEnv.metadata?.labels && infraEnv.metadata?.labels['networkType'] === 'static';

const initValues = getInitValues(bmh, nmState, secret, isEdit, addNmState);
const validationSchema = getValidationSchema(usedHostnames, initValues.hostname, t);
return { initValues, validationSchema };
}, [usedHostnames, bmh, nmState, secret, isEdit, t]);
}, [infraEnv.metadata?.labels, usedHostnames, bmh, nmState, secret, isEdit, t]);

return (
<Formik
Expand Down

0 comments on commit 1568eed

Please sign in to comment.