try:
self._update(context, id, update)
- except exception.NotFound as e:
+ except exception.VolumeNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
notifier.info(context, self.collection + '.reset_status.end',
self.authorize(context, 'force_delete')
try:
resource = self._get(context, id)
- except exception.NotFound:
- raise exc.HTTPNotFound()
+ except exception.VolumeNotFound as e:
+ raise exc.HTTPNotFound(explanation=e.msg)
self._delete(context, resource, force=True)
return webob.Response(status_int=202)
self.authorize(context, 'force_detach')
try:
volume = self._get(context, id)
- except exception.NotFound:
- raise exc.HTTPNotFound()
+ except exception.VolumeNotFound as e:
+ raise exc.HTTPNotFound(explanation=e.msg)
self.volume_api.terminate_connection(context, volume,
{}, force=True)
self.authorize(context, 'migrate_volume')
try:
volume = self._get(context, id)
- except exception.NotFound:
- raise exc.HTTPNotFound()
+ except exception.VolumeNotFound as e:
+ raise exc.HTTPNotFound(explanation=e.msg)
params = body['os-migrate_volume']
try:
host = params['host']
self.authorize(context, 'migrate_volume_completion')
try:
volume = self._get(context, id)
- except exception.NotFound:
- raise exc.HTTPNotFound()
+ except exception.VolumeNotFound as e:
+ raise exc.HTTPNotFound(explanation=e.msg)
params = body['os-migrate_volume_completion']
try:
new_volume_id = params['new_volume']
explanation=_("Must specify 'new_volume'"))
try:
new_volume = self._get(context, new_volume_id)
- except exception.NotFound:
- raise exc.HTTPNotFound()
+ except exception.VolumeNotFound as e:
+ raise exc.HTTPNotFound(explanation=e.msg)
error = params.get('error', False)
ret = self.volume_api.migrate_volume_completion(context, volume,
new_volume, error)
try:
self.backup_api.reset_status(context=context, backup_id=id,
status=update['status'])
- except exception.NotFound as e:
+ except exception.VolumeNotFound as e:
raise exc.HTTPNotFound(explanation=e.msg)
return webob.Response(status_int=202)
context,
cgsnapshot_id=id)
self.cgsnapshot_api.delete_cgsnapshot(context, cgsnapshot)
- except exception.CgSnapshotNotFound:
- msg = _("Cgsnapshot could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.CgSnapshotNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.InvalidCgSnapshot:
msg = _("Invalid cgsnapshot")
raise exc.HTTPBadRequest(explanation=msg)
try:
group = self.cgsnapshot_api.get(context, group_id)
- except exception.NotFound:
- msg = _("Consistency group could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.ConsistencyGroupNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
name = cgsnapshot.get('name', None)
description = cgsnapshot.get('description', None)
try:
group = self.consistencygroup_api.get(context, id)
self.consistencygroup_api.delete(context, group, force)
- except exception.ConsistencyGroupNotFound:
- msg = _("Consistency group %s could not be found.") % id
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.ConsistencyGroupNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.InvalidConsistencyGroup as error:
raise exc.HTTPBadRequest(explanation=error.msg)
self.consistencygroup_api.update(
context, group, name, description,
add_volumes, remove_volumes)
- except exception.ConsistencyGroupNotFound:
- msg = _("Consistency group %s could not be found.") % id
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.ConsistencyGroupNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.InvalidConsistencyGroup as error:
raise exc.HTTPBadRequest(explanation=error.msg)
def _check_specs(context, specs_id):
try:
qos_specs.get_qos_specs(context, specs_id)
- except exception.NotFound as ex:
+ except exception.QoSSpecsNotFound as ex:
raise webob.exc.HTTPNotFound(explanation=six.text_type(ex))
def _check_type(self, context, type_id):
try:
volume_types.get_volume_type(context, type_id)
- except exception.NotFound as ex:
+ except exception.VolumeTypeNotFound as ex:
raise webob.exc.HTTPNotFound(explanation=ex.msg)
@wsgi.serializers(xml=VolumeTypeExtraSpecsTemplate)
if id in specs['extra_specs']:
return {id: specs['extra_specs'][id]}
else:
- raise webob.exc.HTTPNotFound()
+ 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)
def delete(self, req, type_id, id):
"""Deletes an existing extra spec."""
self._notify_volume_type_error(
context, 'volume_type.create', err, volume_type=vol_type)
raise webob.exc.HTTPConflict(explanation=six.text_type(err))
- except exception.NotFound as err:
+ except exception.VolumeTypeNotFoundByName as err:
self._notify_volume_type_error(
context, 'volume_type.create', err, name=name)
- raise webob.exc.HTTPNotFound()
+ raise webob.exc.HTTPNotFound(explanation=err.msg)
return self._view_builder.show(req, vol_type)
context, 'volume_type.delete', err, volume_type=vol_type)
msg = _('Target volume type is still in use.')
raise webob.exc.HTTPBadRequest(explanation=msg)
- except exception.NotFound as err:
+ except exception.VolumeTypeNotFound as err:
self._notify_volume_type_error(
context, 'volume_type.delete', err, id=id)
- raise webob.exc.HTTPNotFound()
+ raise webob.exc.HTTPNotFound(explanation=err.msg)
return webob.Response(status_int=202)
else:
kwargs['volume_type'] = volume_types.get_volume_type(
context, req_volume_type)
- except exception.VolumeTypeNotFound:
- msg = _("Volume type not found.")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeTypeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
else:
kwargs['volume_type'] = {}
from cinder.api.openstack import wsgi
from cinder.api import xmlutil
from cinder import exception
-from cinder.i18n import _, _LI
+from cinder.i18n import _LI
from cinder import replication as replicationAPI
from cinder import volume
id,
context=context)
self.replication_api.promote(context, vol)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.ReplicationError as error:
raise exc.HTTPBadRequest(explanation=six.text_type(error))
return webob.Response(status_int=202)
id,
context=context)
self.replication_api.reenable(context, vol)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.ReplicationError as error:
raise exc.HTTPBadRequest(explanation=six.text_type(error))
return webob.Response(status_int=202)
try:
vol_type = volume_types.get_volume_type(
context, type_id, expected_fields=['projects'])
- except exception.VolumeTypeNotFound:
- explanation = _("Volume type not found.")
- raise webob.exc.HTTPNotFound(explanation=explanation)
+ except exception.VolumeTypeNotFound as error:
+ raise webob.exc.HTTPNotFound(explanation=error.msg)
if vol_type['is_public']:
expl = _("Access list not available for public volume types.")
def _check_type(self, context, type_id):
try:
volume_types.get_volume_type(context, type_id)
- except exception.NotFound as ex:
+ except exception.VolumeTypeNotFound as ex:
raise webob.exc.HTTPNotFound(explanation=ex.msg)
def _check_encryption_input(self, encryption, create=True):
try:
vol = self.volume_api.get(context, id)
self.volume_api.delete(context, vol, unmanage_only=True)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.VolumeAttached:
msg = _("Volume cannot be deleted while in attached state")
raise exc.HTTPBadRequest(explanation=msg)
try:
snapshot = self.volume_api.get_snapshot(context, id)
req.cache_db_snapshot(snapshot)
- except exception.NotFound:
- msg = _("Snapshot could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.SnapshotNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
return {'snapshot': _translate_snapshot_detail_view(context, snapshot)}
try:
snapshot = self.volume_api.get_snapshot(context, id)
self.volume_api.delete_snapshot(context, snapshot)
- except exception.NotFound:
- msg = _("Snapshot could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.SnapshotNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
return webob.Response(status_int=202)
try:
volume = self.volume_api.get(context, volume_id)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
force = snapshot.get('force', False)
msg = _LI("Create snapshot from volume %s")
LOG.info(msg, volume_id, context=context)
try:
snapshot = self.volume_api.get_snapshot(context, id)
self.volume_api.update_snapshot(context, snapshot, update_dict)
- except exception.NotFound:
- msg = _("Snapshot could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.SnapshotNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
snapshot.update(update_dict)
req.cache_db_snapshot(snapshot)
try:
vol_type = volume_types.get_volume_type(context, id)
req.cache_resource(vol_type, name='types')
- except exception.NotFound:
- msg = _("Volume type not found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeTypeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
return self._view_builder.show(req, vol_type)
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 webob.exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise webob.exc.HTTPNotFound(explanation=error.msg)
return meta
@wsgi.serializers(xml=common.MetadataTemplate)
volume,
metadata,
delete)
- except exception.VolumeNotFound:
- msg = _('volume does not exist')
- raise webob.exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise webob.exc.HTTPNotFound(explanation=error.msg)
except (ValueError, AttributeError):
msg = _("Malformed request body")
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 webob.exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise webob.exc.HTTPNotFound(explanation=error.msg)
return webob.Response(status_int=200)
try:
vol = self.volume_api.get(context, id, viewable_admin_meta=True)
req.cache_db_volume(vol)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
utils.add_visible_admin_metadata(vol)
try:
volume = self.volume_api.get(context, id)
self.volume_api.delete(context, volume)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
except exception.VolumeAttached:
msg = _("Volume cannot be deleted while in attached state")
raise exc.HTTPBadRequest(explanation=msg)
else:
kwargs['volume_type'] = volume_types.get_volume_type(
context, req_volume_type)
- except exception.VolumeTypeNotFound:
- msg = _("Volume type not found.")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeTypeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
kwargs['metadata'] = volume.get('metadata', 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)
+ except exception.SnapshotNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
else:
kwargs['snapshot'] = None
kwargs['source_volume'] = \
self.volume_api.get_volume(context,
source_volid)
- except exception.NotFound:
- explanation = _('source volume id:%s not found') % source_volid
- raise exc.HTTPNotFound(explanation=explanation)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
else:
kwargs['source_volume'] = None
' replicated') % source_volid
raise exc.HTTPNotFound(explanation=explanation)
kwargs['source_replica'] = src_vol
- except exception.NotFound:
- explanation = (_('replica source volume id:%s not found') %
- source_replica)
- raise exc.HTTPNotFound(explanation=explanation)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
else:
kwargs['source_replica'] = None
kwargs['consistencygroup'] = \
self.consistencygroup_api.get(context,
consistencygroup_id)
- except exception.NotFound:
- explanation = _('Consistency group id:%s not found') % \
- consistencygroup_id
- raise exc.HTTPNotFound(explanation=explanation)
+ except exception.ConsistencyGroupNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
else:
kwargs['consistencygroup'] = None
volume_utils.notify_about_volume_usage(context, volume,
'update.start')
self.volume_api.update(context, volume, update_dict)
- except exception.NotFound:
- msg = _("Volume could not be found")
- raise exc.HTTPNotFound(explanation=msg)
+ except exception.VolumeNotFound as error:
+ raise exc.HTTPNotFound(explanation=error.msg)
volume.update(update_dict)
self.assertEqual(res.status_int, 404)
self.assertEqual(res_dict['itemNotFound']['code'], 404)
self.assertEqual(res_dict['itemNotFound']['message'],
- 'Cgsnapshot could not be found')
+ 'CgSnapshot 9999 could not be found.')
def test_delete_cgsnapshot_with_Invalidcgsnapshot(self):
consistencygroup_id = utils.create_consistencygroup(self.context)['id']
self.assertEqual(404, res.status_int)
self.assertEqual(404, res_dict['itemNotFound']['code'])
- self.assertEqual('Consistency group 9999 could not be found.',
+ self.assertEqual('ConsistencyGroup 9999 could not be found.',
res_dict['itemNotFound']['message'])
def test_delete_consistencygroup_with_Invalidconsistencygroup(self):
vol = vols.get(volume_id, None)
if not vol:
- raise exception.NotFound
+ raise exception.VolumeNotFound(volume_id)
return vol
def stub_volume_get_notfound(self, context,
volume_id, viewable_admin_meta=False):
- raise exc.NotFound
+ raise exc.VolumeNotFound(volume_id)
def stub_volume_get_db(context, volume_id):
def stub_snapshot_delete(self, context, snapshot):
if snapshot['id'] != UUID:
- raise exception.NotFound
+ raise exception.SnapshotNotFound(snapshot['id'])
def stub_snapshot_get(self, context, snapshot_id):
if snapshot_id != UUID:
- raise exception.NotFound
+ raise exception.SnapshotNotFound(snapshot_id)
param = _get_default_snapshot_param()
return param