Esempio n. 1
0
 def test_prevent_l3_port_no_router(self, gp):
     # without router is allowed
     gp.return_value.get_port.return_value = {
         'device_owner': n_const.DEVICE_OWNER_ROUTER_INTF,
         'device_id': '44', 'id': 'f',
         'fixed_ips': [{'ip_address': '1.1.1.1', 'subnet_id': '4'}]}
     self.db.get_router = mock.Mock()
     self.db.get_router.side_effect = l3_exc.RouterNotFound(router_id='44')
     self.db.prevent_l3_port_deletion(mock.Mock(), None)
 def set_router_for_bgp_speaker(self, context, bgp_sp_id, r_id):
     """Sets the routers associated with the bgp speaker."""
     try:
         with db_api.context_manager.writer.using(context):
             bgp_router_db = model.BgpSpeakerRouterAssociation(
                 bgp_speaker_id=bgp_sp_id, router_id=r_id)
             context.session.add(bgp_router_db)
     except db_exc.DBDuplicateEntry:
         raise l3_exc.RouterInUse(
             router_id=r_id,
             reason='is already associated with bgp speaker')
     except db_exc.DBReferenceError:
         raise l3_exc.RouterNotFound(router_id=r_id)
Esempio n. 3
0
 def test_synchronize_routernot_found_in_db_no_raise(self):
     ctx = context.get_admin_context()
     with self._populate_data(ctx):
         # Put a router down to verify synchronization
         lr_uuid = list(self.fc._fake_lrouter_dict)[0]
         q_rtr_id = self._get_tag_dict(
             self.fc._fake_lrouter_dict[lr_uuid]['tags'])['q_router_id']
         self.fc._fake_lrouter_dict[lr_uuid]['status'] = 'false'
         q_rtr_data = self._plugin._get_router(ctx, q_rtr_id)
         with mock.patch.object(self._plugin, '_get_router') as _get_router:
             _get_router.side_effect = l3_exc.RouterNotFound(
                 router_id=q_rtr_data['id'])
             self._plugin._synchronizer.synchronize_router(ctx, q_rtr_data)
Esempio n. 4
0
    def _create_ha_port_binding(self, context, router_id, port_id):
        try:
            l3_obj.RouterPort(
                context,
                port_id=port_id,
                router_id=router_id,
                port_type=constants.DEVICE_OWNER_ROUTER_HA_INTF).create()
            portbinding = l3_hamode.L3HARouterAgentPortBinding(
                context, port_id=port_id, router_id=router_id)
            portbinding.create()

            return portbinding
        except db_exc.DBReferenceError as e:
            with excutils.save_and_reraise_exception() as ctxt:
                if isinstance(e.inner_exception, sql_exc.IntegrityError):
                    ctxt.reraise = False
                    LOG.debug(
                        'Failed to create HA router agent PortBinding, '
                        'Router %s has already been removed '
                        'by concurrent operation', router_id)
                    raise l3_exc.RouterNotFound(router_id=router_id)
Esempio n. 5
0
 def get_router(self, context, router_id, fields=None):
     router_obj = router.Router.get_object(context, id=router_id)
     if not router_obj:
         raise lib_l3_exc.RouterNotFound(router_id=router_id)
     return router_obj