'Prevent tenants from replacing the device id of router ports with
a router uuid belonging to another tenant.'

def _enforce_device_owner_not_router_intf_or_device_id(self, context, device_owner, device_id, tenant_id):

    if (device_owner not in constants.ROUTER_INTERFACE_OWNERS):
        return
    if (not context.is_admin):
        if device_id:
            if hasattr(self, 'get_router'):
                try:
                    ctx_admin = context.elevated()
                    router = self.get_router(ctx_admin, device_id)
                except l3.RouterNotFound:
                    return
            else:
                l3plugin = directory.get_plugin(plugin_constants.L3)
                if l3plugin:
                    try:
                        ctx_admin = context.elevated()
                        router = l3plugin.get_router(ctx_admin, device_id)
                    except l3.RouterNotFound:
                        return
                else:
                    raise n_exc.DeviceIDNotOwnedByTenant(device_id=device_id)
            if (tenant_id != router['tenant_id']):
                raise n_exc.DeviceIDNotOwnedByTenant(device_id=device_id)
