return True
return False
- def delete_namespace_on_host(self, context, host, router_id):
- """Delete the given router namespace on the host."""
- agent = self._get_agent_by_type_and_host(
- context, q_const.AGENT_TYPE_L3, host)
- agent_id = str(agent.id)
- with context.session.begin(subtransactions=True):
- (context.session.query(l3agent_sch_db.RouterL3AgentBinding).
- filter_by(router_id=router_id, l3_agent_id=agent_id).
- delete(synchronize_session=False))
- LOG.debug('Deleted router %(router_id)s on agent.id %(id)s',
- {'router_id': router_id,
- 'id': agent.id})
-
def dvr_deletens_if_no_vm(self, context, port_id):
"""Delete the DVR namespace if no VM exists."""
router_ids = self.get_dvr_routers_by_vmportid(context, port_id)
# unbind this port from router
dvr_binding['router_id'] = None
dvr_binding.update(dvr_binding)
- self.delete_namespace_on_host(context, port_host, router_id)
- info = {'router_id': router_id, 'host': port_host}
+ agent = self._get_agent_by_type_and_host(context,
+ q_const.AGENT_TYPE_L3,
+ port_host)
+ info = {'router_id': router_id, 'host': port_host,
+ 'agent_id': str(agent.id)}
removed_router_info.append(info)
- LOG.debug('Deleted router namespace %(router_id)s '
- 'on host %(host)s', info)
+ LOG.debug('Router namespace %(router_id)s on host %(host)s '
+ 'to be deleted', info)
return removed_router_info
def bind_snat_router(self, context, router_id, chosen_agent):
import uuid
import webob
+from neutron.common import constants
from neutron.common import exceptions as exc
from neutron import context
from neutron.extensions import multiprovidernet as mpnet
self.assertIsNone(l3plugin.disassociate_floatingips(ctx, port_id))
+class TestMl2DvrPortsV2(TestMl2PortsV2):
+ def setUp(self):
+ super(TestMl2DvrPortsV2, self).setUp()
+ extensions = ['router',
+ constants.L3_AGENT_SCHEDULER_EXT_ALIAS,
+ constants.L3_DISTRIBUTED_EXT_ALIAS]
+ self.plugin = manager.NeutronManager.get_plugin()
+ self.l3plugin = mock.Mock()
+ type(self.l3plugin).supported_extension_aliases = (
+ mock.PropertyMock(return_value=extensions))
+ self.service_plugins = {'L3_ROUTER_NAT': self.l3plugin}
+
+ def test_delete_last_vm_port(self):
+ fip_set = set()
+ ns_to_delete = {'host': 'vmhost', 'agent_id': 'vm_l3_agent',
+ 'router_id': 'my_router'}
+
+ with contextlib.nested(
+ mock.patch.object(manager.NeutronManager,
+ 'get_service_plugins',
+ return_value=self.service_plugins),
+ self.port(do_delete=False, device_owner='compute:None'),
+ mock.patch.object(self.l3plugin, 'notify_routers_updated'),
+ mock.patch.object(self.l3plugin, 'disassociate_floatingips',
+ return_value=fip_set),
+ mock.patch.object(self.l3plugin, 'dvr_deletens_if_no_vm',
+ return_value=[ns_to_delete]),
+ mock.patch.object(self.l3plugin, 'remove_router_from_l3_agent')
+ ) as (get_service_plugin, port, notify, disassociate_floatingips,
+ ddinv, remove_router_from_l3_agent):
+
+ port_id = port['port']['id']
+ self.plugin.delete_port(self.context, port_id)
+
+ notify.assert_has_calls([mock.call(self.context, fip_set)])
+ remove_router_from_l3_agent.assert_has_calls([
+ mock.call(self.context, ns_to_delete['agent_id'],
+ ns_to_delete['router_id'])
+ ])
+
+ def test_delete_last_vm_port_with_floatingip(self):
+ ns_to_delete = {'host': 'vmhost', 'agent_id': 'vm_l3_agent',
+ 'router_id': 'my_router'}
+ fip_set = set([ns_to_delete['router_id']])
+
+ with contextlib.nested(
+ mock.patch.object(manager.NeutronManager,
+ 'get_service_plugins',
+ return_value=self.service_plugins),
+ self.port(do_delete=False, device_owner='compute:None'),
+ mock.patch.object(self.l3plugin, 'notify_routers_updated'),
+ mock.patch.object(self.l3plugin, 'disassociate_floatingips',
+ return_value=fip_set),
+ mock.patch.object(self.l3plugin, 'dvr_deletens_if_no_vm',
+ return_value=[ns_to_delete]),
+ mock.patch.object(self.l3plugin, 'remove_router_from_l3_agent')
+ ) as (get_service_plugins, port, notify, disassociate_floatingips,
+ ddinv, remove_router_from_l3_agent):
+
+ port_id = port['port']['id']
+ self.plugin.delete_port(self.context, port_id)
+
+ notify.assert_has_calls([mock.call(self.context, fip_set)])
+ remove_router_from_l3_agent.assert_has_calls([
+ mock.call(self.context, ns_to_delete['agent_id'],
+ ns_to_delete['router_id'])
+ ])
+
+
class TestMl2PortBinding(Ml2PluginV2TestCase,
test_bindings.PortBindingsTestCase):
# Test case does not set binding:host_id, so ml2 does not attempt