Handle API NotFound exceptions at WSGI level
Throughout the API code we keep catching NotFound exceptions in their various forms and converting them to webob.exc.HTTPNotFound exceptions, but we can leave the WSGI fault handler convert them on its own. This patch changes current behavior and removes the exception handling closer to the operation so that those exceptions can be handled at the WSGI level. This has the following benefits: - Reduces code complexity - Increases code readability - Provides consistent error responses, as messages are stored on the Exceptions. - Prevents raising errors with only partial information (we have cases now that were removing the UUID from the message because they used a custom message). For example: before returned error would be "The resource could not be found", and now we raise "Volume type encryption for type 4e9e6d23-eed0-426d-b90a-28f87a94b6fe does not exist." automatically. - Reduces workload for the translation team because we remove all unnecessary custom messages. Change-Id: I09f98921fdc2400cc3f6056e59001100abe06920
This commit is contained in:
parent
b03f539e6e
commit
c491c3ee61
@ -102,12 +102,10 @@ class AdminController(wsgi.Controller):
|
||||
notifier.info(context, self.collection + '.reset_status.start',
|
||||
notifier_info)
|
||||
|
||||
try:
|
||||
self._update(context, id, update)
|
||||
if update.get('attach_status') == 'detached':
|
||||
_clean_volume_attachment(context, id)
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
self._update(context, id, update)
|
||||
if update.get('attach_status') == 'detached':
|
||||
_clean_volume_attachment(context, id)
|
||||
|
||||
notifier.info(context, self.collection + '.reset_status.end',
|
||||
notifier_info)
|
||||
@ -119,10 +117,8 @@ class AdminController(wsgi.Controller):
|
||||
"""Delete a resource, bypassing the check that it must be available."""
|
||||
context = req.environ['cinder.context']
|
||||
self.authorize(context, 'force_delete')
|
||||
try:
|
||||
resource = self._get(context, id)
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
resource = self._get(context, id)
|
||||
self._delete(context, resource, force=True)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@ -193,10 +189,8 @@ class VolumeAdminController(AdminController):
|
||||
"""Roll back a bad detach after the volume been disconnected."""
|
||||
context = req.environ['cinder.context']
|
||||
self.authorize(context, 'force_detach')
|
||||
try:
|
||||
volume = self._get(context, id)
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self._get(context, id)
|
||||
try:
|
||||
connector = body['os-force_detach'].get('connector', None)
|
||||
except KeyError:
|
||||
@ -232,10 +226,8 @@ class VolumeAdminController(AdminController):
|
||||
"""Migrate a volume to the specified host."""
|
||||
context = req.environ['cinder.context']
|
||||
self.authorize(context, 'migrate_volume')
|
||||
try:
|
||||
volume = self._get(context, id)
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self._get(context, id)
|
||||
params = body['os-migrate_volume']
|
||||
try:
|
||||
host = params['host']
|
||||
@ -252,20 +244,16 @@ class VolumeAdminController(AdminController):
|
||||
"""Complete an in-progress migration."""
|
||||
context = req.environ['cinder.context']
|
||||
self.authorize(context, 'migrate_volume_completion')
|
||||
try:
|
||||
volume = self._get(context, id)
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self._get(context, id)
|
||||
params = body['os-migrate_volume_completion']
|
||||
try:
|
||||
new_volume_id = params['new_volume']
|
||||
except KeyError:
|
||||
raise exc.HTTPBadRequest(
|
||||
explanation=_("Must specify 'new_volume'"))
|
||||
try:
|
||||
new_volume = self._get(context, new_volume_id)
|
||||
except exception.VolumeNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
new_volume = self._get(context, new_volume_id)
|
||||
error = params.get('error', False)
|
||||
ret = self.volume_api.migrate_volume_completion(context, volume,
|
||||
new_volume, error)
|
||||
@ -323,11 +311,9 @@ class BackupAdminController(AdminController):
|
||||
notifier.info(context, self.collection + '.reset_status.start',
|
||||
notifier_info)
|
||||
|
||||
try:
|
||||
self.backup_api.reset_status(context=context, backup_id=id,
|
||||
status=update['status'])
|
||||
except exception.BackupNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
self.backup_api.reset_status(context=context, backup_id=id,
|
||||
status=update['status'])
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
@ -47,11 +47,9 @@ class BackupsController(wsgi.Controller):
|
||||
LOG.debug('show called for member %s', id)
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
backup = self.backup_api.get(context, backup_id=id)
|
||||
req.cache_db_backup(backup)
|
||||
except exception.BackupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
backup = self.backup_api.get(context, backup_id=id)
|
||||
req.cache_db_backup(backup)
|
||||
|
||||
return self._view_builder.detail(req, backup)
|
||||
|
||||
@ -65,8 +63,7 @@ class BackupsController(wsgi.Controller):
|
||||
try:
|
||||
backup = self.backup_api.get(context, id)
|
||||
self.backup_api.delete(context, backup)
|
||||
except exception.BackupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidBackup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
|
||||
@ -157,9 +154,7 @@ class BackupsController(wsgi.Controller):
|
||||
except (exception.InvalidVolume,
|
||||
exception.InvalidSnapshot) as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except (exception.VolumeNotFound,
|
||||
exception.SnapshotNotFound) as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Other not found exceptions will be handled at the wsgi level
|
||||
except exception.ServiceNotFound as error:
|
||||
raise exc.HTTPInternalServerError(explanation=error.msg)
|
||||
|
||||
@ -187,16 +182,13 @@ class BackupsController(wsgi.Controller):
|
||||
backup_id=id,
|
||||
volume_id=volume_id,
|
||||
name=name)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidInput as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.InvalidVolume as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.InvalidBackup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.BackupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.VolumeSizeExceedsAvailableQuota as error:
|
||||
raise exc.HTTPRequestEntityTooLarge(
|
||||
explanation=error.msg, headers={'Retry-After': '0'})
|
||||
@ -216,8 +208,7 @@ class BackupsController(wsgi.Controller):
|
||||
|
||||
try:
|
||||
backup_info = self.backup_api.export_record(context, id)
|
||||
except exception.BackupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidBackup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
|
||||
@ -247,10 +238,9 @@ class BackupsController(wsgi.Controller):
|
||||
new_backup = self.backup_api.import_record(context,
|
||||
backup_service,
|
||||
backup_url)
|
||||
except exception.BackupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.InvalidBackup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
# Other Not found exceptions will be handled at the wsgi level
|
||||
except exception.ServiceNotFound as error:
|
||||
raise exc.HTTPInternalServerError(explanation=error.msg)
|
||||
|
||||
|
@ -45,12 +45,10 @@ class CgsnapshotsController(wsgi.Controller):
|
||||
LOG.debug('show called for member %s', id)
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
cgsnapshot = self.cgsnapshot_api.get_cgsnapshot(
|
||||
context,
|
||||
cgsnapshot_id=id)
|
||||
except exception.CgSnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
cgsnapshot = self.cgsnapshot_api.get_cgsnapshot(
|
||||
context,
|
||||
cgsnapshot_id=id)
|
||||
|
||||
return self._view_builder.detail(req, cgsnapshot)
|
||||
|
||||
@ -66,8 +64,9 @@ class CgsnapshotsController(wsgi.Controller):
|
||||
context,
|
||||
cgsnapshot_id=id)
|
||||
self.cgsnapshot_api.delete_cgsnapshot(context, cgsnapshot)
|
||||
except exception.CgSnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.CgSnapshotNotFound:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.InvalidCgSnapshot as e:
|
||||
raise exc.HTTPBadRequest(explanation=six.text_type(e))
|
||||
except Exception:
|
||||
@ -112,10 +111,8 @@ class CgsnapshotsController(wsgi.Controller):
|
||||
msg = _("'consistencygroup_id' must be specified")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
group = self.cgsnapshot_api.get(context, group_id)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
group = self.cgsnapshot_api.get(context, group_id)
|
||||
|
||||
name = cgsnapshot.get('name', None)
|
||||
description = cgsnapshot.get('description', None)
|
||||
@ -127,10 +124,9 @@ class CgsnapshotsController(wsgi.Controller):
|
||||
try:
|
||||
new_cgsnapshot = self.cgsnapshot_api.create_cgsnapshot(
|
||||
context, group, name, description)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidCgSnapshot as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.CgSnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
|
||||
retval = self._view_builder.summary(req, new_cgsnapshot)
|
||||
|
||||
|
@ -45,12 +45,10 @@ class ConsistencyGroupsController(wsgi.Controller):
|
||||
LOG.debug('show called for member %s', id)
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
consistencygroup = self.consistencygroup_api.get(
|
||||
context,
|
||||
group_id=id)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
consistencygroup = self.consistencygroup_api.get(
|
||||
context,
|
||||
group_id=id)
|
||||
|
||||
return self._view_builder.detail(req, consistencygroup)
|
||||
|
||||
@ -79,8 +77,7 @@ class ConsistencyGroupsController(wsgi.Controller):
|
||||
try:
|
||||
group = self.consistencygroup_api.get(context, id)
|
||||
self.consistencygroup_api.delete(context, group, force)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidConsistencyGroup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
|
||||
@ -139,12 +136,11 @@ class ConsistencyGroupsController(wsgi.Controller):
|
||||
new_consistencygroup = self.consistencygroup_api.create(
|
||||
context, name, description, volume_types,
|
||||
availability_zone=availability_zone)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidConsistencyGroup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.InvalidVolumeType as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
|
||||
retval = self._view_builder.summary(req, new_consistencygroup)
|
||||
return retval
|
||||
@ -195,10 +191,9 @@ class ConsistencyGroupsController(wsgi.Controller):
|
||||
context, name, description, cgsnapshot_id, source_cgid)
|
||||
except exception.InvalidConsistencyGroup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.CgSnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.NotFound:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.CinderException as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
|
||||
@ -225,15 +220,11 @@ class ConsistencyGroupsController(wsgi.Controller):
|
||||
'remove_volumes': remove_volumes},
|
||||
context=context)
|
||||
|
||||
try:
|
||||
group = self.consistencygroup_api.get(context, id)
|
||||
self.consistencygroup_api.update(
|
||||
context, group, name, description,
|
||||
add_volumes, remove_volumes, allow_empty)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.InvalidConsistencyGroup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
# Handle relevant exceptions at wsgi level
|
||||
group = self.consistencygroup_api.get(context, id)
|
||||
self.consistencygroup_api.update(context, group, name, description,
|
||||
add_volumes, remove_volumes,
|
||||
allow_empty)
|
||||
|
||||
def update(self, req, id, body):
|
||||
"""Update the consistency group.
|
||||
|
@ -79,9 +79,7 @@ def check_host(fn):
|
||||
hosts = [h["host_name"] for h in listed_hosts]
|
||||
if id in hosts:
|
||||
return fn(self, req, id, *args, **kwargs)
|
||||
else:
|
||||
message = _("Host '%s' could not be found.") % id
|
||||
raise webob.exc.HTTPNotFound(explanation=message)
|
||||
raise exception.HostNotFound(host=id)
|
||||
return wrapped
|
||||
|
||||
|
||||
@ -149,11 +147,9 @@ class HostController(wsgi.Controller):
|
||||
msg = _("Describe-resource is admin only functionality")
|
||||
raise webob.exc.HTTPForbidden(explanation=msg)
|
||||
|
||||
try:
|
||||
host_ref = objects.Service.get_by_host_and_topic(
|
||||
context, host, CONF.volume_topic)
|
||||
except exception.ServiceNotFound:
|
||||
raise webob.exc.HTTPNotFound(explanation=_("Host not found"))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
host_ref = objects.Service.get_by_host_and_topic(
|
||||
context, host, CONF.volume_topic)
|
||||
|
||||
# Getting total available/used resource
|
||||
# TODO(jdg): Add summary info for Snapshots
|
||||
|
@ -36,10 +36,8 @@ authorize = extensions.extension_authorizer('volume', 'qos_specs_manage')
|
||||
|
||||
|
||||
def _check_specs(context, specs_id):
|
||||
try:
|
||||
qos_specs.get_qos_specs(context, specs_id)
|
||||
except exception.QoSSpecsNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(ex))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
qos_specs.get_qos_specs(context, specs_id)
|
||||
|
||||
|
||||
class QoSSpecsController(wsgi.Controller):
|
||||
@ -129,18 +127,13 @@ class QoSSpecsController(wsgi.Controller):
|
||||
rpc.get_notifier('QoSSpecs').info(context,
|
||||
'qos_specs.update',
|
||||
notifier_info)
|
||||
except exception.QoSSpecsNotFound as err:
|
||||
except (exception.QoSSpecsNotFound, exception.InvalidQoSSpecs) as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.update',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
except exception.InvalidQoSSpecs as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.update',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.QoSSpecsUpdateFailed as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
@ -156,10 +149,8 @@ class QoSSpecsController(wsgi.Controller):
|
||||
context = req.environ['cinder.context']
|
||||
authorize(context)
|
||||
|
||||
try:
|
||||
spec = qos_specs.get_qos_specs(context, id)
|
||||
except exception.QoSSpecsNotFound as err:
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
spec = qos_specs.get_qos_specs(context, id)
|
||||
|
||||
return self._view_builder.detail(req, spec)
|
||||
|
||||
@ -184,7 +175,8 @@ class QoSSpecsController(wsgi.Controller):
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.delete',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.QoSSpecsInUse as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
@ -216,18 +208,13 @@ class QoSSpecsController(wsgi.Controller):
|
||||
notifier_info = dict(id=id)
|
||||
rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.delete_keys',
|
||||
notifier_info)
|
||||
except exception.QoSSpecsNotFound as err:
|
||||
except exception.NotFound as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.delete_keys',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
except exception.QoSSpecsKeyNotFound as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.delete_keys',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPBadRequest(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@ -249,7 +236,8 @@ class QoSSpecsController(wsgi.Controller):
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.associations',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.CinderException as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
@ -283,18 +271,13 @@ class QoSSpecsController(wsgi.Controller):
|
||||
rpc.get_notifier('QoSSpecs').info(context,
|
||||
'qos_specs.associate',
|
||||
notifier_info)
|
||||
except exception.VolumeTypeNotFound as err:
|
||||
except exception.NotFound as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.associate',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
except exception.QoSSpecsNotFound as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.associate',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.InvalidVolumeType as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
@ -337,18 +320,13 @@ class QoSSpecsController(wsgi.Controller):
|
||||
rpc.get_notifier('QoSSpecs').info(context,
|
||||
'qos_specs.disassociate',
|
||||
notifier_info)
|
||||
except exception.VolumeTypeNotFound as err:
|
||||
except exception.NotFound as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.disassociate',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
except exception.QoSSpecsNotFound as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.disassociate',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.QoSSpecsDisassociateFailed as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
@ -377,7 +355,8 @@ class QoSSpecsController(wsgi.Controller):
|
||||
self._notify_qos_specs_error(context,
|
||||
'qos_specs.disassociate_all',
|
||||
notifier_err)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.QoSSpecsDisassociateFailed as err:
|
||||
notifier_err = dict(id=id, error_message=err)
|
||||
self._notify_qos_specs_error(context,
|
||||
|
@ -148,7 +148,7 @@ class ServiceController(wsgi.Controller):
|
||||
)
|
||||
return webob.Response(status_int=202)
|
||||
else:
|
||||
raise webob.exc.HTTPNotFound(explanation=_("Unknown action"))
|
||||
raise exception.InvalidInput(reason=_("Unknown action"))
|
||||
|
||||
try:
|
||||
host = body['host']
|
||||
@ -173,17 +173,13 @@ class ServiceController(wsgi.Controller):
|
||||
if not binary_key:
|
||||
raise webob.exc.HTTPBadRequest()
|
||||
|
||||
try:
|
||||
svc = objects.Service.get_by_args(context, host, binary_key)
|
||||
if not svc:
|
||||
raise webob.exc.HTTPNotFound(explanation=_('Unknown service'))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
svc = objects.Service.get_by_args(context, host, binary_key)
|
||||
|
||||
svc.disabled = ret_val['disabled']
|
||||
if 'disabled_reason' in ret_val:
|
||||
svc.disabled_reason = ret_val['disabled_reason']
|
||||
svc.save()
|
||||
except exception.ServiceNotFound:
|
||||
raise webob.exc.HTTPNotFound(explanation=_("service not found"))
|
||||
svc.disabled = ret_val['disabled']
|
||||
if 'disabled_reason' in ret_val:
|
||||
svc.disabled_reason = ret_val['disabled_reason']
|
||||
svc.save()
|
||||
|
||||
ret_val.update({'host': host, 'service': service,
|
||||
'binary': binary, 'status': status})
|
||||
|
@ -21,7 +21,6 @@ from cinder.api import extensions
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.views import manageable_snapshots as list_manageable_view
|
||||
from cinder.api.views import snapshots as snapshot_views
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
from cinder import volume as cinder_volume
|
||||
|
||||
@ -107,11 +106,8 @@ class SnapshotManageController(wsgi.Controller):
|
||||
|
||||
# Check whether volume exists
|
||||
volume_id = snapshot['volume_id']
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
except exception.VolumeNotFound:
|
||||
msg = _("Volume: %s could not be found.") % volume_id
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
|
||||
LOG.debug('Manage snapshot request body: %s', body)
|
||||
|
||||
@ -121,15 +117,12 @@ class SnapshotManageController(wsgi.Controller):
|
||||
snapshot_parameters['description'] = snapshot.get('description', None)
|
||||
snapshot_parameters['name'] = snapshot.get('name')
|
||||
|
||||
try:
|
||||
new_snapshot = self.volume_api.manage_existing_snapshot(
|
||||
context,
|
||||
snapshot['ref'],
|
||||
volume,
|
||||
**snapshot_parameters)
|
||||
except exception.ServiceNotFound:
|
||||
msg = _("Service %s not found.") % CONF.volume_topic
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
new_snapshot = self.volume_api.manage_existing_snapshot(
|
||||
context,
|
||||
snapshot['ref'],
|
||||
volume,
|
||||
**snapshot_parameters)
|
||||
|
||||
return self._view_builder.detail(req, new_snapshot)
|
||||
|
||||
|
@ -54,8 +54,7 @@ class SnapshotUnmanageController(wsgi.Controller):
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.delete_snapshot(context, snapshot,
|
||||
unmanage_only=True)
|
||||
except exception.SnapshotNotFound as ex:
|
||||
raise exc.HTTPNotFound(explanation=ex.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidSnapshot as ex:
|
||||
raise exc.HTTPBadRequest(explanation=ex.msg)
|
||||
return webob.Response(status_int=202)
|
||||
|
@ -41,10 +41,8 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
|
||||
return dict(extra_specs=specs_dict)
|
||||
|
||||
def _check_type(self, context, type_id):
|
||||
try:
|
||||
volume_types.get_volume_type(context, type_id)
|
||||
except exception.VolumeTypeNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume_types.get_volume_type(context, type_id)
|
||||
|
||||
def index(self, req, type_id):
|
||||
"""Returns the list of extra specs for a given volume type."""
|
||||
@ -108,9 +106,8 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
|
||||
if id in specs['extra_specs']:
|
||||
return {id: specs['extra_specs'][id]}
|
||||
else:
|
||||
msg = _("Volume Type %(type_id)s has no extra spec with key "
|
||||
"%(id)s.") % ({'type_id': type_id, 'id': id})
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.VolumeTypeExtraSpecsNotFound(
|
||||
volume_type_id=type_id, extra_specs_key=id)
|
||||
|
||||
def delete(self, req, type_id, id):
|
||||
"""Deletes an existing extra spec."""
|
||||
@ -118,10 +115,8 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
|
||||
self._check_type(context, type_id)
|
||||
authorize(context)
|
||||
|
||||
try:
|
||||
db.volume_type_extra_specs_delete(context, type_id, id)
|
||||
except exception.VolumeTypeExtraSpecsNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
db.volume_type_extra_specs_delete(context, type_id, id)
|
||||
|
||||
notifier_info = dict(type_id=type_id, id=id)
|
||||
notifier = rpc.get_notifier('volumeTypeExtraSpecs')
|
||||
|
@ -95,7 +95,8 @@ class VolumeTypesManageController(wsgi.Controller):
|
||||
except exception.VolumeTypeNotFoundByName as err:
|
||||
self._notify_volume_type_error(
|
||||
context, 'volume_type.create', err, name=name)
|
||||
raise webob.exc.HTTPNotFound(explanation=err.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
|
||||
return self._view_builder.show(req, vol_type)
|
||||
|
||||
@ -148,7 +149,8 @@ class VolumeTypesManageController(wsgi.Controller):
|
||||
except exception.VolumeTypeNotFound as err:
|
||||
self._notify_volume_type_error(
|
||||
context, 'volume_type.update', err, id=id)
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
except exception.VolumeTypeExists as err:
|
||||
self._notify_volume_type_error(
|
||||
context, 'volume_type.update', err, volume_type=vol_type)
|
||||
@ -180,7 +182,8 @@ class VolumeTypesManageController(wsgi.Controller):
|
||||
except exception.VolumeTypeNotFound as err:
|
||||
self._notify_volume_type_error(
|
||||
context, 'volume_type.delete', err, id=id)
|
||||
raise webob.exc.HTTPNotFound(explanation=err.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
raise
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
@ -47,10 +47,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _attach(self, req, id, body):
|
||||
"""Add attachment metadata."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
# instance uuid is an option now
|
||||
instance_uuid = None
|
||||
@ -95,10 +93,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _detach(self, req, id, body):
|
||||
"""Clear attachment metadata."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
attachment_id = None
|
||||
if body['os-detach']:
|
||||
@ -123,10 +119,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _reserve(self, req, id, body):
|
||||
"""Mark volume as reserved."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
self.volume_api.reserve_volume(context, volume)
|
||||
return webob.Response(status_int=202)
|
||||
@ -135,10 +129,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _unreserve(self, req, id, body):
|
||||
"""Unmark volume as reserved."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
self.volume_api.unreserve_volume(context, volume)
|
||||
return webob.Response(status_int=202)
|
||||
@ -147,10 +139,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _begin_detaching(self, req, id, body):
|
||||
"""Update volume status to 'detaching'."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
self.volume_api.begin_detaching(context, volume)
|
||||
return webob.Response(status_int=202)
|
||||
@ -159,10 +149,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _roll_detaching(self, req, id, body):
|
||||
"""Roll back volume status to 'in-use'."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
self.volume_api.roll_detaching(context, volume)
|
||||
return webob.Response(status_int=202)
|
||||
@ -171,10 +159,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _initialize_connection(self, req, id, body):
|
||||
"""Initialize volume attachment."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
try:
|
||||
connector = body['os-initialize_connection']['connector']
|
||||
except KeyError:
|
||||
@ -187,7 +173,7 @@ class VolumeActionsController(wsgi.Controller):
|
||||
except exception.InvalidInput as err:
|
||||
raise webob.exc.HTTPBadRequest(
|
||||
explanation=err)
|
||||
except exception.VolumeBackendAPIException as error:
|
||||
except exception.VolumeBackendAPIException:
|
||||
msg = _("Unable to fetch connection information from backend.")
|
||||
raise webob.exc.HTTPInternalServerError(explanation=msg)
|
||||
|
||||
@ -197,10 +183,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _terminate_connection(self, req, id, body):
|
||||
"""Terminate volume attachment."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
try:
|
||||
connector = body['os-terminate_connection']['connector']
|
||||
except KeyError:
|
||||
@ -208,7 +192,7 @@ class VolumeActionsController(wsgi.Controller):
|
||||
explanation=_("Must specify 'connector'"))
|
||||
try:
|
||||
self.volume_api.terminate_connection(context, volume, connector)
|
||||
except exception.VolumeBackendAPIException as error:
|
||||
except exception.VolumeBackendAPIException:
|
||||
msg = _("Unable to terminate volume connection from backend.")
|
||||
raise webob.exc.HTTPInternalServerError(explanation=msg)
|
||||
return webob.Response(status_int=202)
|
||||
@ -232,10 +216,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
msg = _("Invalid value for 'force': '%s'") % err_msg
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
authorize(context, "upload_image")
|
||||
# check for valid disk-format
|
||||
@ -292,10 +274,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _extend(self, req, id, body):
|
||||
"""Extend size of volume."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
try:
|
||||
size = int(body['os-extend']['new_size'])
|
||||
@ -314,10 +294,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _volume_readonly_update(self, req, id, body):
|
||||
"""Update volume readonly flag."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
try:
|
||||
readonly_flag = body['os-update_readonly_flag']['readonly']
|
||||
@ -355,10 +333,8 @@ class VolumeActionsController(wsgi.Controller):
|
||||
def _set_bootable(self, req, id, body):
|
||||
"""Update bootable status of a volume."""
|
||||
context = req.environ['cinder.context']
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
|
||||
try:
|
||||
bootable = body['os-set_bootable']['bootable']
|
||||
|
@ -37,12 +37,9 @@ class VolumeImageMetadataController(wsgi.Controller):
|
||||
self.volume_api = volume.API()
|
||||
|
||||
def _get_image_metadata(self, context, volume_id):
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
meta = self.volume_api.get_volume_image_metadata(context, volume)
|
||||
except exception.VolumeNotFound:
|
||||
msg = _('Volume with volume id %s does not exist.') % volume_id
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
meta = self.volume_api.get_volume_image_metadata(context, volume)
|
||||
return (volume, meta)
|
||||
|
||||
def _add_image_metadata(self, context, resp_volume_list, image_metas=None):
|
||||
@ -113,9 +110,7 @@ class VolumeImageMetadataController(wsgi.Controller):
|
||||
metadata,
|
||||
delete=False,
|
||||
meta_type=common.METADATA_TYPES.image)
|
||||
except exception.VolumeNotFound:
|
||||
msg = _('Volume with volume id %s does not exist.') % volume_id
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except (ValueError, AttributeError):
|
||||
msg = _("Malformed request body.")
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
@ -143,8 +138,7 @@ class VolumeImageMetadataController(wsgi.Controller):
|
||||
if key:
|
||||
vol, metadata = self._get_image_metadata(context, id)
|
||||
if key not in metadata:
|
||||
msg = _("Metadata item was not found.")
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.GlanceMetadataNotFound(id=id)
|
||||
|
||||
self.volume_api.delete_volume_metadata(
|
||||
context, vol, key,
|
||||
|
@ -21,7 +21,6 @@ from cinder.api import extensions
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.v2.views import volumes as volume_views
|
||||
from cinder.api.views import manageable_volumes as list_manageable_view
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
from cinder import utils
|
||||
from cinder import volume as cinder_volume
|
||||
@ -120,16 +119,14 @@ class VolumeManageController(wsgi.Controller):
|
||||
kwargs = {}
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
try:
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
except exception.VolumeTypeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = {}
|
||||
|
||||
@ -138,13 +135,11 @@ class VolumeManageController(wsgi.Controller):
|
||||
kwargs['metadata'] = volume.get('metadata', None)
|
||||
kwargs['availability_zone'] = volume.get('availability_zone', None)
|
||||
kwargs['bootable'] = utils.get_bool_param('bootable', volume)
|
||||
try:
|
||||
new_volume = self.volume_api.manage_existing(context,
|
||||
volume['host'],
|
||||
volume['ref'],
|
||||
**kwargs)
|
||||
except exception.ServiceNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at wsgi level
|
||||
new_volume = self.volume_api.manage_existing(context,
|
||||
volume['host'],
|
||||
volume['ref'],
|
||||
**kwargs)
|
||||
|
||||
utils.add_visible_admin_metadata(new_volume)
|
||||
|
||||
|
@ -41,10 +41,8 @@ class VolumeTransferController(wsgi.Controller):
|
||||
"""Return data about active transfers."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
transfer = self.transfer_api.get(context, transfer_id=id)
|
||||
except exception.TransferNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
transfer = self.transfer_api.get(context, transfer_id=id)
|
||||
|
||||
return self._view_builder.detail(req, transfer)
|
||||
|
||||
@ -102,10 +100,9 @@ class VolumeTransferController(wsgi.Controller):
|
||||
|
||||
try:
|
||||
new_transfer = self.transfer_api.create(context, volume_id, name)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.InvalidVolume as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
|
||||
transfer = self._view_builder.create(req,
|
||||
dict(new_transfer))
|
||||
@ -150,10 +147,8 @@ class VolumeTransferController(wsgi.Controller):
|
||||
|
||||
LOG.info(_LI("Delete transfer with id: %s"), id, context=context)
|
||||
|
||||
try:
|
||||
self.transfer_api.delete(context, transfer_id=id)
|
||||
except exception.TransferNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
self.transfer_api.delete(context, transfer_id=id)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
@ -45,15 +45,13 @@ class VolumeTypeAccessController(object):
|
||||
context = req.environ['cinder.context']
|
||||
authorize(context)
|
||||
|
||||
try:
|
||||
vol_type = volume_types.get_volume_type(
|
||||
context, type_id, expected_fields=['projects'])
|
||||
except exception.VolumeTypeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
vol_type = volume_types.get_volume_type(
|
||||
context, type_id, expected_fields=['projects'])
|
||||
|
||||
if vol_type['is_public']:
|
||||
expl = _("Access list not available for public volume types.")
|
||||
raise webob.exc.HTTPNotFound(explanation=expl)
|
||||
raise exception.VolumeTypeAccessNotFound(message=expl)
|
||||
|
||||
return _marshall_volume_type_access(vol_type)
|
||||
|
||||
@ -117,10 +115,9 @@ class VolumeTypeActionController(wsgi.Controller):
|
||||
|
||||
try:
|
||||
volume_types.add_volume_type_access(context, id, project)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except exception.VolumeTypeAccessExists as err:
|
||||
raise webob.exc.HTTPConflict(explanation=six.text_type(err))
|
||||
except exception.VolumeTypeNotFound as err:
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('removeProjectAccess')
|
||||
@ -130,11 +127,8 @@ class VolumeTypeActionController(wsgi.Controller):
|
||||
self._check_body(body, 'removeProjectAccess')
|
||||
project = body['removeProjectAccess']['project']
|
||||
|
||||
try:
|
||||
volume_types.remove_volume_type_access(context, id, project)
|
||||
except (exception.VolumeTypeNotFound,
|
||||
exception.VolumeTypeAccessNotFound) as err:
|
||||
raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume_types.remove_volume_type_access(context, id, project)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
@ -45,10 +45,8 @@ class VolumeTypeEncryptionController(wsgi.Controller):
|
||||
return encryption_specs
|
||||
|
||||
def _check_type(self, context, type_id):
|
||||
try:
|
||||
volume_types.get_volume_type(context, type_id)
|
||||
except exception.VolumeTypeNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume_types.get_volume_type(context, type_id)
|
||||
|
||||
def _check_encryption_input(self, encryption, create=True):
|
||||
if encryption.get('key_size') is not None:
|
||||
@ -153,7 +151,7 @@ class VolumeTypeEncryptionController(wsgi.Controller):
|
||||
encryption_specs = self._get_volume_type_encryption(context, type_id)
|
||||
|
||||
if id not in encryption_specs:
|
||||
raise webob.exc.HTTPNotFound()
|
||||
raise exception.VolumeTypeEncryptionNotFound(type_id=type_id)
|
||||
|
||||
return {id: encryption_specs[id]}
|
||||
|
||||
@ -166,10 +164,8 @@ class VolumeTypeEncryptionController(wsgi.Controller):
|
||||
expl = _('Cannot delete encryption specs. Volume type in use.')
|
||||
raise webob.exc.HTTPBadRequest(explanation=expl)
|
||||
else:
|
||||
try:
|
||||
# Not found exception will be handled at the wsgi level
|
||||
db.volume_type_encryption_delete(context, type_id)
|
||||
except exception.VolumeTypeEncryptionNotFound as ex:
|
||||
raise webob.exc.HTTPNotFound(explanation=ex.msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
@ -14,11 +14,9 @@
|
||||
|
||||
from oslo_log import log as logging
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
from cinder.api import extensions
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder import exception
|
||||
from cinder.i18n import _LI
|
||||
from cinder import volume
|
||||
|
||||
@ -53,11 +51,9 @@ class VolumeUnmanageController(wsgi.Controller):
|
||||
|
||||
LOG.info(_LI("Unmanage volume with id: %s"), id, context=context)
|
||||
|
||||
try:
|
||||
vol = self.volume_api.get(context, id)
|
||||
self.volume_api.delete(context, vol, unmanage_only=True)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
vol = self.volume_api.get(context, id)
|
||||
self.volume_api.delete(context, vol, unmanage_only=True)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
@ -30,12 +30,9 @@ class Controller(wsgi.Controller):
|
||||
super(Controller, self).__init__()
|
||||
|
||||
def _get_metadata(self, context, snapshot_id):
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
meta = self.volume_api.get_snapshot_metadata(context, snapshot)
|
||||
except exception.SnapshotNotFound:
|
||||
msg = _('snapshot does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
meta = self.volume_api.get_snapshot_metadata(context, snapshot)
|
||||
return meta
|
||||
|
||||
def index(self, req, snapshot_id):
|
||||
@ -106,10 +103,7 @@ class Controller(wsgi.Controller):
|
||||
snapshot,
|
||||
metadata,
|
||||
delete)
|
||||
except exception.SnapshotNotFound:
|
||||
msg = _('snapshot does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except (ValueError, AttributeError):
|
||||
msg = _("Malformed request body")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
@ -128,8 +122,8 @@ class Controller(wsgi.Controller):
|
||||
try:
|
||||
return {'meta': {id: data[id]}}
|
||||
except KeyError:
|
||||
msg = _("Metadata item was not found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.SnapshotMetadataNotFound(snapshot_id=snapshot_id,
|
||||
metadata_key=id)
|
||||
|
||||
def delete(self, req, snapshot_id, id):
|
||||
"""Deletes an existing metadata."""
|
||||
@ -138,15 +132,12 @@ class Controller(wsgi.Controller):
|
||||
metadata = self._get_metadata(context, snapshot_id)
|
||||
|
||||
if id not in metadata:
|
||||
msg = _("Metadata item was not found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.SnapshotMetadataNotFound(snapshot_id=snapshot_id,
|
||||
metadata_key=id)
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
self.volume_api.delete_snapshot_metadata(context, snapshot, id)
|
||||
except exception.SnapshotNotFound:
|
||||
msg = _('snapshot does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
self.volume_api.delete_snapshot_metadata(context, snapshot, id)
|
||||
return webob.Response(status_int=200)
|
||||
|
||||
|
||||
|
@ -72,11 +72,9 @@ class SnapshotsController(wsgi.Controller):
|
||||
"""Return data about the given snapshot."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
req.cache_db_snapshot(snapshot)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
req.cache_db_snapshot(snapshot)
|
||||
|
||||
return {'snapshot': _translate_snapshot_detail_view(snapshot)}
|
||||
|
||||
@ -86,11 +84,9 @@ class SnapshotsController(wsgi.Controller):
|
||||
|
||||
LOG.info(_LI("Delete snapshot with id: %s"), id, context=context)
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.delete_snapshot(context, snapshot)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.delete_snapshot(context, snapshot)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
def index(self, req):
|
||||
@ -139,10 +135,8 @@ class SnapshotsController(wsgi.Controller):
|
||||
msg = _("'volume_id' must be specified")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
|
||||
force = snapshot.get('force', False)
|
||||
msg = _LI("Create snapshot from volume %s")
|
||||
@ -194,11 +188,9 @@ class SnapshotsController(wsgi.Controller):
|
||||
if key in snapshot:
|
||||
update_dict[key] = snapshot[key]
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.update_snapshot(context, snapshot, update_dict)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.update_snapshot(context, snapshot, update_dict)
|
||||
|
||||
snapshot.update(update_dict)
|
||||
req.cache_db_snapshot(snapshot)
|
||||
|
@ -15,11 +15,8 @@
|
||||
|
||||
"""The volume type & volume types extra specs extension."""
|
||||
|
||||
from webob import exc
|
||||
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.views import types as views_types
|
||||
from cinder import exception
|
||||
from cinder.volume import volume_types
|
||||
|
||||
|
||||
@ -40,11 +37,9 @@ class VolumeTypesController(wsgi.Controller):
|
||||
"""Return a single volume type item."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
vol_type = volume_types.get_volume_type(context, id)
|
||||
req.cache_resource(vol_type, name='types')
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
vol_type = volume_types.get_volume_type(context, id)
|
||||
req.cache_resource(vol_type, name='types')
|
||||
|
||||
return self._view_builder.show(req, vol_type)
|
||||
|
||||
|
@ -30,12 +30,9 @@ class Controller(wsgi.Controller):
|
||||
super(Controller, self).__init__()
|
||||
|
||||
def _get_metadata(self, context, volume_id):
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
meta = self.volume_api.get_volume_metadata(context, volume)
|
||||
except exception.VolumeNotFound:
|
||||
msg = _('volume does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
meta = self.volume_api.get_volume_metadata(context, volume)
|
||||
return meta
|
||||
|
||||
def index(self, req, volume_id):
|
||||
@ -106,10 +103,7 @@ class Controller(wsgi.Controller):
|
||||
volume,
|
||||
metadata,
|
||||
delete)
|
||||
except exception.VolumeNotFound:
|
||||
msg = _('volume does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except (ValueError, AttributeError):
|
||||
msg = _("Malformed request body")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
@ -128,8 +122,8 @@ class Controller(wsgi.Controller):
|
||||
try:
|
||||
return {'meta': {id: data[id]}}
|
||||
except KeyError:
|
||||
msg = _("Metadata item was not found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.VolumeMetadataNotFound(volume_id=volume_id,
|
||||
metadata_key=id)
|
||||
|
||||
def delete(self, req, volume_id, id):
|
||||
"""Deletes an existing metadata."""
|
||||
@ -138,15 +132,12 @@ class Controller(wsgi.Controller):
|
||||
metadata = self._get_metadata(context, volume_id)
|
||||
|
||||
if id not in metadata:
|
||||
msg = _("Metadata item was not found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.VolumeMetadataNotFound(volume_id=volume_id,
|
||||
metadata_key=id)
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
self.volume_api.delete_volume_metadata(context, volume, id)
|
||||
except exception.VolumeNotFound:
|
||||
msg = _('volume does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
self.volume_api.delete_volume_metadata(context, volume, id)
|
||||
return webob.Response(status_int=200)
|
||||
|
||||
|
||||
|
@ -24,7 +24,6 @@ from webob import exc
|
||||
|
||||
from cinder.api import common
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder import exception
|
||||
from cinder.i18n import _, _LI
|
||||
from cinder import utils
|
||||
from cinder import volume as cinder_volume
|
||||
@ -137,11 +136,9 @@ class VolumeController(wsgi.Controller):
|
||||
"""Return data about the given volume."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
vol = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
req.cache_db_volume(vol)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
vol = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
req.cache_db_volume(vol)
|
||||
|
||||
utils.add_visible_admin_metadata(vol)
|
||||
|
||||
@ -153,11 +150,9 @@ class VolumeController(wsgi.Controller):
|
||||
|
||||
LOG.info(_LI("Delete volume with id: %s"), id, context=context)
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
self.volume_api.delete(context, volume)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
self.volume_api.delete(context, volume)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
def index(self, req):
|
||||
@ -230,41 +225,30 @@ class VolumeController(wsgi.Controller):
|
||||
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
try:
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
except exception.VolumeTypeNotFound:
|
||||
explanation = 'Volume type not found.'
|
||||
raise exc.HTTPNotFound(explanation=explanation)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
|
||||
kwargs['metadata'] = volume.get('metadata', None)
|
||||
|
||||
snapshot_id = volume.get('snapshot_id')
|
||||
if snapshot_id is not None:
|
||||
try:
|
||||
kwargs['snapshot'] = self.volume_api.get_snapshot(context,
|
||||
snapshot_id)
|
||||
except exception.NotFound:
|
||||
explanation = _('snapshot id:%s not found') % snapshot_id
|
||||
raise exc.HTTPNotFound(explanation=explanation)
|
||||
|
||||
# Not found exception will be handled at the wsgi level
|
||||
kwargs['snapshot'] = self.volume_api.get_snapshot(context,
|
||||
snapshot_id)
|
||||
else:
|
||||
kwargs['snapshot'] = None
|
||||
|
||||
source_volid = volume.get('source_volid')
|
||||
if source_volid is not None:
|
||||
try:
|
||||
kwargs['source_volume'] = \
|
||||
self.volume_api.get_volume(context,
|
||||
source_volid)
|
||||
except exception.NotFound:
|
||||
explanation = _('source vol id:%s not found') % source_volid
|
||||
raise exc.HTTPNotFound(explanation=explanation)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
kwargs['source_volume'] = self.volume_api.get_volume(context,
|
||||
source_volid)
|
||||
else:
|
||||
kwargs['source_volume'] = None
|
||||
|
||||
@ -326,13 +310,11 @@ class VolumeController(wsgi.Controller):
|
||||
if key in volume:
|
||||
update_dict[key] = volume[key]
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
volume_utils.notify_about_volume_usage(context, volume,
|
||||
'update.start')
|
||||
self.volume_api.update(context, volume, update_dict)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
volume_utils.notify_about_volume_usage(context, volume,
|
||||
'update.start')
|
||||
self.volume_api.update(context, volume, update_dict)
|
||||
|
||||
volume.update(update_dict)
|
||||
|
||||
|
@ -30,12 +30,9 @@ class Controller(wsgi.Controller):
|
||||
super(Controller, self).__init__()
|
||||
|
||||
def _get_metadata(self, context, snapshot_id):
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
meta = self.volume_api.get_snapshot_metadata(context, snapshot)
|
||||
except exception.SnapshotNotFound:
|
||||
msg = _('snapshot does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
meta = self.volume_api.get_snapshot_metadata(context, snapshot)
|
||||
return meta
|
||||
|
||||
def index(self, req, snapshot_id):
|
||||
@ -96,10 +93,7 @@ class Controller(wsgi.Controller):
|
||||
snapshot,
|
||||
metadata,
|
||||
delete)
|
||||
except exception.SnapshotNotFound:
|
||||
msg = _('snapshot does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except (ValueError, AttributeError):
|
||||
msg = _("Malformed request body")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
@ -118,8 +112,8 @@ class Controller(wsgi.Controller):
|
||||
try:
|
||||
return {'meta': {id: data[id]}}
|
||||
except KeyError:
|
||||
msg = _("Metadata item was not found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.SnapshotMetadataNotFound(snapshot_id=snapshot_id,
|
||||
metadata_key=id)
|
||||
|
||||
def delete(self, req, snapshot_id, id):
|
||||
"""Deletes an existing metadata."""
|
||||
@ -128,15 +122,12 @@ class Controller(wsgi.Controller):
|
||||
metadata = self._get_metadata(context, snapshot_id)
|
||||
|
||||
if id not in metadata:
|
||||
msg = _("Metadata item was not found")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.SnapshotMetadataNotFound(snapshot_id=snapshot_id,
|
||||
metadata_key=id)
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
self.volume_api.delete_snapshot_metadata(context, snapshot, id)
|
||||
except exception.SnapshotNotFound:
|
||||
msg = _('snapshot does not exist')
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, snapshot_id)
|
||||
self.volume_api.delete_snapshot_metadata(context, snapshot, id)
|
||||
return webob.Response(status_int=200)
|
||||
|
||||
|
||||
|
@ -48,11 +48,9 @@ class SnapshotsController(wsgi.Controller):
|
||||
"""Return data about the given snapshot."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
req.cache_db_snapshot(snapshot)
|
||||
except exception.SnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
req.cache_db_snapshot(snapshot)
|
||||
|
||||
return self._view_builder.detail(req, snapshot)
|
||||
|
||||
@ -62,11 +60,9 @@ class SnapshotsController(wsgi.Controller):
|
||||
|
||||
LOG.info(_LI("Delete snapshot with id: %s"), id, context=context)
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.delete_snapshot(context, snapshot)
|
||||
except exception.SnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
self.volume_api.delete_snapshot(context, snapshot)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@ -130,10 +126,7 @@ class SnapshotsController(wsgi.Controller):
|
||||
msg = _("'volume_id' must be specified")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
force = snapshot.get('force', False)
|
||||
msg = _LI("Create snapshot from volume %s")
|
||||
LOG.info(msg, volume_id, context=context)
|
||||
@ -205,13 +198,11 @@ class SnapshotsController(wsgi.Controller):
|
||||
if key in snapshot:
|
||||
update_dict[key] = snapshot[key]
|
||||
|
||||
try:
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
volume_utils.notify_about_snapshot_usage(context, snapshot,
|
||||
'update.start')
|
||||
self.volume_api.update_snapshot(context, snapshot, update_dict)
|
||||
except exception.SnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
snapshot = self.volume_api.get_snapshot(context, id)
|
||||
volume_utils.notify_about_snapshot_usage(context, snapshot,
|
||||
'update.start')
|
||||
self.volume_api.update_snapshot(context, snapshot, update_dict)
|
||||
|
||||
snapshot.update(update_dict)
|
||||
req.cache_db_snapshot(snapshot)
|
||||
|
@ -47,14 +47,12 @@ class VolumeTypesController(wsgi.Controller):
|
||||
vol_type = volume_types.get_default_volume_type()
|
||||
if not vol_type:
|
||||
msg = _("Default volume type can not be found.")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.VolumeTypeNotFound(message=msg)
|
||||
req.cache_resource(vol_type, name='types')
|
||||
else:
|
||||
try:
|
||||
vol_type = volume_types.get_volume_type(context, id)
|
||||
req.cache_resource(vol_type, name='types')
|
||||
except exception.VolumeTypeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at wsgi level
|
||||
vol_type = volume_types.get_volume_type(context, id)
|
||||
req.cache_resource(vol_type, name='types')
|
||||
|
||||
return self._view_builder.show(req, vol_type)
|
||||
|
||||
|
@ -35,11 +35,9 @@ class Controller(wsgi.Controller):
|
||||
return self._get_volume_and_metadata(context, volume_id)[1]
|
||||
|
||||
def _get_volume_and_metadata(self, context, volume_id):
|
||||
try:
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
meta = self.volume_api.get_volume_metadata(context, volume)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, volume_id)
|
||||
meta = self.volume_api.get_volume_metadata(context, volume)
|
||||
return (volume, meta)
|
||||
|
||||
def index(self, req, volume_id):
|
||||
@ -102,9 +100,7 @@ class Controller(wsgi.Controller):
|
||||
metadata,
|
||||
delete,
|
||||
meta_type=common.METADATA_TYPES.user)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
|
||||
# Not found exception will be handled at the wsgi level
|
||||
except (ValueError, AttributeError):
|
||||
msg = _("Malformed request body")
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
@ -123,8 +119,8 @@ class Controller(wsgi.Controller):
|
||||
try:
|
||||
return {'meta': {id: data[id]}}
|
||||
except KeyError:
|
||||
msg = _("Metadata item was not found")
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.VolumeMetadataNotFound(volume_id=volume_id,
|
||||
metadata_key=id)
|
||||
|
||||
def delete(self, req, volume_id, id):
|
||||
"""Deletes an existing metadata."""
|
||||
@ -133,17 +129,15 @@ class Controller(wsgi.Controller):
|
||||
volume, metadata = self._get_volume_and_metadata(context, volume_id)
|
||||
|
||||
if id not in metadata:
|
||||
msg = _("Metadata item was not found")
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
raise exception.VolumeMetadataNotFound(volume_id=volume_id,
|
||||
metadata_key=id)
|
||||
|
||||
try:
|
||||
self.volume_api.delete_volume_metadata(
|
||||
context,
|
||||
volume,
|
||||
id,
|
||||
meta_type=common.METADATA_TYPES.user)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
self.volume_api.delete_volume_metadata(
|
||||
context,
|
||||
volume,
|
||||
id,
|
||||
meta_type=common.METADATA_TYPES.user)
|
||||
return webob.Response(status_int=200)
|
||||
|
||||
|
||||
|
@ -54,11 +54,9 @@ class VolumeController(wsgi.Controller):
|
||||
"""Return data about the given volume."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
vol = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
req.cache_db_volume(vol)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
vol = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
req.cache_db_volume(vol)
|
||||
|
||||
utils.add_visible_admin_metadata(vol)
|
||||
|
||||
@ -72,11 +70,9 @@ class VolumeController(wsgi.Controller):
|
||||
|
||||
LOG.info(_LI("Delete volume with id: %s"), id, context=context)
|
||||
|
||||
try:
|
||||
volume = self.volume_api.get(context, id)
|
||||
self.volume_api.delete(context, volume, cascade=cascade)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
volume = self.volume_api.get(context, id)
|
||||
self.volume_api.delete(context, volume, cascade=cascade)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
def index(self, req):
|
||||
@ -201,63 +197,53 @@ class VolumeController(wsgi.Controller):
|
||||
|
||||
req_volume_type = volume.get('volume_type', None)
|
||||
if req_volume_type:
|
||||
try:
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
# Not found exception will be handled at the wsgi level
|
||||
if not uuidutils.is_uuid_like(req_volume_type):
|
||||
kwargs['volume_type'] = \
|
||||
volume_types.get_volume_type_by_name(
|
||||
context, req_volume_type)
|
||||
except exception.VolumeTypeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
else:
|
||||
kwargs['volume_type'] = volume_types.get_volume_type(
|
||||
context, req_volume_type)
|
||||
|
||||
kwargs['metadata'] = volume.get('metadata', None)
|
||||
|
||||
snapshot_id = volume.get('snapshot_id')
|
||||
if snapshot_id is not None:
|
||||
try:
|
||||
kwargs['snapshot'] = self.volume_api.get_snapshot(context,
|
||||
snapshot_id)
|
||||
except exception.SnapshotNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
kwargs['snapshot'] = self.volume_api.get_snapshot(context,
|
||||
snapshot_id)
|
||||
else:
|
||||
kwargs['snapshot'] = None
|
||||
|
||||
source_volid = volume.get('source_volid')
|
||||
if source_volid is not None:
|
||||
try:
|
||||
kwargs['source_volume'] = \
|
||||
self.volume_api.get_volume(context,
|
||||
source_volid)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
kwargs['source_volume'] = \
|
||||
self.volume_api.get_volume(context,
|
||||
source_volid)
|
||||
else:
|
||||
kwargs['source_volume'] = None
|
||||
|
||||
source_replica = volume.get('source_replica')
|
||||
if source_replica is not None:
|
||||
try:
|
||||
src_vol = self.volume_api.get_volume(context,
|
||||
source_replica)
|
||||
if src_vol['replication_status'] == 'disabled':
|
||||
explanation = _('source volume id:%s is not'
|
||||
' replicated') % source_replica
|
||||
raise exc.HTTPBadRequest(explanation=explanation)
|
||||
kwargs['source_replica'] = src_vol
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
src_vol = self.volume_api.get_volume(context,
|
||||
source_replica)
|
||||
if src_vol['replication_status'] == 'disabled':
|
||||
explanation = _('source volume id:%s is not'
|
||||
' replicated') % source_replica
|
||||
raise exc.HTTPBadRequest(explanation=explanation)
|
||||
kwargs['source_replica'] = src_vol
|
||||
else:
|
||||
kwargs['source_replica'] = None
|
||||
|
||||
consistencygroup_id = volume.get('consistencygroup_id')
|
||||
if consistencygroup_id is not None:
|
||||
try:
|
||||
kwargs['consistencygroup'] = \
|
||||
self.consistencygroup_api.get(context,
|
||||
consistencygroup_id)
|
||||
except exception.ConsistencyGroupNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
kwargs['consistencygroup'] = \
|
||||
self.consistencygroup_api.get(context,
|
||||
consistencygroup_id)
|
||||
else:
|
||||
kwargs['consistencygroup'] = None
|
||||
|
||||
@ -334,15 +320,12 @@ class VolumeController(wsgi.Controller):
|
||||
if 'description' in update_dict:
|
||||
update_dict['display_description'] = update_dict.pop('description')
|
||||
|
||||
# Not found and Invalid exceptions will be handled at the wsgi level
|
||||
try:
|
||||
volume = self.volume_api.get(context, id, viewable_admin_meta=True)
|
||||
volume_utils.notify_about_volume_usage(context, volume,
|
||||
'update.start')
|
||||
self.volume_api.update(context, volume, update_dict)
|
||||
except exception.VolumeNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
except exception.InvalidVolumeMetadata as error:
|
||||
raise webob.exc.HTTPBadRequest(explanation=error.msg)
|
||||
except exception.InvalidVolumeMetadataSize as error:
|
||||
raise webob.exc.HTTPRequestEntityTooLarge(explanation=error.msg)
|
||||
|
||||
|
@ -15,12 +15,10 @@
|
||||
|
||||
from oslo_config import cfg
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
from cinder.api import common
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.v3.views import messages as messages_view
|
||||
from cinder import exception
|
||||
from cinder.message import api as message_api
|
||||
from cinder.message import defined_messages
|
||||
import cinder.policy
|
||||
@ -56,10 +54,8 @@ class MessagesController(wsgi.Controller):
|
||||
"""Return the given message."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
message = self.message_api.get(context, id)
|
||||
except exception.MessageNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
message = self.message_api.get(context, id)
|
||||
|
||||
check_policy(context, 'get', message)
|
||||
|
||||
@ -74,12 +70,10 @@ class MessagesController(wsgi.Controller):
|
||||
"""Delete a message."""
|
||||
context = req.environ['cinder.context']
|
||||
|
||||
try:
|
||||
message = self.message_api.get(context, id)
|
||||
check_policy(context, 'delete', message)
|
||||
self.message_api.delete(context, message)
|
||||
except exception.MessageNotFound as error:
|
||||
raise exc.HTTPNotFound(explanation=error.msg)
|
||||
# Not found exception will be handled at the wsgi level
|
||||
message = self.message_api.get(context, id)
|
||||
check_policy(context, 'delete', message)
|
||||
self.message_api.delete(context, message)
|
||||
|
||||
return webob.Response(status_int=204)
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import webob
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
@ -101,30 +99,26 @@ def get_project_hierarchy(context, project_id, subtree_as_ids=False,
|
||||
If the domain is being used as the top most parent, it is filtered out from
|
||||
the parent tree and parent_id.
|
||||
"""
|
||||
try:
|
||||
keystone = _keystone_client(context)
|
||||
generic_project = GenericProjectInfo(project_id, keystone.version)
|
||||
if keystone.version == 'v3':
|
||||
project = keystone.projects.get(project_id,
|
||||
subtree_as_ids=subtree_as_ids,
|
||||
parents_as_ids=parents_as_ids)
|
||||
keystone = _keystone_client(context)
|
||||
generic_project = GenericProjectInfo(project_id, keystone.version)
|
||||
if keystone.version == 'v3':
|
||||
project = keystone.projects.get(project_id,
|
||||
subtree_as_ids=subtree_as_ids,
|
||||
parents_as_ids=parents_as_ids)
|
||||
|
||||
generic_project.parent_id = None
|
||||
if project.parent_id != project.domain_id:
|
||||
generic_project.parent_id = project.parent_id
|
||||
generic_project.parent_id = None
|
||||
if project.parent_id != project.domain_id:
|
||||
generic_project.parent_id = project.parent_id
|
||||
|
||||
generic_project.subtree = (
|
||||
project.subtree if subtree_as_ids else None)
|
||||
generic_project.subtree = (
|
||||
project.subtree if subtree_as_ids else None)
|
||||
|
||||
generic_project.parents = None
|
||||
if parents_as_ids:
|
||||
generic_project.parents = _filter_domain_id_from_parents(
|
||||
project.domain_id, project.parents)
|
||||
generic_project.parents = None
|
||||
if parents_as_ids:
|
||||
generic_project.parents = _filter_domain_id_from_parents(
|
||||
project.domain_id, project.parents)
|
||||
|
||||
generic_project.is_admin_project = is_admin_project
|
||||
except exceptions.NotFound:
|
||||
msg = (_("Tenant ID: %s does not exist.") % project_id)
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
generic_project.is_admin_project = is_admin_project
|
||||
|
||||
return generic_project
|
||||
|
||||
|
@ -21,6 +21,7 @@ import webob.exc
|
||||
|
||||
from cinder.api.contrib import hosts as os_hosts
|
||||
from cinder import context
|
||||
from cinder import exception
|
||||
from cinder import test
|
||||
|
||||
|
||||
@ -134,7 +135,7 @@ class HostTestCase(test.TestCase):
|
||||
self.req, 'test.host.1', body=body)
|
||||
|
||||
def test_bad_host(self):
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.HostNotFound,
|
||||
self.controller.update,
|
||||
self.req,
|
||||
'bogus_host_name',
|
||||
@ -152,6 +153,6 @@ class HostTestCase(test.TestCase):
|
||||
"""A host given as an argument does not exists."""
|
||||
self.req.environ['cinder.context'].is_admin = True
|
||||
dest = 'dummydest'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.ServiceNotFound,
|
||||
self.controller.show,
|
||||
self.req, dest)
|
||||
|
@ -288,8 +288,9 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
|
||||
(fake.PROJECT_ID,
|
||||
fake.WILL_NOT_BE_FOUND_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID)
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.delete, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID)
|
||||
self.assertEqual(1, notifier.get_notification_count())
|
||||
|
||||
@mock.patch('cinder.volume.qos_specs.get_qos_specs',
|
||||
@ -355,7 +356,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
|
||||
notifier = fake_notifier.get_fake_notifier()
|
||||
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.delete_keys,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
self.assertEqual(1, notifier.get_notification_count())
|
||||
@ -369,7 +370,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
|
||||
notifier = fake_notifier.get_fake_notifier()
|
||||
with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.assertRaises(exception.QoSSpecsKeyNotFound,
|
||||
self.controller.delete_keys,
|
||||
req, fake.IN_USE_ID, body)
|
||||
self.assertEqual(1, notifier.get_notification_count())
|
||||
@ -490,7 +491,8 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
fake.WILL_NOT_BE_FOUND_ID))
|
||||
body = {'qos_specs': {'key1': 'value1',
|
||||
'key2': 'value2'}}
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.update,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
self.assertEqual(1, notifier.get_notification_count())
|
||||
|
||||
@ -503,7 +505,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
(fake.PROJECT_ID, fake.INVALID_ID))
|
||||
body = {'qos_specs': {'key1': 'value1',
|
||||
'key2': 'value2'}}
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.assertRaises(exception.InvalidQoSSpecs,
|
||||
self.controller.update,
|
||||
req, fake.INVALID_ID, body)
|
||||
self.assertEqual(1, notifier.get_notification_count())
|
||||
@ -553,7 +555,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/%s/qos-specs/%s/associations' %
|
||||
(fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.associations,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
@ -598,7 +600,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
'/v2/%s/qos-specs/%s/associate?vol_type_id=%s' % (
|
||||
fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID,
|
||||
fake.VOLUME_TYPE_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.associate, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
@ -606,7 +608,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
'/v2/%s/qos-specs/%s/associate?vol_type_id=%s' %
|
||||
(fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.WILL_NOT_BE_FOUND_ID))
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeTypeNotFound,
|
||||
self.controller.associate, req, fake.QOS_SPEC_ID)
|
||||
|
||||
@mock.patch('cinder.volume.qos_specs.get_qos_specs',
|
||||
@ -653,14 +655,14 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
'/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' % (
|
||||
fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID,
|
||||
fake.VOLUME_TYPE_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.disassociate, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' %
|
||||
(fake.PROJECT_ID, fake.VOLUME_TYPE_ID, fake.WILL_NOT_BE_FOUND_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeTypeNotFound,
|
||||
self.controller.disassociate, req,
|
||||
fake.VOLUME_TYPE_ID)
|
||||
|
||||
@ -695,7 +697,7 @@ class QoSSpecManageApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/%s/qos-specs/%s/disassociate_all' % (
|
||||
fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.QoSSpecsNotFound,
|
||||
self.controller.disassociate_all, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
|
@ -104,8 +104,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
return_empty_volume_type_extra_specs)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
req, fake.VOLUME_ID, 'key6')
|
||||
self.assertRaises(exception.VolumeTypeExtraSpecsNotFound,
|
||||
self.controller.show, req, fake.VOLUME_ID, 'key6')
|
||||
|
||||
def test_delete(self):
|
||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
|
||||
@ -121,8 +121,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||
delete_volume_type_extra_specs_not_found)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
req, fake.VOLUME_ID, 'key6')
|
||||
self.assertRaises(exception.VolumeTypeExtraSpecsNotFound,
|
||||
self.controller.delete, req, fake.VOLUME_ID, 'key6')
|
||||
|
||||
@mock.patch('cinder.utils.check_string_length')
|
||||
def test_create(self, mock_check):
|
||||
|
@ -168,8 +168,8 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s' % (
|
||||
fake.PROJECT_ID, NOT_FOUND_VOLUME_TYPE))
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller._delete,
|
||||
req, NOT_FOUND_VOLUME_TYPE)
|
||||
self.assertRaises(exception.VolumeTypeNotFound,
|
||||
self.controller._delete, req, NOT_FOUND_VOLUME_TYPE)
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_volume_types_with_volumes_destroy(self):
|
||||
@ -429,7 +429,7 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
req.method = 'PUT'
|
||||
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeTypeNotFound,
|
||||
self.controller._update, req,
|
||||
NOT_FOUND_VOLUME_TYPE, body)
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
@ -878,7 +878,7 @@ class VolumeImageActionsTest(test.TestCase):
|
||||
body = {"os-volume_upload_image": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/volumes/%s/action' %
|
||||
(fake.PROJECT_ID, id))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller._volume_upload_image,
|
||||
req,
|
||||
id,
|
||||
|
@ -255,7 +255,7 @@ class VolumeImageMetadataTest(test.TestCase):
|
||||
"metadata": {"image_name": "fake"}}
|
||||
}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.create, req, fake.VOLUME_ID, body)
|
||||
|
||||
def test_invalid_metadata_items_on_create(self):
|
||||
@ -318,7 +318,7 @@ class VolumeImageMetadataTest(test.TestCase):
|
||||
req.body = jsonutils.dump_as_bytes(data)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.GlanceMetadataNotFound,
|
||||
self.controller.delete, req, fake.VOLUME_ID, data)
|
||||
|
||||
def test_delete_nonexistent_volume(self):
|
||||
@ -334,7 +334,7 @@ class VolumeImageMetadataTest(test.TestCase):
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.GlanceMetadataNotFound,
|
||||
self.controller.delete, req, fake.VOLUME_ID, body)
|
||||
|
||||
def test_show_image_metadata(self):
|
||||
|
@ -132,7 +132,7 @@ class VolumeTypeAccessTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/os-volume-type-access' %
|
||||
fake.PROJECT_ID,
|
||||
use_admin_context=True)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeTypeAccessNotFound,
|
||||
self.type_access_controller.index,
|
||||
req, fake.VOLUME_TYPE2_ID)
|
||||
|
||||
@ -330,7 +330,7 @@ class VolumeTypeAccessTest(test.TestCase):
|
||||
body = {'removeProjectAccess': {'project': PROJ2_UUID}}
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s/action' % (
|
||||
fake.PROJECT_ID, fake.VOLUME_TYPE3_ID), use_admin_context=True)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeTypeAccessNotFound,
|
||||
self.type_action_controller._removeProjectAccess,
|
||||
req, fake.VOLUME_TYPE4_ID, body)
|
||||
|
||||
|
@ -147,7 +147,8 @@ class VolumeTypeEncryptionTest(test.TestCase):
|
||||
expected = {
|
||||
'itemNotFound': {
|
||||
'code': 404,
|
||||
'message': ('The resource could not be found.')
|
||||
'message': ('Volume type encryption for type %s does not '
|
||||
'exist.' % volume_type['id'])
|
||||
}
|
||||
}
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
@ -171,7 +171,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
exc.SnapshotNotFound(snapshot_id=fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotNotFound,
|
||||
self.controller.index, req, self.url)
|
||||
|
||||
@mock.patch('cinder.objects.Snapshot.get_by_id')
|
||||
@ -211,7 +211,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
exc.SnapshotNotFound(snapshot_id=fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotNotFound,
|
||||
self.controller.show, req, fake.SNAPSHOT_ID, 'key2')
|
||||
|
||||
@mock.patch('cinder.objects.Snapshot.get_by_id')
|
||||
@ -225,7 +225,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
snapshot_get_by_id.return_value = snapshot_obj
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotMetadataNotFound,
|
||||
self.controller.show, req, fake.SNAPSHOT_ID, 'key6')
|
||||
|
||||
@mock.patch('cinder.db.snapshot_metadata_delete')
|
||||
@ -249,7 +249,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
def test_delete_nonexistent_snapshot(self):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotNotFound,
|
||||
self.controller.delete, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, 'key1')
|
||||
|
||||
@ -265,7 +265,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotMetadataNotFound,
|
||||
self.controller.delete, req,
|
||||
fake.SNAPSHOT_ID, 'key6')
|
||||
|
||||
@ -375,7 +375,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotNotFound,
|
||||
self.controller.create, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
|
||||
@ -504,7 +504,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
body = {'metadata': {'key10': 'value10'}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotNotFound,
|
||||
self.controller.update_all, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
|
||||
@ -538,7 +538,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.SnapshotNotFound,
|
||||
self.controller.update, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, 'key1',
|
||||
body)
|
||||
|
@ -202,7 +202,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
}
|
||||
body = {"snapshot": updates}
|
||||
req = fakes.HTTPRequest.blank('/v1/snapshots/not-the-uuid')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update, req,
|
||||
self.assertRaises(exception.NotFound, self.controller.update, req,
|
||||
'not-the-uuid', body)
|
||||
|
||||
@mock.patch.object(volume.api.API, "delete_snapshot",
|
||||
@ -236,7 +236,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
self.stubs.Set(volume.api.API, "delete_snapshot", stub_snapshot_delete)
|
||||
snapshot_id = INVALID_UUID
|
||||
req = fakes.HTTPRequest.blank('/v1/snapshots/%s' % snapshot_id)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.delete,
|
||||
req,
|
||||
snapshot_id)
|
||||
@ -270,7 +270,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
def test_snapshot_show_invalid_id(self):
|
||||
snapshot_id = INVALID_UUID
|
||||
req = fakes.HTTPRequest.blank('/v1/snapshots/%s' % snapshot_id)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.show,
|
||||
req,
|
||||
snapshot_id)
|
||||
|
@ -16,7 +16,6 @@
|
||||
import uuid
|
||||
|
||||
from oslo_utils import timeutils
|
||||
import webob
|
||||
|
||||
from cinder.api.v1 import types
|
||||
from cinder.api.views import types as views_types
|
||||
@ -108,7 +107,7 @@ class VolumeTypesApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1/%s/types/%s' %
|
||||
(fake.PROJECT_ID,
|
||||
fake.WILL_NOT_BE_FOUND_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
self.assertRaises(exception.VolumeTypeNotFound, self.controller.show,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
def test_view_builder_show(self):
|
||||
|
@ -180,7 +180,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
|
||||
def test_index_nonexistent_volume(self):
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.index,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
@ -200,7 +200,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
|
||||
def test_show_nonexistent_volume(self):
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.show, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, 'key2')
|
||||
|
||||
@ -208,7 +208,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
self.stubs.Set(cinder.db, 'volume_metadata_get',
|
||||
return_empty_volume_metadata)
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeMetadataNotFound,
|
||||
self.controller.show, req, fake.VOLUME_ID, 'key6')
|
||||
|
||||
@mock.patch.object(cinder.db, 'volume_metadata_delete')
|
||||
@ -237,7 +237,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
req.method = 'DELETE'
|
||||
req.environ['cinder.context'] = fake_context
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
self.assertRaises(exc.VolumeNotFound, self.controller.delete,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID, 'key1')
|
||||
|
||||
def test_delete_meta_not_found(self):
|
||||
@ -245,7 +245,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
return_empty_volume_metadata)
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeMetadataNotFound,
|
||||
self.controller.delete, req, fake.VOLUME_ID, 'key6')
|
||||
|
||||
@mock.patch.object(cinder.db, 'volume_metadata_update')
|
||||
@ -349,7 +349,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.create, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
|
||||
@ -496,7 +496,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
body = {'metadata': {'key10': 'value10'}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.update_all, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
|
||||
@ -530,7 +530,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.update, req,
|
||||
fake.WILL_NOT_BE_FOUND_ID, 'key1',
|
||||
body)
|
||||
|
@ -98,8 +98,8 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes')
|
||||
# Raise 404 when type name isn't valid
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
|
||||
req, body)
|
||||
self.assertRaises(exc.VolumeTypeNotFoundByName,
|
||||
self.controller.create, req, body)
|
||||
# Use correct volume type name
|
||||
vol.update(dict(volume_type=CONF.default_volume_type))
|
||||
body.update(dict(volume=vol))
|
||||
@ -385,7 +385,7 @@ class VolumeApiTest(test.TestCase):
|
||||
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v1/volumes/%s' % fake.WILL_NOT_BE_FOUND_ID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.update,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID, body)
|
||||
|
||||
@ -650,7 +650,7 @@ class VolumeApiTest(test.TestCase):
|
||||
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v1/volumes/%s' % fake.WILL_NOT_BE_FOUND_ID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.show,
|
||||
req,
|
||||
fake.WILL_NOT_BE_FOUND_ID)
|
||||
@ -768,7 +768,7 @@ class VolumeApiTest(test.TestCase):
|
||||
def test_volume_delete_no_volume(self):
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v1/volumes/%s' % fake.WILL_NOT_BE_FOUND_ID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exc.VolumeNotFound,
|
||||
self.controller.delete,
|
||||
req,
|
||||
fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
@ -169,7 +169,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
exception.SnapshotNotFound(snapshot_id=self.req_id)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.index, req, self.url)
|
||||
|
||||
@mock.patch('cinder.objects.Snapshot.get_by_id')
|
||||
@ -209,7 +209,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
exception.SnapshotNotFound(snapshot_id=self.req_id)
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.show, req, self.req_id, 'key2')
|
||||
|
||||
@mock.patch('cinder.objects.Snapshot.get_by_id')
|
||||
@ -223,7 +223,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
snapshot_get_by_id.return_value = snapshot_obj
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotMetadataNotFound,
|
||||
self.controller.show, req, self.req_id, 'key6')
|
||||
|
||||
@mock.patch('cinder.db.snapshot_metadata_delete')
|
||||
@ -249,7 +249,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
return_snapshot_nonexistent)
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.delete, req, self.req_id, 'key1')
|
||||
|
||||
@mock.patch('cinder.objects.Snapshot.get_by_id')
|
||||
@ -264,7 +264,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotMetadataNotFound,
|
||||
self.controller.delete, req, self.req_id, 'key6')
|
||||
|
||||
@mock.patch('cinder.db.snapshot_update')
|
||||
@ -375,7 +375,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.create, req, self.req_id, body)
|
||||
|
||||
@mock.patch('cinder.db.snapshot_update')
|
||||
@ -503,7 +503,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
body = {'metadata': {'key10': 'value10'}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.update_all, req, '100', body)
|
||||
|
||||
@mock.patch('cinder.db.snapshot_metadata_update', return_value=dict())
|
||||
@ -538,7 +538,7 @@ class SnapshotMetaDataTest(test.TestCase):
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.update, req, self.req_id, 'key1',
|
||||
body)
|
||||
|
||||
|
@ -230,8 +230,8 @@ class SnapshotApiTest(test.TestCase):
|
||||
}
|
||||
body = {"snapshot": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/snapshots/not-the-uuid')
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update, req,
|
||||
'not-the-uuid', body)
|
||||
self.assertRaises(exception.SnapshotNotFound, self.controller.update,
|
||||
req, 'not-the-uuid', body)
|
||||
|
||||
@mock.patch.object(volume.api.API, "delete_snapshot",
|
||||
side_effect=stubs.stub_snapshot_update)
|
||||
@ -264,7 +264,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
self.stubs.Set(volume.api.API, "delete_snapshot", stub_snapshot_delete)
|
||||
snapshot_id = INVALID_UUID
|
||||
req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id)
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
self.assertRaises(exception.SnapshotNotFound, self.controller.delete,
|
||||
req, snapshot_id)
|
||||
|
||||
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
|
||||
@ -296,7 +296,7 @@ class SnapshotApiTest(test.TestCase):
|
||||
def test_snapshot_show_invalid_id(self):
|
||||
snapshot_id = INVALID_UUID
|
||||
req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.SnapshotNotFound,
|
||||
self.controller.show, req, snapshot_id)
|
||||
|
||||
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
|
||||
|
@ -254,7 +254,7 @@ class VolumeTypesApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/%s' %
|
||||
(fake.PROJECT_ID,
|
||||
fake.WILL_NOT_BE_FOUND_ID))
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
self.assertRaises(exception.VolumeTypeNotFound, self.controller.show,
|
||||
req, fake.WILL_NOT_BE_FOUND_ID)
|
||||
|
||||
def test_get_default(self):
|
||||
@ -274,7 +274,7 @@ class VolumeTypesApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/types/default' % fake.PROJECT_ID)
|
||||
req.method = 'GET'
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeTypeNotFound,
|
||||
self.controller.show, req, 'default')
|
||||
|
||||
def test_view_builder_show(self):
|
||||
|
@ -173,7 +173,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
self.stubs.Set(db, 'volume_metadata_get',
|
||||
return_volume_nonexistent)
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.index, req, self.url)
|
||||
|
||||
def test_index_no_data(self):
|
||||
@ -194,14 +194,14 @@ class volumeMetaDataTest(test.TestCase):
|
||||
self.stubs.Set(db, 'volume_metadata_get',
|
||||
return_volume_nonexistent)
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.show, req, self.req_id, 'key2')
|
||||
|
||||
def test_show_meta_not_found(self):
|
||||
self.stubs.Set(db, 'volume_metadata_get',
|
||||
return_empty_volume_metadata)
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeMetadataNotFound,
|
||||
self.controller.show, req, self.req_id, 'key6')
|
||||
|
||||
@mock.patch.object(db, 'volume_metadata_delete')
|
||||
@ -255,7 +255,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
with mock.patch.object(self.controller.volume_api,
|
||||
'get') as get_volume:
|
||||
get_volume.return_value = fake_volume
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.delete, req,
|
||||
self.req_id, 'key1')
|
||||
get_volume.assert_called_once_with(fake_context, self.req_id)
|
||||
@ -265,7 +265,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
return_empty_volume_metadata)
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeMetadataNotFound,
|
||||
self.controller.delete, req, self.req_id, 'key6')
|
||||
|
||||
@mock.patch.object(db, 'volume_metadata_update')
|
||||
@ -393,7 +393,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.create, req, self.req_id, body)
|
||||
|
||||
@mock.patch.object(db, 'volume_metadata_update')
|
||||
@ -538,7 +538,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
body = {'metadata': {'key10': 'value10'}}
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.update_all, req, '100', body)
|
||||
|
||||
@mock.patch.object(db, 'volume_metadata_update')
|
||||
@ -592,7 +592,7 @@ class volumeMetaDataTest(test.TestCase):
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.update, req, self.req_id, 'key1',
|
||||
body)
|
||||
|
||||
|
@ -96,8 +96,8 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes')
|
||||
# Raise 404 when type name isn't valid
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
|
||||
req, body)
|
||||
self.assertRaises(exception.VolumeTypeNotFoundByName,
|
||||
self.controller.create, req, body)
|
||||
|
||||
# Use correct volume type name
|
||||
vol.update(dict(volume_type=CONF.default_volume_type))
|
||||
@ -261,7 +261,7 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes')
|
||||
# Raise 404 when snapshot cannot be found.
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
|
||||
self.assertRaises(exception.SnapshotNotFound, self.controller.create,
|
||||
req, body)
|
||||
context = req.environ['cinder.context']
|
||||
get_snapshot.assert_called_once_with(self.controller.volume_api,
|
||||
@ -309,7 +309,7 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes')
|
||||
# Raise 404 when source volume cannot be found.
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
|
||||
self.assertRaises(exception.VolumeNotFound, self.controller.create,
|
||||
req, body)
|
||||
|
||||
context = req.environ['cinder.context']
|
||||
@ -327,7 +327,7 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes')
|
||||
# Raise 404 when source replica cannot be found.
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
|
||||
self.assertRaises(exception.VolumeNotFound, self.controller.create,
|
||||
req, body)
|
||||
|
||||
context = req.environ['cinder.context']
|
||||
@ -364,8 +364,8 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes')
|
||||
# Raise 404 when consistency group is not found.
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
|
||||
req, body)
|
||||
self.assertRaises(exception.ConsistencyGroupNotFound,
|
||||
self.controller.create, req, body)
|
||||
|
||||
context = req.environ['cinder.context']
|
||||
get_cg.assert_called_once_with(self.controller.consistencygroup_api,
|
||||
@ -700,7 +700,7 @@ class VolumeApiTest(test.TestCase):
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||
self.assertEqual(0, len(self.notifier.notifications))
|
||||
self.assertRaises(exc.HTTPBadRequest,
|
||||
self.assertRaises(exception.InvalidVolumeMetadata,
|
||||
self.controller.update, req, fake.VOLUME_ID, body)
|
||||
|
||||
@mock.patch(
|
||||
@ -779,7 +779,7 @@ class VolumeApiTest(test.TestCase):
|
||||
}
|
||||
body = {"volume": updates}
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.assertRaises(exception.VolumeNotFound,
|
||||
self.controller.update,
|
||||
req, fake.VOLUME_ID, body)
|
||||
|
||||
@ -1279,7 +1279,7 @@ class VolumeApiTest(test.TestCase):
|
||||
self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
self.assertRaises(exception.VolumeNotFound, self.controller.show,
|
||||
req, 1)
|
||||
# Finally test that nothing was cached
|
||||
self.assertIsNone(req.cached_resource_by_id(fake.VOLUME_ID))
|
||||
@ -1372,7 +1372,7 @@ class VolumeApiTest(test.TestCase):
|
||||
self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
self.assertRaises(exception.VolumeNotFound, self.controller.delete,
|
||||
req, 1)
|
||||
|
||||
def test_admin_list_volumes_limited_to_project(self):
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import webob
|
||||
|
||||
from cinder.api import extensions
|
||||
from cinder.api.v3 import messages
|
||||
@ -84,7 +83,7 @@ class MessageApiTest(test.TestCase):
|
||||
version=messages.MESSAGES_BASE_MICRO_VERSION)
|
||||
req.environ['cinder.context'] = self.ctxt
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
||||
self.assertRaises(exception.MessageNotFound, self.controller.show,
|
||||
req, fakes.FAKE_UUID)
|
||||
|
||||
def test_show_pre_microversion(self):
|
||||
@ -120,7 +119,7 @@ class MessageApiTest(test.TestCase):
|
||||
'/v3/messages/%s' % fakes.FAKE_UUID,
|
||||
version=messages.MESSAGES_BASE_MICRO_VERSION)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||
self.assertRaises(exception.MessageNotFound, self.controller.delete,
|
||||
req, fakes.FAKE_UUID)
|
||||
|
||||
def test_index(self):
|
||||
|
Loading…
Reference in New Issue
Block a user