Skip to content

Commit 363a2cf

Browse files
Backport: kvm: truncate vnc password to 8 chars (apache#6244) (apache#6402)
* kvm: truncate vnc password to 8 chars (apache#6244) This PR truncates the vnc password of kvm vms to 8 chars to support latest versions of libvirt. * Use lang3 string utils Co-authored-by: Wei Zhou <[email protected]>
1 parent b62b5c9 commit 363a2cf

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Map;
2424

2525
import org.apache.commons.lang.StringEscapeUtils;
26-
import org.apache.commons.lang.StringUtils;
26+
import org.apache.commons.lang3.StringUtils;
2727
import org.apache.log4j.Logger;
2828

2929
public class LibvirtVMDef {
@@ -1764,7 +1764,7 @@ public String toString() {
17641764
graphicBuilder.append(" listen=''");
17651765
}
17661766
if (_passwd != null) {
1767-
graphicBuilder.append(" passwd='" + _passwd + "'");
1767+
graphicBuilder.append(" passwd='" + StringUtils.truncate(_passwd, 8) + "'");
17681768
} else if (_keyMap != null) {
17691769
graphicBuilder.append(" _keymap='" + _keyMap + "'");
17701770
}

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.apache.cloudstack.utils.linux.MemStat;
6161
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
6262
import org.apache.commons.lang.SystemUtils;
63+
import org.apache.commons.lang3.StringUtils;
6364
import org.joda.time.Duration;
6465
import org.junit.Assert;
6566
import org.junit.Before;
@@ -773,7 +774,7 @@ private void verifyGraphicsDevices(VirtualMachineTO to, Document domainDoc, Stri
773774
assertXpath(domainDoc, prefix + "/graphics/@type", "vnc");
774775
assertXpath(domainDoc, prefix + "/graphics/@listen", to.getVncAddr());
775776
assertXpath(domainDoc, prefix + "/graphics/@autoport", "yes");
776-
assertXpath(domainDoc, prefix + "/graphics/@passwd", to.getVncPassword());
777+
assertXpath(domainDoc, prefix + "/graphics/@passwd", StringUtils.truncate(to.getVncPassword(), 8));
777778
}
778779

779780
private void verifySerialDevices(Document domainDoc, String prefix) {

0 commit comments

Comments
 (0)