Skip to content

Commit f09ca4c

Browse files
committed
Improve validation of the input variables in wait_for_interface_or_ip
Introduce an explicit check for IRONIC_IP, allowing PROVISIONING_INTERFACE to be tested separately, to improve quality and readability. Moreover, whenever PROVISIONING_INTERFACE is not set by the user, function get_provisioning_interface attempts to determine one, or provide "provisioning" as default value. However this can cause confusing errors down the line. So, also remove this default value and fail gracefully, with proper logging, if the PROVISIONING_INTERFACE value is not detected. Signed-off-by: Marco Chiappero <[email protected]>
1 parent 8e987bf commit f09ca4c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

scripts/ironic-common.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ get_provisioning_interface()
4646
return
4747
fi
4848

49-
local interface="provisioning"
49+
local interface=""
5050

5151
for mac in ${PROVISIONING_MACS//,/ }; do
5252
if ip -br link show up | grep -i "$mac" &>/dev/null; then
@@ -132,13 +132,24 @@ wait_for_interface_or_ip()
132132

133133
export PROVISIONING_INTERFACE="${IFACE_OF_IP}"
134134
export IRONIC_IP="${PARSED_IP}"
135-
else
135+
elif [[ -n "${IRONIC_IP}" ]]; then
136+
local PARSED_IP
137+
PARSED_IP="$(parse_ip_address "${IRONIC_IP}")"
138+
if [[ -z "${PARSED_IP}" ]]; then
139+
return 1
140+
fi
141+
142+
export IRONIC_IP="${PARSED_IP}"
143+
elif [[ -n "${PROVISIONING_INTERFACE}" ]]; then
136144
until [[ -n "$IRONIC_IP" ]]; do
137145
echo "Waiting for ${PROVISIONING_INTERFACE} interface to be configured"
138146
IRONIC_IP="$(ip -br add show scope global up dev "${PROVISIONING_INTERFACE}" | awk '{print $3}' | sed -e 's%/.*%%' | head -n 1)"
139147
export IRONIC_IP
140148
sleep 1
141149
done
150+
else
151+
echo "Cannot determine an interface or an IP for binding and creating URLs"
152+
return 1
142153
fi
143154

144155
# If the IP contains a colon, then it's an IPv6 address, and the HTTP

0 commit comments

Comments
 (0)