예제 #1
0
 def test_ensure_distributed_port_binding(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_distributed_port_binding(self.ctx, port_id, 'foo_host',
                                            router.id)
     expected = (self.ctx.session.query(
         models.DistributedPortBinding).filter_by(port_id=port_id).one())
     self.assertEqual(port_id, expected.port_id)
예제 #2
0
 def test_ensure_distributed_port_binding(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_distributed_port_binding(
         self.ctx, port_id, 'foo_host', router.id)
     expected = (self.ctx.session.query(models.DistributedPortBinding).
                 filter_by(port_id=port_id).one())
     self.assertEqual(port_id, expected.port_id)
예제 #3
0
 def test_ensure_distributed_port_binding_multiple_bindings(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_distributed_port_binding(self.ctx, port_id, 'foo_host_1',
                                            router.id)
     ml2_db.ensure_distributed_port_binding(self.ctx, port_id, 'foo_host_2',
                                            router.id)
     bindings = (self.ctx.session.query(
         models.DistributedPortBinding).filter_by(port_id=port_id).all())
     self.assertEqual(2, len(bindings))
예제 #4
0
 def test_ensure_distributed_port_binding_multiple_bindings(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_distributed_port_binding(
         self.ctx, port_id, 'foo_host_1', router.id)
     ml2_db.ensure_distributed_port_binding(
         self.ctx, port_id, 'foo_host_2', router.id)
     bindings = (self.ctx.session.query(models.DistributedPortBinding).
                 filter_by(port_id=port_id).all())
     self.assertEqual(2, len(bindings))
예제 #5
0
 def test_ensure_distributed_port_binding_multiple_bindings(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_distributed_port_binding(
         self.ctx, port_id, 'foo_host_1', router.id)
     ml2_db.ensure_distributed_port_binding(
         self.ctx, port_id, 'foo_host_2', router.id)
     count_objs = port_obj.DistributedPortBinding.count(
         self.ctx, port_id=port_id)
     self.assertEqual(2, count_objs)
예제 #6
0
 def test_ensure_distributed_port_binding(self):
     network_id = uuidutils.generate_uuid()
     expected_port_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [expected_port_id])
     router = self._setup_neutron_router()
     ml2_db.ensure_distributed_port_binding(
         self.ctx, expected_port_id, 'foo_host', router.id)
     actual_objs = port_obj.DistributedPortBinding.get_objects(
         self.ctx, port_id=expected_port_id)
     self.assertEqual(1, len(actual_objs))
     actual_obj = actual_objs.pop()
     self.assertEqual(expected_port_id, actual_obj.port_id)
예제 #7
0
 def test_ensure_distributed_port_binding_deals_with_db_duplicate(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     router_id = uuidutils.generate_uuid()
     host_id = uuidutils.generate_uuid()
     self._setup_neutron_network(network_id, [port_id])
     dpb = self._setup_distributed_binding(network_id, port_id,
                                           router_id, host_id)
     with mock.patch.object(port_obj.DistributedPortBinding,
             'get_object') as get_object:
         get_object.side_effect = [None, dpb]
         binding = ml2_db.ensure_distributed_port_binding(
             self.ctx, port_id, host_id, router_id)
     self.assertTrue(get_object.called)
     self.assertEqual(port_id, binding.port_id)
예제 #8
0
 def test_ensure_distributed_port_binding_deals_with_db_duplicate(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     router_id = 'foo_router_id'
     host_id = 'foo_host_id'
     self._setup_neutron_network(network_id, [port_id])
     self._setup_distributed_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_distributed_port_binding(
                 self.ctx, 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 test_ensure_distributed_port_binding_deals_with_db_duplicate(self):
     network_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     router_id = 'foo_router_id'
     host_id = 'foo_host_id'
     self._setup_neutron_network(network_id, [port_id])
     self._setup_distributed_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_distributed_port_binding(
                 self.ctx, port_id, host_id, router_id)
     self.assertTrue(query_first.called)
     self.assertTrue(log_trace.called)
     self.assertEqual(port_id, binding.port_id)