This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 8e33cf7 kvm: fix of detach volume while OS is in boot state (#4572)
8e33cf7 is described below
commit 8e33cf715948e4d17e323ac8e83fd22c6195ed7b
Author: slavkap <[email protected]>
AuthorDate: Fri Jun 18 04:21:49 2021 +0300
kvm: fix of detach volume while OS is in boot state (#4572)
* fix of detach volume while OS is in boot state
* check that the VM could be accessed trough ssh
---
.../com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java | 9 +++++++++
test/integration/smoke/test_volumes.py | 4 ++++
2 files changed, 13 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 34c610d..2ad3089 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
@@ -70,6 +70,7 @@ import org.apache.cloudstack.utils.qemu.QemuImgException;
import org.apache.cloudstack.utils.qemu.QemuImgFile;
import org.apache.commons.collections.MapUtils;
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;
@@ -1195,6 +1196,14 @@ public class KVMStorageProcessor implements
StorageProcessor {
} else {
s_logger.debug("Detaching device: " + xml);
dm.detachDevice(xml);
+ LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
+ parser.parseDomainXML(dm.getXMLDesc(0));
+ List<DiskDef> 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) {
diff --git a/test/integration/smoke/test_volumes.py
b/test/integration/smoke/test_volumes.py
index 107403e..fa7bea0 100644
--- a/test/integration/smoke/test_volumes.py
+++ b/test/integration/smoke/test_volumes.py
@@ -385,11 +385,15 @@ class TestVolumes(cloudstackTestCase):
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