From cb7edf9f0baea50c851a2e6f116d71c96aac6b47 Mon Sep 17 00:00:00 2001 From: Slavka Peleva Date: Thu, 7 Jan 2021 12:53:19 +0200 Subject: [PATCH 1/2] fix of detach volume while OS is in boot state --- .../hypervisor/kvm/storage/KVMStorageProcessor.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index cc47c5532834..58c3d7592274 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -69,6 +69,7 @@ import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; @@ -1166,6 +1167,14 @@ protected synchronized String attachOrDetachDevice(final Connect conn, final boo } else { s_logger.debug("Detaching device: " + xml); dm.detachDevice(xml); + LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser(); + parser.parseDomainXML(dm.getXMLDesc(0)); + List disks = parser.getDisks(); + for (DiskDef diskDef : disks) { + if (StringUtils.contains(xml, diskDef.getDiskPath())) { + throw new InternalErrorException("Could not detach volume. Probably the VM is in boot state at the moment"); + } + } } } catch (final LibvirtException e) { if (attach) { From ff0a91413d6cca7b73a8ff8aacb2b89bea7cadea Mon Sep 17 00:00:00 2001 From: Slavka Peleva Date: Fri, 22 Jan 2021 11:19:23 +0200 Subject: [PATCH 2/2] check that the VM could be accessed trough ssh --- test/integration/smoke/test_volumes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index aa4eaf13fa4d..796baaaf9a4d 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -383,11 +383,15 @@ def setUp(self): def tearDown(self): #Clean up, terminate the created volumes if self.attached: + self.virtual_machine.get_ssh_client(reconnect = True) + self.virtual_machine.detach_volume(self.apiClient, self.volume) if self.virtual_machine.hypervisor == "KVM": self.virtual_machine.stop(self.apiClient) self.virtual_machine.start(self.apiClient) + self.virtual_machine.get_ssh_client(reconnect = True) + cleanup_resources(self.apiClient, self.cleanup) return