Skip to content

Commit

Permalink
Call detach_volume when attach fails
Browse files Browse the repository at this point in the history
* Fixes bug 914974
* Raise exception.DeviceBusy when volume cannot attach

Change-Id: Ie18377ba6acd6226612c70fa209185cc579c2d85
  • Loading branch information
bcwaldon committed Feb 28, 2012
1 parent f01b9b8 commit 44067ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nova/exception.py
Expand Up @@ -362,6 +362,10 @@ class InvalidDevicePath(Invalid):
message = _("The supplied device path (%(path)s) is invalid.")


class DeviceIsBusy(Invalid):
message = _("The supplied device (%(device)s) is busy.")


class InvalidCPUInfo(Invalid):
message = _("Unacceptable CPU info") + ": %(reason)s"

Expand Down
13 changes: 12 additions & 1 deletion nova/virt/libvirt/connection.py
Expand Up @@ -472,7 +472,18 @@ def attach_volume(self, connection_info, instance_name, mountpoint):
if FLAGS.libvirt_type == 'lxc':
self._attach_lxc_volume(xml, virt_dom, instance_name)
else:
virt_dom.attachDevice(xml)
try:
virt_dom.attachDevice(xml)
except Exception, ex:
self.volume_driver_method('disconnect_volume',
connection_info,
mount_device)

if isinstance(ex, libvirt.libvirtError):
errcode = ex.get_error_code()
if errcode == libvirt.VIR_ERR_OPERATION_FAILED:
raise exception.DeviceIsBusy(device=mount_device)
raise

@staticmethod
def _get_disk_xml(xml, device):
Expand Down

0 comments on commit 44067ba

Please sign in to comment.