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
This commit is contained in:
slavkap 2021-06-18 04:21:49 +03:00 committed by GitHub
parent 2ececbf994
commit 8e33cf7159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -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) {

View File

@ -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