From 2e8194ef137de8213eb587d78dafe3f53635dddd Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Wed, 27 Apr 2022 20:40:20 +0000 Subject: [PATCH 1/4] Add more logs to migrate VM process in KVM --- .../resource/LibvirtComputingResource.java | 15 ++++---- .../wrapper/LibvirtMigrateCommandWrapper.java | 34 +++++++++++++------ .../LibvirtMigrateCommandWrapperTest.java | 6 ++-- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index c513be6be229..a3c1c64e7d77 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -4500,12 +4500,15 @@ public List> cleanVMSnapshotMetadata(Domain dm) s_logger.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); List> vmsnapshots = new ArrayList>(); if (dm.snapshotNum() == 0) { + s_logger.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); return vmsnapshots; } String currentSnapshotName = null; try { DomainSnapshot snapshotCurrent = dm.snapshotCurrent(); String snapshotXML = snapshotCurrent.getXMLDesc(); + s_logger.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); + snapshotCurrent.free(); DocumentBuilder builder; try { @@ -4517,25 +4520,23 @@ public List> cleanVMSnapshotMetadata(Domain dm) Element rootElement = doc.getDocumentElement(); currentSnapshotName = getTagValue("name", rootElement); - } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); - } catch (SAXException e) { - s_logger.debug(e.toString()); - } catch (IOException e) { - s_logger.debug(e.toString()); + } catch (ParserConfigurationException | SAXException | IOException e) { + s_logger.error(String.format("Failed to parse snapshot configuration [%s] of VM [%s] due to: [%s].", snapshotXML, dm.getName(), e.getMessage()), e); } } catch (LibvirtException e) { - s_logger.debug("Fail to get the current vm snapshot for vm: " + dm.getName() + ", continue"); + s_logger.error(String.format("Failed to get the current snapshot of VM [%s] due to: [%s]. Continuing the migration process.", dm.getName(), e.getMessage()), e); } int flags = 2; // VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY = 2 String[] snapshotNames = dm.snapshotListNames(); Arrays.sort(snapshotNames); + s_logger.debug(String.format("Found [%s] snapshots in VM [%s] to clean.", snapshotNames.length, dm.getName())); for (String snapshotName: snapshotNames) { DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); Boolean isCurrent = (currentSnapshotName != null && currentSnapshotName.equals(snapshotName)) ? true: false; vmsnapshots.add(new Ternary(snapshotName, isCurrent, snapshot.getXMLDesc())); } for (String snapshotName: snapshotNames) { + s_logger.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); snapshot.delete(flags); // clean metadata of vm snapshot } 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 cdb9b384b030..abd0d9cd7260 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 @@ -77,6 +77,7 @@ import com.cloud.hypervisor.kvm.resource.VifDriver; import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.LogUtils; import com.cloud.utils.Ternary; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; @@ -102,6 +103,7 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour final Map vlanToPersistenceMap = command.getVlanToPersistenceMap(); final String destinationUri = createMigrationURI(command.getDestinationIp(), libvirtComputingResource); final List migrateDiskInfoList = command.getMigrateDiskInfoList(); + s_logger.debug(LogUtils.logGsonWithoutException("Trying to migrate VM [%s] with VLAN map [%s] and disk info [%s] to destination host [%s].", vmName, vlanToPersistenceMap, migrateDiskInfoList, destinationUri)); String result = null; @@ -122,6 +124,7 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour ifaces = libvirtComputingResource.getInterfaces(conn, vmName); disks = libvirtComputingResource.getDisks(conn, vmName); + s_logger.debug(LogUtils.logGsonWithoutException("Found domain with name [%s] with interfaces [%s] and disks [%s].", vmName, ifaces, disks)); VirtualMachineTO to = command.getVirtualMachine(); dm = conn.domainLookupByName(vmName); @@ -148,13 +151,16 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. final String target = command.getDestinationIp(); xmlDesc = dm.getXMLDesc(xmlFlag); - xmlDesc = replaceIpForVNCInDescFile(xmlDesc, target); + s_logger.debug(String.format("VM [%s] with XML configuration [%s] will be migrated to host [%s].", vmName, xmlDesc, target)); + + xmlDesc = replaceIpForVNCInDescFile(xmlDesc, target, vmName); String oldIsoVolumePath = getOldVolumePath(disks, vmName); String newIsoVolumePath = getNewVolumePathIfDatastoreHasChanged(libvirtComputingResource, conn, to); if (newIsoVolumePath != null && !newIsoVolumePath.equals(oldIsoVolumePath)) { s_logger.debug(String.format("Editing mount path of iso from %s to %s", oldIsoVolumePath, newIsoVolumePath)); xmlDesc = replaceDiskSourceFile(xmlDesc, newIsoVolumePath, vmName); + s_logger.debug(String.format("Replaced disk mount point [%s] with [%s] in VM [%s] XML configuration. New XML configuration is [%s].", oldIsoVolumePath, newIsoVolumePath, vmName, xmlDesc)); } // delete the metadata of vm snapshots before migration vmsnapshots = libvirtComputingResource.cleanVMSnapshotMetadata(dm); @@ -174,12 +180,16 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. final boolean migrateStorageManaged = command.isMigrateStorageManaged(); if (migrateStorage) { + s_logger.debug(LogUtils.logGsonWithoutException("Changing VM [%s] volumes using mapping of storages: [%s].", vmName, mapMigrateStorage)); xmlDesc = replaceStorage(xmlDesc, mapMigrateStorage, migrateStorageManaged); + s_logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc)); } Map dpdkPortsMapping = command.getDpdkInterfaceMapping(); if (MapUtils.isNotEmpty(dpdkPortsMapping)) { + s_logger.debug(LogUtils.logGsonWithoutException("Changing VM [%s] DPDK interfaces using mapping: [%s].", vmName, dpdkPortsMapping)); xmlDesc = replaceDpdkInterfaces(xmlDesc, dpdkPortsMapping); + s_logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); } dconn = libvirtUtilitiesHelper.retrieveQemuConnection(destinationUri); @@ -189,7 +199,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. } //run migration in thread so we can monitor it - s_logger.info("Live migration of instance " + vmName + " initiated to destination host: " + dconn.getURI()); + s_logger.info(String.format("Starting live migration of instance [%s] to destination host [%s] having the final XML configuration: [%s].", vmName, dconn.getURI(), xmlDesc)); final ExecutorService executor = Executors.newFixedThreadPool(1); boolean migrateNonSharedInc = command.isMigrateNonSharedInc() && !migrateStorageManaged; @@ -231,13 +241,13 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. if (state != null && state == DomainState.VIR_DOMAIN_RUNNING) { try { DomainJobInfo job = dm.getJobInfo(); - s_logger.info("Aborting " + vmName + " domain job: " + job); + s_logger.info(String.format("Aborting migration of VM [%s] with domain job [%s] due to time out after %d seconds.", vmName, job, migrateWait)); dm.abortJob(); - result = String.format("Migration of VM %s was cancelled by cloudstack due to time out after %d seconds", vmName, migrateWait); + result = String.format("Migration of VM [%s] was cancelled by CloudStack due to time out after %d seconds.", vmName, migrateWait); s_logger.debug(result); break; } catch (final LibvirtException e) { - s_logger.info("Failed to abort the vm migration job of vm " + vmName + " : " + e.getMessage()); + s_logger.error(String.format("Failed to abort the VM migration job of VM [%s] due to: [%s].", vmName, e.getMessage()), e); } } } @@ -262,16 +272,17 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. } } } - s_logger.info("Migration thread for " + vmName + " is done"); + s_logger.info(String.format("Migration thread of VM [%s] finished.", vmName)); destDomain = migrateThread.get(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT), TimeUnit.SECONDS); if (destDomain != null) { + s_logger.debug(String.format("Cleaning the disks of VM [%s] in the source pool after VM migration finished.", vmName)); deleteOrDisconnectDisksOnSourcePool(libvirtComputingResource, migrateDiskInfoList, disks); } } catch (final LibvirtException e) { - s_logger.debug("Can't migrate domain: " + e.getMessage()); + s_logger.error(String.format("Can't migrate domain [%s] due to: [%s].", vmName, e.getMessage()), e); result = e.getMessage(); if (result.startsWith("unable to connect to server") && result.endsWith("refused")) { result = String.format("Migration was refused connection to destination: %s. Please check libvirt configuration compatibility and firewall rules on the source and destination hosts.", destinationUri); @@ -284,7 +295,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. | SAXException | TransformerException | URISyntaxException e) { - s_logger.debug(String.format("%s : %s", e.getClass().getSimpleName(), e.getMessage())); + s_logger.error(String.format("Can't migrate domain [%s] due to: [%s].", vmName, e.getMessage()), e); if (result == null) { result = "Exception during migrate: " + e.getMessage(); } @@ -313,8 +324,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. } } - if (result != null) { - } else { + if (result == null) { libvirtComputingResource.destroyNetworkRulesForVM(conn, vmName); for (final InterfaceDef iface : ifaces) { String vlanId = libvirtComputingResource.getVlanIdFromBridgeName(iface.getBrName()); @@ -451,15 +461,17 @@ protected MigrateDiskInfo searchDiskDefOnMigrateDiskInfoList(List= 0) { final int end = xmlDesc.lastIndexOf(GRAPHICS_ELEM_END) + GRAPHICS_ELEM_END.length(); if (end > begin) { + String originalGraphElem = xmlDesc.substring(begin, end); String graphElem = xmlDesc.substring(begin, end); graphElem = graphElem.replaceAll("listen='[a-zA-Z0-9\\.]*'", "listen='" + target + "'"); graphElem = graphElem.replaceAll("address='[a-zA-Z0-9\\.]*'", "address='" + target + "'"); xmlDesc = xmlDesc.replaceAll(GRAPHICS_ELEM_START + CONTENTS_WILDCARD + GRAPHICS_ELEM_END, graphElem); + s_logger.debug(String.format("Replaced the VNC IP address [%s] with [%s] in VM [%s].", originalGraphElem, graphElem, vmName)); } } return xmlDesc; diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java index b5574bf7297f..c65347cc223b 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java @@ -571,7 +571,7 @@ public void setup() throws Exception { @Test public void testReplaceIpForVNCInDescFile() { final String targetIp = "192.168.22.21"; - final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFile(fullfile, targetIp); + final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFile(fullfile, targetIp, ""); assertTrue("transformation does not live up to expectation:\n" + result, targetfile.equals(result)); } @@ -594,7 +594,7 @@ public void testReplaceIpForVNCInDesc() { " " + ""; final String targetIp = "10.10.10.10"; - final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFile(xmlDesc, targetIp); + final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFile(xmlDesc, targetIp, ""); assertTrue("transformation does not live up to expectation:\n" + result, expectedXmlDesc.equals(result)); } @@ -617,7 +617,7 @@ public void testReplaceFqdnForVNCInDesc() { " " + ""; final String targetIp = "localhost.localdomain"; - final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFile(xmlDesc, targetIp); + final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFile(xmlDesc, targetIp, ""); assertTrue("transformation does not live up to expectation:\n" + result, expectedXmlDesc.equals(result)); } From 8b2124eab0939a76c3b6aa9ba25d2d7b0388682f Mon Sep 17 00:00:00 2001 From: SadiJr Date: Thu, 28 Apr 2022 07:48:39 -0300 Subject: [PATCH 2/4] Remove unused imports --- .../resource/wrapper/LibvirtMigrateCommandWrapper.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 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 abd0d9cd7260..323cbc629b28 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 @@ -77,7 +77,6 @@ import com.cloud.hypervisor.kvm.resource.VifDriver; import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; -import com.cloud.utils.LogUtils; import com.cloud.utils.Ternary; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; @@ -103,7 +102,7 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour final Map vlanToPersistenceMap = command.getVlanToPersistenceMap(); final String destinationUri = createMigrationURI(command.getDestinationIp(), libvirtComputingResource); final List migrateDiskInfoList = command.getMigrateDiskInfoList(); - s_logger.debug(LogUtils.logGsonWithoutException("Trying to migrate VM [%s] with VLAN map [%s] and disk info [%s] to destination host [%s].", vmName, vlanToPersistenceMap, migrateDiskInfoList, destinationUri)); + s_logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); String result = null; @@ -124,7 +123,7 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour ifaces = libvirtComputingResource.getInterfaces(conn, vmName); disks = libvirtComputingResource.getDisks(conn, vmName); - s_logger.debug(LogUtils.logGsonWithoutException("Found domain with name [%s] with interfaces [%s] and disks [%s].", vmName, ifaces, disks)); + s_logger.debug(String.format("Found domain with name [%s]. Starting VM migration to host [%s].", vmName, destinationUri)); VirtualMachineTO to = command.getVirtualMachine(); dm = conn.domainLookupByName(vmName); @@ -180,14 +179,14 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. final boolean migrateStorageManaged = command.isMigrateStorageManaged(); if (migrateStorage) { - s_logger.debug(LogUtils.logGsonWithoutException("Changing VM [%s] volumes using mapping of storages: [%s].", vmName, mapMigrateStorage)); + s_logger.debug(String.format("Changing VM [%s] volumes during migration to host: [%s].", vmName, target)); xmlDesc = replaceStorage(xmlDesc, mapMigrateStorage, migrateStorageManaged); s_logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc)); } Map dpdkPortsMapping = command.getDpdkInterfaceMapping(); if (MapUtils.isNotEmpty(dpdkPortsMapping)) { - s_logger.debug(LogUtils.logGsonWithoutException("Changing VM [%s] DPDK interfaces using mapping: [%s].", vmName, dpdkPortsMapping)); + s_logger.debug(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); xmlDesc = replaceDpdkInterfaces(xmlDesc, dpdkPortsMapping); s_logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); } From 7387c5039eab99b15755c0a4e525a7bb5b93cee0 Mon Sep 17 00:00:00 2001 From: SadiJr Date: Wed, 4 May 2022 13:19:29 -0300 Subject: [PATCH 3/4] Verify if debug is enable before write the log string --- .../resource/LibvirtComputingResource.java | 12 ++++-- .../wrapper/LibvirtMigrateCommandWrapper.java | 41 ++++++++++++++----- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index a3c1c64e7d77..148820cc03c1 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -4500,14 +4500,18 @@ public List> cleanVMSnapshotMetadata(Domain dm) s_logger.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); List> vmsnapshots = new ArrayList>(); if (dm.snapshotNum() == 0) { - s_logger.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); + } return vmsnapshots; } String currentSnapshotName = null; try { DomainSnapshot snapshotCurrent = dm.snapshotCurrent(); String snapshotXML = snapshotCurrent.getXMLDesc(); - s_logger.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); + } snapshotCurrent.free(); DocumentBuilder builder; @@ -4536,7 +4540,9 @@ public List> cleanVMSnapshotMetadata(Domain dm) vmsnapshots.add(new Ternary(snapshotName, isCurrent, snapshot.getXMLDesc())); } for (String snapshotName: snapshotNames) { - s_logger.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); + } DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); snapshot.delete(flags); // clean metadata of vm snapshot } 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 323cbc629b28..7049103202e9 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 @@ -102,7 +102,9 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour final Map vlanToPersistenceMap = command.getVlanToPersistenceMap(); final String destinationUri = createMigrationURI(command.getDestinationIp(), libvirtComputingResource); final List migrateDiskInfoList = command.getMigrateDiskInfoList(); - s_logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); + } String result = null; @@ -122,8 +124,9 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName); ifaces = libvirtComputingResource.getInterfaces(conn, vmName); disks = libvirtComputingResource.getDisks(conn, vmName); - - s_logger.debug(String.format("Found domain with name [%s]. Starting VM migration to host [%s].", vmName, destinationUri)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Found domain with name [%s]. Starting VM migration to host [%s].", vmName, destinationUri)); + } VirtualMachineTO to = command.getVirtualMachine(); dm = conn.domainLookupByName(vmName); @@ -150,7 +153,9 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. final String target = command.getDestinationIp(); xmlDesc = dm.getXMLDesc(xmlFlag); - s_logger.debug(String.format("VM [%s] with XML configuration [%s] will be migrated to host [%s].", vmName, xmlDesc, target)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("VM [%s] with XML configuration [%s] will be migrated to host [%s].", vmName, xmlDesc, target)); + } xmlDesc = replaceIpForVNCInDescFile(xmlDesc, target, vmName); @@ -159,7 +164,9 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. if (newIsoVolumePath != null && !newIsoVolumePath.equals(oldIsoVolumePath)) { s_logger.debug(String.format("Editing mount path of iso from %s to %s", oldIsoVolumePath, newIsoVolumePath)); xmlDesc = replaceDiskSourceFile(xmlDesc, newIsoVolumePath, vmName); - s_logger.debug(String.format("Replaced disk mount point [%s] with [%s] in VM [%s] XML configuration. New XML configuration is [%s].", oldIsoVolumePath, newIsoVolumePath, vmName, xmlDesc)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Replaced disk mount point [%s] with [%s] in VM [%s] XML configuration. New XML configuration is [%s].", oldIsoVolumePath, newIsoVolumePath, vmName, xmlDesc)); + } } // delete the metadata of vm snapshots before migration vmsnapshots = libvirtComputingResource.cleanVMSnapshotMetadata(dm); @@ -179,16 +186,24 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. final boolean migrateStorageManaged = command.isMigrateStorageManaged(); if (migrateStorage) { - s_logger.debug(String.format("Changing VM [%s] volumes during migration to host: [%s].", vmName, target)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Changing VM [%s] volumes during migration to host: [%s].", vmName, target)); + } xmlDesc = replaceStorage(xmlDesc, mapMigrateStorage, migrateStorageManaged); - s_logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc)); + } } Map dpdkPortsMapping = command.getDpdkInterfaceMapping(); if (MapUtils.isNotEmpty(dpdkPortsMapping)) { - s_logger.debug(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); + if (s_logger.isTraceEnabled()) { + s_logger.trace(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); + } xmlDesc = replaceDpdkInterfaces(xmlDesc, dpdkPortsMapping); - s_logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); + } } dconn = libvirtUtilitiesHelper.retrieveQemuConnection(destinationUri); @@ -276,7 +291,9 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. destDomain = migrateThread.get(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT), TimeUnit.SECONDS); if (destDomain != null) { - s_logger.debug(String.format("Cleaning the disks of VM [%s] in the source pool after VM migration finished.", vmName)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Cleaning the disks of VM [%s] in the source pool after VM migration finished.", vmName)); + } deleteOrDisconnectDisksOnSourcePool(libvirtComputingResource, migrateDiskInfoList, disks); } @@ -470,7 +487,9 @@ String replaceIpForVNCInDescFile(String xmlDesc, final String target, String vmN graphElem = graphElem.replaceAll("listen='[a-zA-Z0-9\\.]*'", "listen='" + target + "'"); graphElem = graphElem.replaceAll("address='[a-zA-Z0-9\\.]*'", "address='" + target + "'"); xmlDesc = xmlDesc.replaceAll(GRAPHICS_ELEM_START + CONTENTS_WILDCARD + GRAPHICS_ELEM_END, graphElem); - s_logger.debug(String.format("Replaced the VNC IP address [%s] with [%s] in VM [%s].", originalGraphElem, graphElem, vmName)); + if (s_logger.isDebugEnabled()) { + s_logger.debug(String.format("Replaced the VNC IP address [%s] with [%s] in VM [%s].", originalGraphElem, graphElem, vmName)); + } } } return xmlDesc; From b79d1787f8ee52382da677e7e2613eadd5314d58 Mon Sep 17 00:00:00 2001 From: SadiJr Date: Wed, 22 Jun 2022 12:01:31 -0300 Subject: [PATCH 4/4] Fix conflicts --- .../kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java | 4 ++-- .../resource/wrapper/LibvirtMigrateCommandWrapperTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 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 aafcec6865a7..812ca76ca46f 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 @@ -160,7 +160,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. // Limit the VNC password in case the length is greater than 8 characters // Since libvirt version 8 VNC passwords are limited to 8 characters String vncPassword = org.apache.commons.lang3.StringUtils.truncate(to.getVncPassword(), 8); - xmlDesc = replaceIpForVNCInDescFileAndNormalizePassword(xmlDesc, target, vncPassword); + xmlDesc = replaceIpForVNCInDescFileAndNormalizePassword(xmlDesc, target, vncPassword, vmName); String oldIsoVolumePath = getOldVolumePath(disks, vmName); String newIsoVolumePath = getNewVolumePathIfDatastoreHasChanged(libvirtComputingResource, conn, to); @@ -481,7 +481,7 @@ protected MigrateDiskInfo searchDiskDefOnMigrateDiskInfoList(List= 0) { final int end = xmlDesc.lastIndexOf(GRAPHICS_ELEM_END) + GRAPHICS_ELEM_END.length(); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java index 23f0ff911283..ae2e4cc41c25 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapperTest.java @@ -571,7 +571,7 @@ public void setup() throws Exception { @Test public void testReplaceIpForVNCInDescFile() { final String targetIp = "192.168.22.21"; - final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFileAndNormalizePassword(fullfile, targetIp, null); + final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFileAndNormalizePassword(fullfile, targetIp, null, ""); assertTrue("transformation does not live up to expectation:\n" + result, targetfile.equals(result)); } @@ -595,7 +595,7 @@ public void testReplaceIpAndPasswordForVNCInDesc() { ""; final String targetIp = "10.10.10.10"; final String password = "12345678"; - final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFileAndNormalizePassword(xmlDesc, targetIp, password); + final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFileAndNormalizePassword(xmlDesc, targetIp, password, ""); assertTrue("transformation does not live up to expectation:\n" + result, expectedXmlDesc.equals(result)); } @@ -619,7 +619,7 @@ public void testReplaceFqdnAndPasswordForVNCInDesc() { ""; final String targetIp = "localhost.localdomain"; final String password = "12345678"; - final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFileAndNormalizePassword(xmlDesc, targetIp, password); + final String result = libvirtMigrateCmdWrapper.replaceIpForVNCInDescFileAndNormalizePassword(xmlDesc, targetIp, password, ""); assertTrue("transformation does not live up to expectation:\n" + result, expectedXmlDesc.equals(result)); }