Skip to content

Commit 8e33cf7

Browse files
authored
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
1 parent 2ececbf commit 8e33cf7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.apache.cloudstack.utils.qemu.QemuImgFile;
7171
import org.apache.commons.collections.MapUtils;
7272
import org.apache.commons.io.FileUtils;
73+
import org.apache.commons.lang.StringUtils;
7374
import org.apache.log4j.Logger;
7475
import org.libvirt.Connect;
7576
import org.libvirt.Domain;
@@ -1195,6 +1196,14 @@ protected synchronized String attachOrDetachDevice(final Connect conn, final boo
11951196
} else {
11961197
s_logger.debug("Detaching device: " + xml);
11971198
dm.detachDevice(xml);
1199+
LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
1200+
parser.parseDomainXML(dm.getXMLDesc(0));
1201+
List<DiskDef> disks = parser.getDisks();
1202+
for (DiskDef diskDef : disks) {
1203+
if (StringUtils.contains(xml, diskDef.getDiskPath())) {
1204+
throw new InternalErrorException("Could not detach volume. Probably the VM is in boot state at the moment");
1205+
}
1206+
}
11981207
}
11991208
} catch (final LibvirtException e) {
12001209
if (attach) {

test/integration/smoke/test_volumes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,15 @@ def setUp(self):
385385
def tearDown(self):
386386
#Clean up, terminate the created volumes
387387
if self.attached:
388+
self.virtual_machine.get_ssh_client(reconnect = True)
389+
388390
self.virtual_machine.detach_volume(self.apiClient, self.volume)
389391

390392
if self.virtual_machine.hypervisor == "KVM":
391393
self.virtual_machine.stop(self.apiClient)
392394
self.virtual_machine.start(self.apiClient)
395+
self.virtual_machine.get_ssh_client(reconnect = True)
396+
393397

394398
cleanup_resources(self.apiClient, self.cleanup)
395399
return

0 commit comments

Comments
 (0)