Add protection from pyroute crashed

It may happen that if pyroute crashed with a dump interrupted,
and the exception is not properly handled, the agent will stop
processing further events

Change-Id: I2416393a3c45f2424aefd342380d7f9e07df9123
This commit is contained in:
Luis Tomas Bolivar 2023-04-14 10:25:15 +02:00
parent 16a7dccefe
commit 3d45f71476
2 changed files with 56 additions and 29 deletions

View File

@ -195,6 +195,7 @@ class NBOVNBGPDriver(driver_api.AgentDriverBase):
def _expose_provider_port(self, port_ips, logical_switch, bridge_device, def _expose_provider_port(self, port_ips, logical_switch, bridge_device,
bridge_vlan, proxy_cidrs=None): bridge_vlan, proxy_cidrs=None):
# Connect to OVN # Connect to OVN
try:
if wire_utils.wire_provider_port( if wire_utils.wire_provider_port(
self.ovn_routing_tables_routes, port_ips, bridge_device, self.ovn_routing_tables_routes, port_ips, bridge_device,
bridge_vlan, self.ovn_routing_tables, proxy_cidrs): bridge_vlan, self.ovn_routing_tables, proxy_cidrs):
@ -204,6 +205,10 @@ class NBOVNBGPDriver(driver_api.AgentDriverBase):
self._exposed_ips.setdefault(logical_switch, {}).update( self._exposed_ips.setdefault(logical_switch, {}).update(
{ip: {'bridge_device': bridge_device, {ip: {'bridge_device': bridge_device,
'bridge_vlan': bridge_vlan}}) 'bridge_vlan': bridge_vlan}})
except Exception as e:
LOG.exception("Unexpected exception while wiring provider port: "
"%s", e)
return False
def _withdraw_provider_port(self, port_ips, logical_switch, bridge_device, def _withdraw_provider_port(self, port_ips, logical_switch, bridge_device,
bridge_vlan, proxy_cidrs=None): bridge_vlan, proxy_cidrs=None):
@ -211,9 +216,13 @@ class NBOVNBGPDriver(driver_api.AgentDriverBase):
bgp_utils.withdraw_ips(port_ips) bgp_utils.withdraw_ips(port_ips)
# Disconnect IP from OVN # Disconnect IP from OVN
try:
wire_utils.unwire_provider_port( wire_utils.unwire_provider_port(
self.ovn_routing_tables_routes, port_ips, bridge_device, self.ovn_routing_tables_routes, port_ips, bridge_device,
bridge_vlan, self.ovn_routing_tables, proxy_cidrs) bridge_vlan, self.ovn_routing_tables, proxy_cidrs)
except Exception as e:
LOG.exception("Unexpected exception while unwiring provider port: "
"%s", e)
for ip in port_ips: for ip in port_ips:
if self._exposed_ips.get(logical_switch, {}).get(ip): if self._exposed_ips.get(logical_switch, {}).get(ip):
self._exposed_ips[logical_switch].pop(ip) self._exposed_ips[logical_switch].pop(ip)

View File

@ -317,6 +317,7 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
return False return False
# Connect to OVN # Connect to OVN
try:
if wire_utils.wire_provider_port( if wire_utils.wire_provider_port(
self.ovn_routing_tables_routes, port_ips, bridge_device, self.ovn_routing_tables_routes, port_ips, bridge_device,
bridge_vlan, self.ovn_routing_tables, proxy_cidrs, lladdr): bridge_vlan, self.ovn_routing_tables, proxy_cidrs, lladdr):
@ -324,6 +325,10 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
bgp_utils.announce_ips(port_ips) bgp_utils.announce_ips(port_ips)
return True return True
return False return False
except Exception as e:
LOG.exception("Unexpected exception while wiring provider port: "
"%s", e)
return False
def _expose_tenant_port(self, port, ip_version, exposed_ips=None, def _expose_tenant_port(self, port, ip_version, exposed_ips=None,
ovn_ip_rules=None): ovn_ip_rules=None):
@ -386,9 +391,14 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
provider_datapath) provider_datapath)
if not bridge_device: if not bridge_device:
return False return False
try:
return wire_utils.unwire_provider_port( return wire_utils.unwire_provider_port(
self.ovn_routing_tables_routes, port_ips, bridge_device, self.ovn_routing_tables_routes, port_ips, bridge_device,
bridge_vlan, self.ovn_routing_tables, proxy_cidrs, lladdr) bridge_vlan, self.ovn_routing_tables, proxy_cidrs, lladdr)
except Exception as e:
LOG.exception("Unexpected exception while unwiring provider port: "
"%s", e)
return False
def _get_bridge_for_datapath(self, datapath): def _get_bridge_for_datapath(self, datapath):
network_name, network_tag = self.sb_idl.get_network_name_and_tag( network_name, network_tag = self.sb_idl.get_network_name_and_tag(
@ -959,11 +969,15 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
cr_lrp_info['subnets_cidr'].append(ip) cr_lrp_info['subnets_cidr'].append(ip)
self.ovn_local_lrps.update({lrp: associated_cr_lrp}) self.ovn_local_lrps.update({lrp: associated_cr_lrp})
try:
if not wire_utils.wire_lrp_port( if not wire_utils.wire_lrp_port(
self.ovn_routing_tables_routes, ip, bridge_device, bridge_vlan, self.ovn_routing_tables_routes, ip, bridge_device,
self.ovn_routing_tables, cr_lrp_ips): bridge_vlan, self.ovn_routing_tables, cr_lrp_ips):
LOG.warning("Not able to expose subnet with IP %s", ip) LOG.warning("Not able to expose subnet with IP %s", ip)
return return
except Exception as e:
LOG.exception("Unexpected exception while wiring lrp port: %s", e)
return
if ovn_ip_rules: if ovn_ip_rules:
ovn_ip_rules.pop(ip, None) ovn_ip_rules.pop(ip, None)
@ -1024,9 +1038,13 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
linux_net.delete_exposed_ips(vms_on_net, CONF.bgp_nic) linux_net.delete_exposed_ips(vms_on_net, CONF.bgp_nic)
# Disconnect the network to OVN # Disconnect the network to OVN
try:
wire_utils.unwire_lrp_port( wire_utils.unwire_lrp_port(
self.ovn_routing_tables_routes, ip, bridge_device, bridge_vlan, self.ovn_routing_tables_routes, ip, bridge_device, bridge_vlan,
self.ovn_routing_tables, cr_lrp_ips) self.ovn_routing_tables, cr_lrp_ips)
except Exception as e:
LOG.exception("Unexpected exception while unwiring lrp port: %s",
e)
@lockutils.synchronized('bgp') @lockutils.synchronized('bgp')
def expose_subnet(self, ip, row): def expose_subnet(self, ip, row):