Merge "Return BadRequest for invalid Unicode names"

This commit is contained in:
Jenkins 2016-03-02 00:12:09 +00:00 committed by Gerrit Code Review
commit 82d1d81124

View File

@ -240,6 +240,18 @@ def _retry_on_deadlock(f):
return wrapped
def handle_db_data_error(f):
def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
except db_exc.DBDataError:
msg = _('Error writing field to database')
LOG.exception(msg)
raise exception.Invalid(msg)
return wrapper
def model_query(context, *args, **kwargs):
"""Query helper that accounts for context's `read_deleted` field.
@ -1180,6 +1192,7 @@ def volume_attached(context, attachment_id, instance_uuid, host_name,
return volume_ref
@handle_db_data_error
@require_context
def volume_create(context, values):
values['volume_metadata'] = _metadata_refs(values.get('metadata'),
@ -1197,11 +1210,8 @@ def volume_create(context, values):
volume_ref.update(values)
session = get_session()
try:
with session.begin():
session.add(volume_ref)
except db_exc.DBDataError:
raise exception.Invalid()
with session.begin():
session.add(volume_ref)
return _volume_get(context, values['id'], session=session)
@ -1796,6 +1806,7 @@ def process_sort_params(sort_keys, sort_dirs, default_keys=None,
return result_keys, result_dirs
@handle_db_data_error
@require_context
def volume_update(context, volume_id, values):
session = get_session()
@ -2115,6 +2126,7 @@ def volume_admin_metadata_update(context, volume_id, metadata, delete,
###################
@handle_db_data_error
@require_context
def snapshot_create(context, values):
values['snapshot_metadata'] = _metadata_refs(values.get('metadata'),
@ -2354,6 +2366,7 @@ def snapshot_get_active_by_window(context, begin, end=None, project_id=None):
return query.all()
@handle_db_data_error
@require_context
def snapshot_update(context, snapshot_id, values):
session = get_session()
@ -2454,6 +2467,7 @@ def snapshot_metadata_update(context, snapshot_id, metadata, delete):
###################
@handle_db_data_error
@require_admin_context
def volume_type_create(context, values, projects=None):
"""Create a new volume type.
@ -2553,6 +2567,7 @@ def _process_volume_types_filters(query, filters):
return query
@handle_db_data_error
@require_admin_context
def volume_type_update(context, volume_type_id, values):
session = get_session()
@ -3288,6 +3303,7 @@ def _qos_specs_get_item(context, qos_specs_id, key, session=None):
return result
@handle_db_data_error
@require_admin_context
def qos_specs_update(context, qos_specs_id, specs):
"""Make updates to an existing qos specs.
@ -3345,6 +3361,7 @@ def volume_type_encryption_delete(context, volume_type_id):
'updated_at': literal_column('updated_at')})
@handle_db_data_error
@require_admin_context
def volume_type_encryption_create(context, volume_type_id, values):
session = get_session()
@ -3363,6 +3380,7 @@ def volume_type_encryption_create(context, volume_type_id, values):
return encryption
@handle_db_data_error
@require_admin_context
def volume_type_encryption_update(context, volume_type_id, values):
session = get_session()
@ -3728,6 +3746,7 @@ def backup_get_all_by_volume(context, volume_id, filters=None):
return _backup_get_all(context, filters)
@handle_db_data_error
@require_context
def backup_create(context, values):
backup = models.Backup()
@ -3741,6 +3760,7 @@ def backup_create(context, values):
return backup
@handle_db_data_error
@require_context
def backup_update(context, backup_id, values):
session = get_session()
@ -4034,6 +4054,7 @@ def consistencygroup_get_all_by_project(context, project_id, filters=None,
sort_keys, sort_dirs)
@handle_db_data_error
@require_context
def consistencygroup_create(context, values):
consistencygroup = models.ConsistencyGroup()
@ -4048,6 +4069,7 @@ def consistencygroup_create(context, values):
return _consistencygroup_get(context, values['id'], session=session)
@handle_db_data_error
@require_context
def consistencygroup_update(context, consistencygroup_id, values):
session = get_session()
@ -4147,6 +4169,7 @@ def cgsnapshot_get_all_by_project(context, project_id, filters=None):
return _cgsnapshot_get_all(context, project_id=project_id, filters=filters)
@handle_db_data_error
@require_context
def cgsnapshot_create(context, values):
cgsnapshot = models.Cgsnapshot()
@ -4161,6 +4184,7 @@ def cgsnapshot_create(context, values):
return _cgsnapshot_get(context, values['id'], session=session)
@handle_db_data_error
@require_context
def cgsnapshot_update(context, cgsnapshot_id, values):
session = get_session()