From cc02f6a5604892fb776158dab06b06f24a25cbfb Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 27 Sep 2012 20:38:59 +0000 Subject: libvirt: continue detach if instance not found Currently the libvirt code will always logout of the iscsi target during detach error, but the exception will cause the volume to remain in an attached state. This needs to be more consistent, so This patch checks specifically for not found and logs a warning and explicitly detaches. Any other exception will leave iscsi logged in and leave the volume in the attached state. Fixes bug 1057756 Change-Id: I23bb7f27e8a9b20fdbf62b0629ca8cc448f427c5 --- nova/virt/libvirt/driver.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 75a257a92..22c64a218 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -689,9 +689,6 @@ class LibvirtDriver(driver.ComputeDriver): def detach_volume(self, connection_info, instance_name, mountpoint): mount_device = mountpoint.rpartition("/")[2] try: - # NOTE(vish): This is called to cleanup volumes after live - # migration, so we should still logout even if - # the instance doesn't exist here anymore. virt_dom = self._lookup_by_name(instance_name) xml = self._get_disk_xml(virt_dom.XMLDesc(0), mount_device) if not xml: @@ -707,10 +704,20 @@ class LibvirtDriver(driver.ComputeDriver): else: flags = (libvirt.VIR_DOMAIN_AFFECT_CURRENT) virt_dom.detachDeviceFlags(xml, flags) - finally: - self.volume_driver_method('disconnect_volume', - connection_info, - mount_device) + except libvirt.libvirtError as ex: + # NOTE(vish): This is called to cleanup volumes after live + # migration, so we should still disconnect even if + # the instance doesn't exist here anymore. + error_code = ex.get_error_code() + if error_code == libvirt.VIR_ERR_NO_DOMAIN: + # NOTE(vish): + LOG.warn(_("During detach_volume, instance disappeared.")) + else: + raise + + self.volume_driver_method('disconnect_volume', + connection_info, + mount_device) @exception.wrap_exception() def _attach_lxc_volume(self, xml, virt_dom, instance_name): -- cgit