Exemplo n.º 1
0
 def test_distributed_port_binding_deleted_by_port_deletion(self):
     network_id = uuidutils.generate_uuid()
     network_obj.Network(self.ctx, id=network_id).create()
     with db_api.context_manager.writer.using(self.ctx):
         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.DistributedPortBinding(**binding_kwarg))
         binding_kwarg['host'] = 'another-host'
         self.ctx.session.add(
             models.DistributedPortBinding(**binding_kwarg))
     with warnings.catch_warnings(record=True) as warning_list:
         with db_api.context_manager.writer.using(self.ctx):
             self.ctx.session.delete(port)
         self.assertEqual([], warning_list)
     ports = ml2_db.get_distributed_port_bindings(self.ctx, 'port_id')
     self.assertEqual(0, len(ports))
Exemplo n.º 2
0
def ensure_distributed_port_binding(context, port_id, host, router_id=None):
    with db_api.context_manager.reader.using(context):
        record = (context.session.query(
            models.DistributedPortBinding).filter_by(port_id=port_id,
                                                     host=host).first())
    if record:
        return record

    try:
        with db_api.context_manager.writer.using(context):
            record = models.DistributedPortBinding(
                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)
            context.session.add(record)
            return record
    except db_exc.DBDuplicateEntry:
        LOG.debug("Distributed Port %s already bound", port_id)
        with db_api.context_manager.reader.using(context):
            return (context.session.query(
                models.DistributedPortBinding).filter_by(port_id=port_id,
                                                         host=host).one())
Exemplo n.º 3
0
 def _setup_distributed_binding(self, network_id, port_id, router_id,
                                host_id):
     with db_api.context_manager.writer.using(self.ctx):
         record = models.DistributedPortBinding(
             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
Exemplo n.º 4
0
 def _setup_distributed_binding(self, network_id, port_id, router_id,
                                host_id):
     with self.ctx.session.begin(subtransactions=True):
         record = models.DistributedPortBinding(
             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
Exemplo n.º 5
0
def ensure_distributed_port_binding(session, port_id, host, router_id=None):
    record = (session.query(models.DistributedPortBinding).
              filter_by(port_id=port_id, host=host).first())
    if record:
        return record

    try:
        with session.begin(subtransactions=True):
            record = models.DistributedPortBinding(
                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("Distributed Port %s already bound", port_id)
        return (session.query(models.DistributedPortBinding).
                filter_by(port_id=port_id, host=host).one())