From 89bf3cf7b81fe5cc3e22733a055705e59b05dc46 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Thu, 7 Apr 2022 09:04:50 -0400 Subject: [PATCH] neutron: migrate IP for bridges This patch makes a change to the Helm chart so that it migrates the IP addresse assigned to an interface to `br-ex`. It's assumed that if the operator put an IP address on that interface, they likely need it, and if they just had no IP address then it's there for L2 connectivity so nothing won't happen anyways. Change-Id: I17dc2e532dc8b472a5c5c16ff2ec2bdcfb5bfac5 --- neutron/Chart.yaml | 2 +- .../_neutron-openvswitch-agent-init.sh.tpl | 68 +++++++++++-------- releasenotes/notes/neutron.yaml | 1 + 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/neutron/Chart.yaml b/neutron/Chart.yaml index f7c1bdb90e..6e03fdab30 100644 --- a/neutron/Chart.yaml +++ b/neutron/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Neutron name: neutron -version: 0.2.13 +version: 0.2.14 home: https://docs.openstack.org/neutron/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Neutron/OpenStack_Project_Neutron_vertical.png sources: diff --git a/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl b/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl index 969f9d0fab..3283e09e7c 100644 --- a/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl +++ b/neutron/templates/bin/_neutron-openvswitch-agent-init.sh.tpl @@ -87,44 +87,57 @@ function migrate_ip { local src_nic=$(get_name_by_pci_id ${pci_id}) if [ -n "${src_nic}" ] ; then - set +e - ip=$(get_ip_address_from_interface ${src_nic}) - prefix=$(get_ip_prefix_from_interface ${src_nic}) - - # Enabling explicit error handling: We must avoid to lose the IP - # address in the migration process. Hence, on every error, we - # attempt to assign the IP back to the original NIC and exit. bridge_exists=$(ip a s "${bridge_name}" | grep "${bridge_name}" | cut -f2 -d':' 2> /dev/null) if [ -z "${bridge_exists}" ] ; then echo "Bridge "${bridge_name}" does not exist. Creating it on demand." init_ovs_dpdk_bridge "${bridge_name}" fi - bridge_ip=$(get_ip_address_from_interface "${bridge_name}") - bridge_prefix=$(get_ip_prefix_from_interface "${bridge_name}") + migrate_ip_from_nic ${src_nic} ${bridge_name} + fi +} - if [[ -n "${ip}" && -n "${prefix}" ]]; then - ip addr flush dev ${src_nic} - if [ $? -ne 0 ] ; then - ip addr add ${ip}/${prefix} dev ${src_nic} - echo "Error while flushing IP from ${src_nic}." - exit 1 - fi +function migrate_ip_from_nic { + src_nic=$1 + bridge_name=$2 - ip addr add ${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} - exit 1 - fi - elif [[ -n "${bridge_ip}" && -n "${bridge_prefix}" ]]; then - echo "Bridge '${bridge_name}' already has IP assigned. Keeping the same:: IP:[${bridge_ip}]; Prefix:[${bridge_prefix}]..." - else - echo "Interface ${name} has invalid IP address. IP:[${ip}]; Prefix:[${prefix}]..." + # Enabling explicit error handling: We must avoid to lose the IP + # address in the migration process. Hence, on every error, we + # attempt to assign the IP back to the original NIC and exit. + set +e + + ip=$(get_ip_address_from_interface ${src_nic}) + prefix=$(get_ip_prefix_from_interface ${src_nic}) + + bridge_ip=$(get_ip_address_from_interface "${bridge_name}") + bridge_prefix=$(get_ip_prefix_from_interface "${bridge_name}") + + ip link set ${bridge_name} up + + if [[ -n "${ip}" && -n "${prefix}" ]]; then + ip addr flush dev ${src_nic} + if [ $? -ne 0 ] ; then + ip addr add ${ip}/${prefix} dev ${src_nic} + echo "Error while flushing IP from ${src_nic}." exit 1 fi - set -e + + ip addr add ${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} + exit 1 + fi + elif [[ -n "${bridge_ip}" && -n "${bridge_prefix}" ]]; then + echo "Bridge '${bridge_name}' already has IP assigned. Keeping the same:: IP:[${bridge_ip}]; Prefix:[${bridge_prefix}]..." + elif [[ -z "${bridge_ip}" && -z "${ip}" ]]; then + echo "Interface and bridge have no ips configured. Leaving as is." + else + echo "Interface ${name} has invalid IP address. IP:[${ip}]; Prefix:[${prefix}]..." + exit 1 fi + + set -e } function get_pf_or_vf_pci { @@ -397,6 +410,7 @@ do if [ -n "$iface" ] && [ "$iface" != "null" ] then ovs-vsctl --no-wait --may-exist add-port $bridge $iface + migrate_ip_from_nic $iface $bridge if [[ $(get_dpdk_config_value ${DPDK_CONFIG} '.enabled') != "true" ]]; then ip link set dev $iface up fi diff --git a/releasenotes/notes/neutron.yaml b/releasenotes/notes/neutron.yaml index 6784610156..c97dc99d41 100644 --- a/releasenotes/notes/neutron.yaml +++ b/releasenotes/notes/neutron.yaml @@ -27,4 +27,5 @@ neutron: - 0.2.11 Improve health probe logging - 0.2.12 Fix infinite recursion deadlock on netns cleanup cron - 0.2.13 Enable taint toleration for Openstack services + - 0.2.14 Migrate IP from bridge for auto_bridge_add ...