Пример #1
0
 def test_ensure_dvr_port_binding(self):
     network_id = "foo_network_id"
     port_id = "foo_port_id"
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_dvr_port_binding(self.ctx.session, port_id, "foo_host", router.id)
     expected = self.ctx.session.query(models.DVRPortBinding).filter_by(port_id=port_id).one()
     self.assertEqual(port_id, expected.port_id)
Пример #2
0
 def test_ensure_dvr_port_binding_multiple_bindings(self):
     network_id = "foo_network_id"
     port_id = "foo_port_id"
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_dvr_port_binding(self.ctx.session, port_id, "foo_host_1", router.id)
     ml2_db.ensure_dvr_port_binding(self.ctx.session, port_id, "foo_host_2", router.id)
     bindings = self.ctx.session.query(models.DVRPortBinding).filter_by(port_id=port_id).all()
     self.assertEqual(2, len(bindings))
Пример #3
0
 def test_ensure_dvr_port_binding(self):
     network_id = 'foo_network_id'
     port_id = 'foo_port_id'
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_dvr_port_binding(
         self.ctx.session, port_id, 'foo_host', router.id)
     expected = (self.ctx.session.query(models.DVRPortBinding).
                 filter_by(port_id=port_id).one())
     self.assertEqual(port_id, expected.port_id)
Пример #4
0
 def test_ensure_dvr_port_binding_created_if_not_found(self):
     network_id = 'foo_network_id'
     port_id = 'foo_port_id'
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_dvr_port_binding(
         self.ctx.session, port_id, 'foo_host', router.id)
     expected = (self.ctx.session.query(ml2_models.DVRPortBinding).
                 filter_by(port_id=port_id).one())
     self.assertEqual(expected.port_id, port_id)
Пример #5
0
 def test_ensure_dvr_port_binding_multiple_bindings(self):
     network_id = 'foo_network_id'
     port_id = 'foo_port_id'
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_dvr_port_binding(
         self.ctx.session, port_id, 'foo_host_1', router.id)
     ml2_db.ensure_dvr_port_binding(
         self.ctx.session, port_id, 'foo_host_2', router.id)
     bindings = (self.ctx.session.query(models.DVRPortBinding).
                 filter_by(port_id=port_id).all())
     self.assertEqual(2, len(bindings))
Пример #6
0
    def update_dvr_port_binding(self, context, id, port):
        attrs = port['port']
        need_port_update_notify = False

        host = attrs and attrs.get(portbindings.HOST_ID)
        host_set = attributes.is_attr_set(host)

        if not host_set:
            LOG.error(_("No Host supplied to bind DVR Port %s"), id)
            return

        binding = db.get_dvr_port_binding_by_host(port_id=id, host=host,
                                                  session=None)
        if ((not binding) or
                (binding.vif_type == portbindings.VIF_TYPE_BINDING_FAILED)):
            session = context.session
            with session.begin(subtransactions=True):
                if (not binding):
                    binding = db.ensure_dvr_port_binding(session, id,
                                                         host,
                                                         attrs['device_id'])
                orig_port = super(Ml2Plugin, self).get_port(context, id)
                network = self.get_network(context, orig_port['network_id'])
                mech_context = driver_context.PortContext(self,
                    context, orig_port, network,
                    original_port=orig_port, binding=binding)
                need_port_update_notify |= self._process_dvr_port_binding(
                    mech_context, context, attrs)
Пример #7
0
 def test_ensure_dvr_port_binding_deals_with_db_duplicate(self):
     network_id = "foo_network_id"
     port_id = "foo_port_id"
     router_id = "foo_router_id"
     host_id = "foo_host_id"
     self._setup_neutron_network(network_id, [port_id])
     self._setup_dvr_binding(network_id, port_id, router_id, host_id)
     with mock.patch.object(query.Query, "first") as query_first:
         query_first.return_value = []
         with mock.patch.object(ml2_db.LOG, "debug") as log_trace:
             binding = ml2_db.ensure_dvr_port_binding(self.ctx.session, port_id, host_id, router_id)
     self.assertTrue(query_first.called)
     self.assertTrue(log_trace.called)
     self.assertEqual(port_id, binding.port_id)
Пример #8
0
 def test_ensure_dvr_port_binding_deals_with_db_duplicate(self):
     network_id = 'foo_network_id'
     port_id = 'foo_port_id'
     router_id = 'foo_router_id'
     host_id = 'foo_host_id'
     self._setup_neutron_network(network_id, [port_id])
     self._setup_dvr_binding(network_id, port_id, router_id, host_id)
     with mock.patch.object(query.Query, 'first') as query_first:
         query_first.return_value = []
         with mock.patch.object(ml2_db.LOG, 'debug') as log_trace:
             binding = ml2_db.ensure_dvr_port_binding(
                 self.ctx.session, port_id, host_id, router_id)
     self.assertTrue(query_first.called)
     self.assertTrue(log_trace.called)
     self.assertEqual(port_id, binding.port_id)
Пример #9
0
    def get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        LOG.debug("Device %(device)s details requested by agent "
                  "%(agent_id)s with host %(host)s",
                  {'device': device, 'agent_id': agent_id, 'host': host})
        port_id = self._device_to_port_id(device)

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            port = db.get_port(session, port_id)
            if not port:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s not found in database"),
                            {'device': device, 'agent_id': agent_id})
                return {'device': device}

            segments = db.get_network_segments(session, port.network_id)
            if not segments:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s has network %(network_id)s with "
                              "no segments"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id})
                return {'device': device}

            if port['device_owner'] == q_const.DEVICE_OWNER_DVR_INTERFACE:
                binding = db.ensure_dvr_port_binding(session, port_id, host)
            else:
                binding = db.ensure_port_binding(session, port.id)

            if not binding.segment:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s on network %(network_id)s not "
                              "bound, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id,
                             'vif_type': binding.vif_type})
                return {'device': device}

            segment = self._find_segment(segments, binding.segment)
            if not segment:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s on network %(network_id)s "
                              "invalid segment, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id,
                             'vif_type': binding.vif_type})
                return {'device': device}

            new_status = (q_const.PORT_STATUS_BUILD if port.admin_state_up
                          else q_const.PORT_STATUS_DOWN)
            if port.status != new_status:
                plugin = manager.NeutronManager.get_plugin()
                plugin.update_port_status(rpc_context,
                                          port_id,
                                          new_status,
                                          host)
                port.status = new_status
            entry = {'device': device,
                     'network_id': port.network_id,
                     'port_id': port.id,
                     'admin_state_up': port.admin_state_up,
                     'network_type': segment[api.NETWORK_TYPE],
                     'segmentation_id': segment[api.SEGMENTATION_ID],
                     'physical_network': segment[api.PHYSICAL_NETWORK],
                     'fixed_ips': port['fixed_ips'],
                     'device_owner': port['device_owner']}
            LOG.debug(_("Returning: %s"), entry)
            return entry