Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DiskDef> disks = parser.getDisks();
for (DiskDef diskDef : disks) {
if (StringUtils.contains(xml, diskDef.getDiskPath())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavkap can you check if this is applicable for attach disk as well (when VM is either booting or shutting down)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, @sureshanaparti, I'll do the test and will let you know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sureshanaparti, sorry for the late response, but I didn't have time to check it yesterday! The change is applied only to detach a volume when the VM is in Running or Stopped state

throw new InternalErrorException("Could not detach volume. Probably the VM is in boot state at the moment");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM, for detach disk.

}
} catch (final LibvirtException e) {
if (attach) {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/smoke/test_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down