From 3cb7ee45557ad68458bb96c3f4bcea1f796dcde9 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 8 Jan 2013 13:23:15 -0500 Subject: [PATCH] Update exceptions to pass correct kwargs. Updates a variety of Cinder exceptions so that they pass the correct kwargs for proper exception message formatting. Previously these exceptions would work but have incorrect error messages because of how CinderException handled exception formatting errors. Change-Id: Id1d15b112cad46a698227fa172d81a9ab586e66e --- cinder/db/sqlalchemy/api.py | 2 +- cinder/volume/driver.py | 6 +++--- cinder/volume/drivers/nexenta/volume.py | 4 ++-- cinder/volume/drivers/rbd.py | 12 ++++++------ cinder/volume/manager.py | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 266580575..121a23355 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -914,7 +914,7 @@ def volume_allocate_iscsi_target(context, volume_id, host): @require_admin_context def volume_attached(context, volume_id, instance_uuid, mountpoint): if not uuidutils.is_uuid_like(instance_uuid): - raise exception.InvalidUUID(instance_uuid) + raise exception.InvalidUUID(uuid=instance_uuid) session = get_session() with session.begin(): diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 6626ddf70..1ae2e95c0 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -547,9 +547,9 @@ class ISCSIDriver(VolumeDriver): location = self._do_iscsi_discovery(volume) if not location: - raise exception.InvalidVolume(_("Could not find iSCSI export " - " for volume %s") % - (volume['name'])) + msg = (_("Could not find iSCSI export for volume %s") % + (volume['name'])) + raise exception.InvalidVolume(reason=msg) LOG.debug(_("ISCSI Discovery: Found %s") % (location)) properties['target_discovered'] = True diff --git a/cinder/volume/drivers/nexenta/volume.py b/cinder/volume/drivers/nexenta/volume.py index cdff190cb..0b737e914 100644 --- a/cinder/volume/drivers/nexenta/volume.py +++ b/cinder/volume/drivers/nexenta/volume.py @@ -130,7 +130,7 @@ class NexentaDriver(driver.ISCSIDriver): # pylint: disable=R0921 self.nms.zvol.destroy(self._get_zvol_name(volume['name']), '') except nexenta.NexentaException as exc: if "zvol has children" in exc.args[1]: - raise exception.VolumeIsBusy + raise exception.VolumeIsBusy(volume_name=volume['name']) else: raise @@ -166,7 +166,7 @@ class NexentaDriver(driver.ISCSIDriver): # pylint: disable=R0921 '') except nexenta.NexentaException as exc: if "snapshot has dependent clones" in exc.args[1]: - raise exception.SnapshotIsBusy + raise exception.SnapshotIsBusy(snapshot_name=snapshot['name']) else: raise diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index cc2fb53ba..a4241aa55 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -176,15 +176,15 @@ class RBDDriver(driver.VolumeDriver): def _parse_location(self, location): prefix = 'rbd://' if not location.startswith(prefix): - reason = _('Image %s is not stored in rbd') % location - raise exception.ImageUnacceptable(reason) + reason = _('Not stored in rbd') + raise exception.ImageUnacceptable(image_id=location, reason=reason) pieces = map(urllib.unquote, location[len(prefix):].split('/')) if any(map(lambda p: p == '', pieces)): - reason = _('Image %s has blank components') % location - raise exception.ImageUnacceptable(reason) + reason = _('Blank components') + raise exception.ImageUnacceptable(image_id=location, reason=reason) if len(pieces) != 4: - reason = _('Image %s is not an rbd snapshot') % location - raise exception.ImageUnacceptable(reason) + reason = _('Not an rbd snapshot') + raise exception.ImageUnacceptable(image_id=location, reason=reason) return pieces def _get_fsid(self): diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 895007638..7400f62a7 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -362,7 +362,7 @@ class VolumeManager(manager.SchedulerDependentManager): # TODO(vish): refactor this into a more general "reserve" # TODO(sleepsonthefloor): Is this 'elevated' appropriate? if not uuidutils.is_uuid_like(instance_uuid): - raise exception.InvalidUUID(instance_uuid) + raise exception.InvalidUUID(uuid=instance_uuid) try: self.driver.attach_volume(context, -- 2.45.2