Browse Source

Merge "[OVN] Make delete_router_port() less error prone" into stable/train

changes/17/785617/1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
b0b334d307
2 changed files with 31 additions and 5 deletions
  1. +13
    -5
      networking_ovn/common/ovn_client.py
  2. +18
    -0
      networking_ovn/tests/unit/l3/test_l3_ovn.py

+ 13
- 5
networking_ovn/common/ovn_client.py View File

@ -26,6 +26,7 @@ from neutron_lib.api.definitions import segment as segment_def
from neutron_lib import constants as const
from neutron_lib import context as n_context
from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory
from neutron_lib.plugins import utils as p_utils
@ -1519,14 +1520,18 @@ class OVNClient(object):
router_id = router_id or ovn_port.external_ids.get(
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY)
if not router_id:
if port and not router_id:
router_id = port.get('device_id')
router = None
if router_id:
router = self._l3_plugin.get_router(context, router_id)
try:
router = self._l3_plugin.get_router(context, router_id)
except l3_exc.RouterNotFound:
# If the router is gone, the router port is also gone
port_removed = True
if not router.get(l3.EXTERNAL_GW_INFO):
if not router or not router.get(l3.EXTERNAL_GW_INFO):
if port_removed:
self._delete_lrouter_port(port_id, router_id, txn=txn)
return
@ -1540,12 +1545,15 @@ class OVNClient(object):
cidr = None
for sid in subnet_ids:
subnet = self._plugin.get_subnet(context, sid)
try:
subnet = self._plugin.get_subnet(context, sid)
except n_exc.SubnetNotFound:
continue
if subnet['ip_version'] == 4:
cidr = subnet['cidr']
break
if router and utils.is_snat_enabled(router) and cidr:
if utils.is_snat_enabled(router) and cidr:
self.update_nat_rules(
router, networks=[cidr], enable_snat=False, txn=txn)


+ 18
- 0
networking_ovn/tests/unit/l3/test_l3_ovn.py View File

@ -28,6 +28,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants
from neutron_lib import exceptions as n_exc
from neutron_lib.exceptions import availability_zone as az_exc
from neutron_lib.exceptions import l3 as l3_exc
from neutron_lib.plugins import constants as plugin_constants
from neutron_lib.plugins import directory
from oslo_config import cfg
@ -356,6 +357,23 @@ class OVNL3RouterPlugin(test_mech_driver.OVNMechanismDriverTestCase):
ovn_const.OVN_NETWORK_NAME_EXT_ID_KEY:
utils.ovn_name(self.fake_network['id'])})
@mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin.get_router')
@mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.get_port')
def test_remove_router_interface_router_not_found(self, get_port,
get_router):
router_id = 'router-id'
interface_info = {'port_id': 'router-port-id'}
get_port.side_effect = n_exc.PortNotFound(port_id='router-port-id')
get_router.side_effect = l3_exc.RouterNotFound(
router_id='router-id')
self.l3_inst.remove_router_interface(
self.context, router_id, interface_info)
get_router.assert_called_once_with(mock.ANY, 'router-id')
self.l3_inst._ovn.lrp_del.assert_called_once_with(
'lrp-router-port-id', 'neutron-router-id', if_exists=True)
self.del_rev_p.assert_called_once_with(
'router-port-id', ovn_const.TYPE_ROUTER_PORTS)
@mock.patch('neutron.db.extraroute_db.ExtraRoute_dbonly_mixin.'
'update_router')
@mock.patch('neutron.db.l3_db.L3_NAT_dbonly_mixin.get_router')


Loading…
Cancel
Save