Пример #1
0
 def _unbind_dvr_port_before_delete(self, context, router_id, port_host):
     filter_rtr = {
         'device_id': [router_id],
         'device_owner': [n_const.DEVICE_OWNER_DVR_INTERFACE]
     }
     int_ports = self._core_plugin.get_ports(
         n_utils.get_elevated_context(context), filters=filter_rtr)
     for port in int_ports:
         dvr_binding = (ml2_db.get_distributed_port_binding_by_host(
             context, port['id'], port_host))
         if dvr_binding:
             # unbind this port from router
             dvr_binding['router_id'] = None
             dvr_binding.update(dvr_binding)
Пример #2
0
 def test_get_distributed_port_binding_by_host_not_found(self):
     port = ml2_db.get_distributed_port_binding_by_host(
         self.ctx, 'foo_port_id', 'foo_host_id')
     self.assertIsNone(port)
Пример #3
0
    def get_dvr_routers_to_remove(self, context, deleted_port):
        """Returns info about which routers should be removed

        In case dvr serviceable port was deleted we need to check
        if any dvr routers should be removed from l3 agent on port's host
        """
        if not n_utils.is_dvr_serviced(deleted_port['device_owner']):
            return []

        admin_context = context.elevated()
        port_host = deleted_port[portbindings.HOST_ID]
        subnet_ids = [ip['subnet_id'] for ip in deleted_port['fixed_ips']]
        router_ids = self.get_dvr_routers_by_subnet_ids(
            admin_context, subnet_ids)

        if not router_ids:
            LOG.debug(
                'No DVR routers for this DVR port %(port)s '
                'on host %(host)s', {
                    'port': deleted_port['id'],
                    'host': port_host
                })
            return []
        agent = self._get_agent_by_type_and_host(context,
                                                 n_const.AGENT_TYPE_L3,
                                                 port_host)
        removed_router_info = []
        for router_id in router_ids:
            snat_binding = context.session.query(
                rb_model.RouterL3AgentBinding).filter_by(
                    router_id=router_id).filter_by(
                        l3_agent_id=agent.id).first()
            if snat_binding:
                # not removing from the agent hosting SNAT for the router
                continue
            subnet_ids = self.get_subnet_ids_on_router(admin_context,
                                                       router_id)
            if self._check_dvr_serviceable_ports_on_host(
                    admin_context, port_host, subnet_ids):
                continue
            filter_rtr = {
                'device_id': [router_id],
                'device_owner': [n_const.DEVICE_OWNER_DVR_INTERFACE]
            }
            int_ports = self._core_plugin.get_ports(admin_context,
                                                    filters=filter_rtr)
            for port in int_ports:
                dvr_binding = (ml2_db.get_distributed_port_binding_by_host(
                    context.session, port['id'], port_host))
                if dvr_binding:
                    # unbind this port from router
                    dvr_binding['router_id'] = None
                    dvr_binding.update(dvr_binding)

            info = {
                'router_id': router_id,
                'host': port_host,
                'agent_id': str(agent.id)
            }
            removed_router_info.append(info)
            LOG.debug('Router %(router_id)s on host %(host)s to be deleted',
                      info)
        return removed_router_info
Пример #4
0
 def test_get_distributed_port_binding_by_host_not_found(self):
     port = ml2_db.get_distributed_port_binding_by_host(
         self.ctx, 'foo_port_id', 'foo_host_id')
     self.assertIsNone(port)
Пример #5
0
 def test_get_distributed_port_binding_by_host_not_found(self):
     port_id = uuidutils.generate_uuid()
     host_id = uuidutils.generate_uuid()
     port = ml2_db.get_distributed_port_binding_by_host(
         self.ctx, port_id, host_id)
     self.assertIsNone(port)