From 1d00d2c58fb5cd3585e321e3eea54fc8ae0178d8 Mon Sep 17 00:00:00 2001 From: Luis Tomas Bolivar Date: Wed, 14 Jun 2023 16:50:39 +0200 Subject: [PATCH] Retry get_ovs_patch_port_ofport if empty port It seems sometimes we are getting [] instead of the ofport, possibly due to a race between creating the interface and attaching it to the ovs bridge. This ensure it is also retried in that case Change-Id: I2f0766c3a018336168c02ab77bbdfc9ed246a150 --- ovn_bgp_agent/drivers/openstack/utils/ovs.py | 20 +++++++++++++++++-- ovn_bgp_agent/drivers/openstack/utils/wire.py | 11 +--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ovn_bgp_agent/drivers/openstack/utils/ovs.py b/ovn_bgp_agent/drivers/openstack/utils/ovs.py index 5a7df532..0bbd3b6b 100644 --- a/ovn_bgp_agent/drivers/openstack/utils/ovs.py +++ b/ovn_bgp_agent/drivers/openstack/utils/ovs.py @@ -18,8 +18,10 @@ from ovsdbapp.backend.ovs_idl import connection from ovsdbapp.backend.ovs_idl import idlutils from ovsdbapp.schema.open_vswitch import impl_idl as idl_ovs import pyroute2 +import tenacity from ovn_bgp_agent import constants +from ovn_bgp_agent import exceptions as agent_exc import ovn_bgp_agent.privileged.ovs_vsctl from ovn_bgp_agent.utils import linux_net @@ -62,10 +64,24 @@ def get_ovs_patch_ports_info(bridge): return in_ports +@tenacity.retry( + retry=tenacity.retry_if_exception_type(agent_exc.PatchPortNotFound), + wait=tenacity.wait_fixed(1), + stop=tenacity.stop_after_delay(5), + reraise=True) def get_ovs_patch_port_ofport(patch): patch_name = "patch-{}-to-br-int".format(patch) - ofport = ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd( - 'ovs-vsctl', ['get', 'Interface', patch_name, 'ofport'])[0].rstrip() + try: + ofport = ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd( + 'ovs-vsctl', ['get', 'Interface', patch_name, 'ofport'] + )[0].rstrip() + except Exception: + raise agent_exc.PatchPortNotFound(localnet=patch) + if ofport == '[]': + # NOTE(ltomasbo): there is a chance the patch port interface was + # created but not yet added to ovs bridge, therefore it exists but + # has an empty ofport. We should retry in this case + raise agent_exc.PatchPortNotFound(localnet=patch) return ofport diff --git a/ovn_bgp_agent/drivers/openstack/utils/wire.py b/ovn_bgp_agent/drivers/openstack/utils/wire.py index 1d5f63f7..4f0c1e79 100644 --- a/ovn_bgp_agent/drivers/openstack/utils/wire.py +++ b/ovn_bgp_agent/drivers/openstack/utils/wire.py @@ -16,7 +16,6 @@ import pyroute2 from oslo_config import cfg from oslo_log import log as logging -import tenacity from ovn_bgp_agent import constants from ovn_bgp_agent.drivers.openstack.utils import ovs @@ -139,16 +138,8 @@ def unwire_provider_port(routing_tables_routes, port_ips, bridge_device, return True -@tenacity.retry( - retry=tenacity.retry_if_exception_type(agent_exc.PatchPortNotFound), - wait=tenacity.wait_fixed(1), - stop=tenacity.stop_after_delay(5), - reraise=True) def _ensure_updated_mac_tweak_flows(localnet, bridge_device, ovs_flows): - try: - ofport = ovs.get_ovs_patch_port_ofport(localnet) - except Exception: - raise agent_exc.PatchPortNotFound(localnet=localnet) + ofport = ovs.get_ovs_patch_port_ofport(localnet) if ofport not in ovs_flows[bridge_device]['in_port']: ovs_flows[bridge_device]['in_port'].append(ofport) ovs.ensure_mac_tweak_flows(bridge_device,