From 709845f4a333ad2ace0183706433a0653ba159c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Beims=20Br=C3=A4scher?= Date: Tue, 12 Feb 2019 22:07:03 -0200 Subject: [PATCH] Keep iotune section in the VM's XML after live migration (#3171) * Keep iotune section in the VM's XML after live migration When live migrating a KVM VM among local storages, the VM loses the section on its XML, therefore, having no IO limitations. This commit removes the piece of code that deletes the section in the XML. * Add test for replaceStorage in LibvirtMigrateCommandWrapper Signed-off-by: Wido den Hollander * Fix Javadoc for method replaceIpForVNCInDescFile --- .../wrapper/LibvirtMigrateCommandWrapper.java | 20 ++++---- .../LibvirtMigrateCommandWrapperTest.java | 48 +++++++++++++++++++ 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java index 2e3bd20f75d..0c1370e2551 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java @@ -346,13 +346,17 @@ public final class LibvirtMigrateCommandWrapper extends CommandWrapper migrateStorage) + /** + * Pass in a list of the disks to update in the XML (xmlDesc). Each disk passed in needs to have a serial number. If any disk's serial number in the + * list does not match a disk in the XML, an exception should be thrown. + * In addition to the serial number, each disk in the list needs the following info: + *
    + *
  • The value of the 'type' of the disk (ex. file, block) + *
  • The value of the 'type' of the driver of the disk (ex. qcow2, raw) + *
  • The source of the disk needs an attribute that is either 'file' or 'dev' as well as its corresponding value. + *
+ */ + protected String replaceStorage(String xmlDesc, Map migrateStorage) throws IOException, ParserConfigurationException, SAXException, TransformerException { InputStream in = IOUtils.toInputStream(xmlDesc); @@ -411,8 +415,6 @@ public final class LibvirtMigrateCommandWrapper extends CommandWrapper\n" + " \n" + " \n" + +" \n" + +" 500\n" + +" 5000\n" + +" 60\n" + +" \n" + " 4650a2f7fce548e2beaa\n" + " \n" + "
\n" + @@ -208,6 +223,11 @@ public class LibvirtMigrateCommandWrapperTest { " \n" + " \n" + " \n" + +" \n" + +" 500\n" + +" 5000\n" + +" 60\n" + +" \n" + " 4650a2f7fce548e2beaa\n" + " \n" + "
\n" + @@ -435,4 +455,32 @@ public class LibvirtMigrateCommandWrapperTest { inOrder.verify(virtResource, Mockito.times(timesCleanup)).cleanupDisk(disk); } + static void assertXpath(final Document doc, final String xPathExpr, + final String expected) { + try { + Assert.assertEquals(expected, XPathFactory.newInstance().newXPath() + .evaluate(xPathExpr, doc)); + } catch (final XPathExpressionException e) { + Assert.fail("Could not evaluate xpath" + xPathExpr + ":" + + e.getMessage()); + } + } + + @Test + public void testReplaceStorage() throws Exception { + Map mapMigrateStorage = new HashMap(); + + MigrateDiskInfo diskInfo = new MigrateDiskInfo("123456", DiskType.BLOCK, DriverType.RAW, Source.FILE, "sourctest"); + mapMigrateStorage.put("/mnt/812ea6a3-7ad0-30f4-9cab-01e3f2985b98/4650a2f7-fce5-48e2-beaa-bcdf063194e6", diskInfo); + final String result = libvirtMigrateCmdWrapper.replaceStorage(fullfile, mapMigrateStorage); + + InputStream in = IOUtils.toInputStream(result); + DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + Document doc = docBuilder.parse(in); + assertXpath(doc, "/domain/devices/disk/iotune/write_iops_sec", "500"); + assertXpath(doc, "/domain/devices/disk/@type", "block"); + assertXpath(doc, "/domain/devices/disk/driver/@type", "raw"); + } + }