Пример #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()
     device_owner = constants.DEVICE_OWNER_DVR_INTERFACE
     port = port_obj.Port(self.ctx,
                          id=uuidutils.generate_uuid(),
                          network_id=network_id,
                          mac_address=netaddr.EUI('00-11-22-33-44-55'),
                          admin_state_up=True,
                          status=constants.PORT_STATUS_ACTIVE,
                          device_id='device_id',
                          device_owner=device_owner)
     port.create()
     port_obj.DistributedPortBinding(
         self.ctx,
         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).create()
     port_obj.DistributedPortBinding(
         self.ctx,
         port_id=port.id,
         host='another-host',
         vif_type=portbindings.VIF_TYPE_UNBOUND,
         vnic_type=portbindings.VNIC_NORMAL,
         router_id='router_id',
         status=constants.PORT_STATUS_DOWN).create()
     with warnings.catch_warnings(record=True) as warning_list:
         port.delete()
         self.assertEqual([], warning_list, 'Warnings: %s' %
                          ';'.join([str(w) for w in warning_list]))
     ports = ml2_db.get_distributed_port_bindings(self.ctx, port.id)
     self.assertEqual(0, len(ports))
Пример #2
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_id = uuidutils.generate_uuid()
         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
     }
     port_obj.DistributedPortBinding(self.ctx, **binding_kwarg).create()
     binding_kwarg['host'] = 'another-host'
     port_obj.DistributedPortBinding(self.ctx, **binding_kwarg).create()
     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)
     bindings = ml2_db.get_distributed_port_bindings(self.ctx, port_id)
     self.assertEqual(0, len(bindings))
Пример #3
0
    def test_v1_3_to_v1_2_unlists_distributed_bindings(self):
        port_new = self._create_test_port()

        # empty list transforms into None
        port_v1_2 = port_new.obj_to_primitive(target_version='1.2')
        port_data = port_v1_2['versioned_object.data']
        self.assertIsNone(port_data['distributed_binding'])

        # now insert a distributed binding
        binding = ports.DistributedPortBinding(self.context,
                                               host='host1',
                                               port_id=port_new.id,
                                               status='ACTIVE',
                                               vnic_type='vnic_type1',
                                               vif_type='vif_type1')
        binding.create()

        # refetch port object to include binding
        port_new = ports.Port.get_object(self.context, id=port_new.id)

        # new primitive should contain the binding data
        port_v1_2 = port_new.obj_to_primitive(target_version='1.2')
        port_data = port_v1_2['versioned_object.data']
        binding_data = (
            port_data['distributed_binding']['versioned_object.data'])
        self.assertEqual(binding.host, binding_data['host'])
Пример #4
0
 def _setup_distributed_binding(self, network_id,
                                port_id, router_id, host_id):
     binding_obj = port_obj.DistributedPortBinding(
         self.ctx,
         port_id=port_id,
         host=host_id,
         router_id=router_id,
         vif_type=portbindings.VIF_TYPE_UNBOUND,
         vnic_type=portbindings.VNIC_NORMAL,
         status='DOWN')
     binding_obj.create()
     return binding_obj
Пример #5
0
def ensure_distributed_port_binding(context, port_id, host, router_id=None):
    binding_obj = port_obj.DistributedPortBinding.get_object(context,
                                                             port_id=port_id,
                                                             host=host)
    if binding_obj:
        return binding_obj

    try:
        binding_obj = port_obj.DistributedPortBinding(
            context,
            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)
        binding_obj.create()
        return binding_obj
    except exceptions.NeutronDbObjectDuplicateEntry:
        LOG.debug("Distributed Port %s already bound", port_id)
        return port_obj.DistributedPortBinding.get_object(context,
                                                          port_id=port_id,
                                                          host=host)