Repository navigation
Conversation
|
@waterWang you are adding a lot of PRs, thanks. Very welcome. You are basing all your PRs of main, though the reports/issues are on 4.22 for the most time. Do you think you can rebase them? |
DaanHoogland
left a comment
There was a problem hiding this comment.
@waterWang, assess if this is applicable to branch 4.20 as well, and rebase to either that branch or to 4.22.
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by an unhandled whitespace-only inventory/path value that can remain unencoded in the URI, along with missing regression tests for spaces, nested paths, and reserved characters.
2 open issues
What changed in this PR
This pull request fixes VMware import failures by percent-encoding vCenter inventory names in virt-v2v and ovftool URIs.
Changes:
- Adds UTF-8 percent-encoding for URI components, using
%20for spaces. - Preserves
/separators in nested datacenter, cluster, and inventory paths. - Applies encoding to
vpx://andvi://URL construction and usernames.
This pull request requires changes.
| File | Review findings |
|---|---|
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java |
Moderate (2 votes): StringUtils.isBlank leaves whitespace-only inventory names or path segments unencoded; use null/empty checks so they reach URLEncoder.Nit (4 votes): Add regression tests covering spaces, nested slash-preserving paths, reserved characters, and generated vi:// paths. |
Review effort: Lite
| private String encodePathSegment(String value) { | ||
| if (StringUtils.isBlank(value)) { | ||
| return value; | ||
| } | ||
| return URLEncoder.encode(value, StandardCharsets.UTF_8).replace("+", "%20"); | ||
| } | ||
|
|
||
| private String encodePathSegments(String value) { | ||
| if (StringUtils.isBlank(value)) { | ||
| return value; |
| private String encodePathSegment(String value) { | ||
| if (StringUtils.isBlank(value)) { | ||
| return value; | ||
| } | ||
| return URLEncoder.encode(value, StandardCharsets.UTF_8).replace("+", "%20"); | ||
| } | ||
|
|
||
| private String encodePathSegments(String value) { | ||
| if (StringUtils.isBlank(value)) { | ||
| return value; | ||
| } | ||
| StringBuilder encoded = new StringBuilder(); | ||
| for (String seg : value.split("/", -1)) { | ||
| if (encoded.length() > 0) { | ||
| encoded.append("/"); | ||
| } | ||
| encoded.append(encodePathSegment(seg)); | ||
| } | ||
| return encoded.toString(); |


Fixes #13920
Summary
LibvirtConvertInstanceCommandWrapperbuilds vpx:// and vi:// connection URIs for virt-v2v by concatenating vCenter datacenter/cluster/host names without percent-encoding them. A datacenter (or cluster/host) name containing a space — valid in vSphere — produces an invalid URI, and VM import from VMware fails.Changes
encodePathSegment— percent-encodes a single URI path segment using%20for spaces (not+)encodePathSegments— splits on/and encodes each sub-segment individually, preserving literal/separators for folder-nested names (e.g.MyFolder/MyDC)buildVpxUrl— now callsencodePathSegmentson datacenter and cluster,encodePathSegmenton hostgetExportOVAUrlFromRemoteInstance— now callsencodePathSegmentson datacenter and path,encodePathSegmenton vmencodeUsername— fixed to use explicitUTF-8charset and%20instead of+for spaces (libvirt only decodes%20in URI authority segments)Testing
Manual test: with a datacenter named
QA Lab, the vpx:// URL now correctly becomes: