From f41f282fdfe018affc3524ceaef049cc2f8a43b4 Mon Sep 17 00:00:00 2001 From: Stanislav Datskevych Date: Fri, 13 Feb 2026 10:00:14 +0100 Subject: [PATCH] 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 --- .../bin/_neutron-openvswitch-agent-init.sh.tpl | 6 +++--- ovn/templates/bin/_ovn-controller-init.sh.tpl | 6 +++--- releasenotes/notes/neutron-2af36e49a0a377c3.yaml | 13 +++++++++++++ releasenotes/notes/ovn-ffd84bb8c9e73b64.yaml | 13 +++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/neutron-2af36e49a0a377c3.yaml create mode 100644 releasenotes/notes/ovn-ffd84bb8c9e73b64.yaml diff --git a/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl b/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl index 4facfdc99f..efe360cda7 100644 --- a/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl +++ b/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl @@ -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 diff --git a/ovn/templates/bin/_ovn-controller-init.sh.tpl b/ovn/templates/bin/_ovn-controller-init.sh.tpl index 13fed73a77..648e7dd404 100644 --- a/ovn/templates/bin/_ovn-controller-init.sh.tpl +++ b/ovn/templates/bin/_ovn-controller-init.sh.tpl @@ -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 diff --git a/releasenotes/notes/neutron-2af36e49a0a377c3.yaml b/releasenotes/notes/neutron-2af36e49a0a377c3.yaml new file mode 100644 index 0000000000..c59120bf77 --- /dev/null +++ b/releasenotes/notes/neutron-2af36e49a0a377c3.yaml @@ -0,0 +1,13 @@ +--- +# To create a new release note related to a specific chart: +# reno new +# +# 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. +... diff --git a/releasenotes/notes/ovn-ffd84bb8c9e73b64.yaml b/releasenotes/notes/ovn-ffd84bb8c9e73b64.yaml new file mode 100644 index 0000000000..570ba51ddf --- /dev/null +++ b/releasenotes/notes/ovn-ffd84bb8c9e73b64.yaml @@ -0,0 +1,13 @@ +--- +# To create a new release note related to a specific chart: +# reno new +# +# 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. +...