コード例 #1
0
 def test_dvr_port_binding_deleted_by_port_deletion(self):
     with self.ctx.session.begin(subtransactions=True):
         self.ctx.session.add(models_v2.Network(id='network_id'))
         device_owner = constants.DEVICE_OWNER_DVR_INTERFACE
         port = models_v2.Port(
             id='port_id',
             network_id='network_id',
             mac_address='00:11:22:33:44:55',
             admin_state_up=True,
             status=constants.PORT_STATUS_ACTIVE,
             device_id='device_id',
             device_owner=device_owner)
         self.ctx.session.add(port)
         binding_kwarg = {
             'port_id': 'port_id',
             'host': 'host',
             'vif_type': portbindings.VIF_TYPE_UNBOUND,
             'vnic_type': portbindings.VNIC_NORMAL,
             'router_id': 'router_id',
             'status': constants.PORT_STATUS_DOWN
         }
         self.ctx.session.add(models.DVRPortBinding(**binding_kwarg))
         binding_kwarg['host'] = 'another-host'
         self.ctx.session.add(models.DVRPortBinding(**binding_kwarg))
     with warnings.catch_warnings(record=True) as warning_list:
         with self.ctx.session.begin(subtransactions=True):
             self.ctx.session.delete(port)
         self.assertEqual([], warning_list)
     ports = ml2_db.get_dvr_port_bindings(self.ctx.session, 'port_id')
     self.assertEqual(0, len(ports))
コード例 #2
0
 def _setup_dvr_binding(self, network_id, port_id, router_id, host_id):
     with self.ctx.session.begin(subtransactions=True):
         record = models.DVRPortBinding(
             port_id=port_id,
             host=host_id,
             router_id=router_id,
             vif_type=portbindings.VIF_TYPE_UNBOUND,
             vnic_type=portbindings.VNIC_NORMAL,
             status='DOWN')
         self.ctx.session.add(record)
         return record
コード例 #3
0
def ensure_dvr_port_binding(session, port_id, host, router_id=None):
    record = (session.query(models.DVRPortBinding).
              filter_by(port_id=port_id, host=host).first())
    if record:
        return record

    try:
        with session.begin(subtransactions=True):
            record = models.DVRPortBinding(
                port_id=port_id,
                host=host,
                router_id=router_id,
                vif_type=portbindings.VIF_TYPE_UNBOUND,
                vnic_type=portbindings.VNIC_NORMAL,
                status=n_const.PORT_STATUS_DOWN)
            session.add(record)
            return record
    except db_exc.DBDuplicateEntry:
        LOG.debug("DVR Port %s already bound", port_id)
        return (session.query(models.DVRPortBinding).
                filter_by(port_id=port_id, host=host).one())
コード例 #4
0
ファイル: test_ml2_plugin.py プロジェクト: samsu/neutron
 def test_process_dvr_port_binding_update_router_id(self):
     host_id = 'host'
     binding = models.DVRPortBinding(port_id='port_id',
                                     host=host_id,
                                     router_id='old_router_id',
                                     vif_type=portbindings.VIF_TYPE_OVS,
                                     vnic_type=portbindings.VNIC_NORMAL,
                                     cap_port_filter=False,
                                     status=constants.PORT_STATUS_DOWN)
     plugin = manager.NeutronManager.get_plugin()
     mock_network = {'id': 'net_id'}
     context = mock.Mock()
     new_router_id = 'new_router'
     attrs = {'device_id': new_router_id, portbindings.HOST_ID: host_id}
     with mock.patch.object(plugin, '_update_port_dict_binding'):
         with mock.patch.object(ml2_db,
                                'get_network_segments',
                                return_value=[]):
             mech_context = driver_context.DvrPortContext(
                 self, context, 'port', mock_network, binding)
             plugin._process_dvr_port_binding(mech_context, context, attrs)
             self.assertEqual(new_router_id,
                              mech_context._binding.router_id)
             self.assertEqual(host_id, mech_context._binding.host)