Use "ip addr replace" when adding IP addresses

Uses the idempotent "replace" action while adding IP addresses.
This way the action will not fail if this IP already exists on the interface.

Change-Id: I2cbe40a3686335896889dda86bc1b0326eb2e066
Signed-off-by: Stanislav Datskevych <me@nek0.net>
This commit is contained in:
Stanislav Datskevych
2026-02-13 10:00:14 +01:00
parent 74bd196bb8
commit f41f282fdf
4 changed files with 32 additions and 6 deletions

View File

@@ -117,15 +117,15 @@ function migrate_ip_from_nic {
if [[ -n "${ip}" && -n "${prefix}" ]]; then
ip addr flush dev ${src_nic}
if [ $? -ne 0 ] ; then
ip addr add ${ip}/${prefix} dev ${src_nic}
ip addr replace ${ip}/${prefix} dev ${src_nic}
echo "Error while flushing IP from ${src_nic}."
exit 1
fi
ip addr add ${ip}/${prefix} dev "${bridge_name}"
ip addr replace ${ip}/${prefix} dev "${bridge_name}"
if [ $? -ne 0 ] ; then
echo "Error assigning IP to bridge "${bridge_name}"."
ip addr add ${ip}/${prefix} dev ${src_nic}
ip addr replace ${ip}/${prefix} dev ${src_nic}
exit 1
fi
elif [[ -n "${bridge_ip}" && -n "${bridge_prefix}" ]]; then

View File

@@ -54,15 +54,15 @@ function migrate_ip_from_nic {
if [[ -n "${ip}" && -n "${prefix}" ]]; then
ip addr flush dev ${src_nic}
if [ $? -ne 0 ] ; then
ip addr add ${ip}/${prefix} dev ${src_nic}
ip addr replace ${ip}/${prefix} dev ${src_nic}
echo "Error while flushing IP from ${src_nic}."
exit 1
fi
ip addr add ${ip}/${prefix} dev "${bridge_name}"
ip addr replace ${ip}/${prefix} dev "${bridge_name}"
if [ $? -ne 0 ] ; then
echo "Error assigning IP to bridge "${bridge_name}"."
ip addr add ${ip}/${prefix} dev ${src_nic}
ip addr replace ${ip}/${prefix} dev ${src_nic}
exit 1
fi
elif [[ -n "${bridge_ip}" && -n "${bridge_prefix}" ]]; then

View File

@@ -0,0 +1,13 @@
---
# To create a new release note related to a specific chart:
# reno new <chart_name>
#
# To create a new release note for a common change (when multiple charts
# are changed):
# reno new common
neutron:
- |
Use `ip add replace` instead of `ip addr add` in the init script to
make it idempotent and avoid errors when the script tries to assign
the same IP address to the interface on subsequent runs.
...

View File

@@ -0,0 +1,13 @@
---
# To create a new release note related to a specific chart:
# reno new <chart_name>
#
# To create a new release note for a common change (when multiple charts
# are changed):
# reno new common
ovn:
- |
Use `ip add replace` instead of `ip addr add` in the init script to
make it idempotent and avoid errors when the script tries to assign
the same IP address to the interface on subsequent runs.
...