Merge "Remove _router_exists method"
This commit is contained in:
commit
bac2981e4d
|
@ -1517,13 +1517,6 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
|||
filters = filters or {}
|
||||
return l3_obj.FloatingIP.count(context, **filters)
|
||||
|
||||
def _router_exists(self, context, router_id):
|
||||
try:
|
||||
self.get_router(context.elevated(), router_id)
|
||||
return True
|
||||
except l3_exc.RouterNotFound:
|
||||
return False
|
||||
|
||||
def prevent_l3_port_deletion(self, context, port_id):
|
||||
"""Checks to make sure a port is allowed to be deleted.
|
||||
|
||||
|
@ -1561,7 +1554,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
|||
"%(port_id)s no longer exists, allowing deletion.",
|
||||
{'f_id': port['device_id'], 'port_id': port['id']})
|
||||
return
|
||||
elif not self._router_exists(context, port['device_id']):
|
||||
elif not l3_obj.Router.objects_exist(context.elevated(),
|
||||
id=port['device_id']):
|
||||
LOG.debug("Router %(router_id)s corresponding to port "
|
||||
"%(port_id)s no longer exists, allowing deletion.",
|
||||
{'router_id': port['device_id'],
|
||||
|
|
|
@ -22,7 +22,6 @@ from neutron_lib.callbacks import resources
|
|||
from neutron_lib import constants as n_const
|
||||
from neutron_lib import 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 plugin_utils
|
||||
|
@ -217,9 +216,9 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase):
|
|||
'device_owner': n_const.DEVICE_OWNER_ROUTER_INTF,
|
||||
'device_id': '44', 'id': 'f',
|
||||
'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]}
|
||||
self.db.get_router = mock.Mock()
|
||||
self.db.get_router.side_effect = l3_exc.RouterNotFound(router_id='44')
|
||||
self.db.prevent_l3_port_deletion(mock.Mock(), None)
|
||||
with mock.patch.object(l3_obj.Router, 'objects_exist',
|
||||
return_value=False):
|
||||
self.db.prevent_l3_port_deletion(mock.Mock(), None)
|
||||
|
||||
@mock.patch.object(directory, 'get_plugin')
|
||||
def test_prevent_l3_port_existing_router(self, gp):
|
||||
|
|
|
@ -347,11 +347,11 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
|
|||
plugin = mock.Mock()
|
||||
directory.add_plugin(plugin_constants.CORE, plugin)
|
||||
plugin.get_port.return_value = port
|
||||
self.mixin._router_exists = mock.Mock(return_value=True)
|
||||
self.assertRaises(exceptions.ServicePortInUse,
|
||||
self.mixin.prevent_l3_port_deletion,
|
||||
self.ctx,
|
||||
port['id'])
|
||||
with mock.patch.object(router_obj.Router, 'objects_exist',
|
||||
return_value=True):
|
||||
self.assertRaises(exceptions.ServicePortInUse,
|
||||
self.mixin.prevent_l3_port_deletion,
|
||||
self.ctx, port['id'])
|
||||
|
||||
def test_prevent_delete_floatingip_agent_gateway_port(self):
|
||||
port = {
|
||||
|
|
Loading…
Reference in New Issue