Catch and report errors from copy image to volume.

The copy image-to-volume errors weren't being handled
properly and the result was the lvcreate being retried
even though the lvcreate itself succeeded.

The result of this was misleading errors stating that
the volume couldn't be created because it already existed
(which it did, becuase the create itself was succesful).

Fixes bug: 1183283

Change-Id: I23f05fe64475c3efe285e05a258c4625b801375c
This commit is contained in:
John Griffith 2013-05-27 20:04:56 +00:00 committed by Mike Perez
parent 77a77456af
commit b2371aeff9
3 changed files with 28 additions and 9 deletions
cinder
exception.py
volume
drivers/xenapi
manager.py

@ -562,7 +562,7 @@ class GlanceMetadataExists(Invalid):
class ImageCopyFailure(Invalid):
message = _("Failed to copy image to volume")
message = _("Failed to copy image to volume: %(reason)s")
class BackupNotFound(NotFound):

@ -194,7 +194,8 @@ class XenAPINFSDriver(driver.VolumeDriver):
FLAGS.xenapi_sr_base_path)
if overwrite_result is False:
raise exception.ImageCopyFailure()
raise exception.ImageCopyFailure(reason='Overwriting volume '
'failed.')
self.nfs_ops.resize_volume(
FLAGS.xenapi_nfs_server,

@ -186,7 +186,6 @@ class VolumeManager(manager.SchedulerDependentManager):
volume_ref = self.db.volume_update(context,
volume_ref['id'],
updates)
self._copy_image_to_volume(context,
volume_ref,
image_service,
@ -252,6 +251,13 @@ class VolumeManager(manager.SchedulerDependentManager):
image_service,
image_id,
image_location)
except exception.ImageCopyFailure as ex:
LOG.error(_('Setting volume: %s status to error '
'after failed image copy.'), volume_ref['id'])
self.db.volume_update(context,
volume_ref['id'],
{'status': 'error'})
return
except Exception:
# restore source volume status before reschedule
if sourcevol_ref is not None:
@ -278,7 +284,6 @@ class VolumeManager(manager.SchedulerDependentManager):
model_update = self.driver.create_export(context, volume_ref)
if model_update:
self.db.volume_update(context, volume_ref['id'], model_update)
except Exception:
with excutils.save_and_reraise_exception():
self.db.volume_update(context,
@ -602,11 +607,24 @@ class VolumeManager(manager.SchedulerDependentManager):
def _copy_image_to_volume(self, context, volume, image_service, image_id):
"""Downloads Glance image to the specified volume. """
volume_id = volume['id']
self.driver.copy_image_to_volume(context, volume,
image_service,
image_id)
LOG.debug(_("Downloaded image %(image_id)s to %(volume_id)s "
"successfully") % locals())
try:
self.driver.copy_image_to_volume(context, volume,
image_service,
image_id)
except exception.ProcessExecutionError as ex:
LOG.error(_("Failed to copy image to volume: %(volume_id)s, "
"error: %(error)s") % {'volume_id': volume_id,
'error': ex.stderr})
raise exception.ImageCopyFailure(reason=ex.stderr)
except exception.ImageUnacceptable as ex:
LOG.error(_("Failed to copy image to volume: %(volume_id)s, "
"error: %(error)s") % {'volume_id': volume_id,
'error': ex})
raise exception.ImageCopyFailure(reason=ex)
LOG.info(_("Downloaded image %(image_id)s to %(volume_id)s "
"successfully.") % {'image_id': image_id,
'volume_id': volume_id})
def copy_volume_to_image(self, context, volume_id, image_meta):
"""Uploads the specified volume to Glance.