Backport: kvm: truncate vnc password to 8 chars (#6244) (#6402)

* kvm: truncate vnc password to 8 chars (#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 <weizhou@apache.org>
This commit is contained in:
Nicolas Vazquez 2022-05-20 11:36:43 -03:00 committed by GitHub
parent b62b5c96e8
commit 363a2cff82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
public class LibvirtVMDef {
@ -1764,7 +1764,7 @@ public class LibvirtVMDef {
graphicBuilder.append(" listen=''");
}
if (_passwd != null) {
graphicBuilder.append(" passwd='" + _passwd + "'");
graphicBuilder.append(" passwd='" + StringUtils.truncate(_passwd, 8) + "'");
} else if (_keyMap != null) {
graphicBuilder.append(" _keymap='" + _keyMap + "'");
}

View File

@ -60,6 +60,7 @@ import org.apache.cloudstack.utils.linux.CPUStat;
import org.apache.cloudstack.utils.linux.MemStat;
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.Duration;
import org.junit.Assert;
import org.junit.Before;
@ -773,7 +774,7 @@ public class LibvirtComputingResourceTest {
assertXpath(domainDoc, prefix + "/graphics/@type", "vnc");
assertXpath(domainDoc, prefix + "/graphics/@listen", to.getVncAddr());
assertXpath(domainDoc, prefix + "/graphics/@autoport", "yes");
assertXpath(domainDoc, prefix + "/graphics/@passwd", to.getVncPassword());
assertXpath(domainDoc, prefix + "/graphics/@passwd", StringUtils.truncate(to.getVncPassword(), 8));
}
private void verifySerialDevices(Document domainDoc, String prefix) {