apache / apache/cloudstack

VMware import (importVm) fails when datacenter/cluster/host name contains a space

未关闭
#13,920 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
component:kvm component:vmware Severity:Minor type:bug
主要语言
Java
星标
3.1k
派生
1.4k
平均合并
6 天 19 小时
30 天内合并 PR
32

描述

## Summary

`LibvirtConvertInstanceCommandWrapper` builds the `vpx://`/`vi://` connection URIs for virt-v2v by concatenating the 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.

## Environment

- CloudStack main (`659f675b059c1e5008deb3bb28793eadf377d687`)
- KVM host, `virt-v2v 2.7.1`, `libvirt 9.0.0`
- Import VM from VMware (UI: *Import Instance*, or the `importVm` API with `importsource=vmware`), reproduced on both the OVA-conversion path and the VDDK path (`-it vddk`)

## Steps to Reproduce

1. Rename a vCenter Datacenter to include a space, e.g. `"QA Lab"`.
2. Import a VM from it via the CloudStack UI (*Import Instance*) or the `importVm` API.
3. Conversion fails.

## Actual Behavior

```
Using VPX URL: vpx://Administrator%40vsphere.local@203.0.113.10/QA Lab/cluster-a/203.0.113.20?no_verify=1
virt-v2v: error: could not parse '-ic vpx://...QA Lab/cluster-a/203.0.113.20?no_verify=1'. Original error message was: parse_uri: unable to parse URI
```

Also seen on the VDDK import path (`-it vddk`), same unencoded `QA Lab` segment, surfacing as `java.io.IOException: Stream closed` instead — a downstream symptom of virt-v2v exiting immediately on the same bad URI, not a separate defect.

The username is correctly percent-encoded (`Administrator%40vsphere.local`); `datacenter`/`cluster`/`host` are not.

## Root Cause

`plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java`

- `buildVpxUrl` (~L463): appends `datacenter`, `cluster`, `host` raw after `url.append("/")`.
- `getExportOVAUrlFromRemoteInstance` (~L203): same pattern for `datacenter`/`path`/`vm` in the `vi://` URL.
- `encodeUsername` (~L298) uses `URLEncoder.encode`, which encodes space as `+` — wrong for a URI path/authority (libvirt only decodes `%20`). Not yet visible as a bug since vCenter usernames rarely have spaces, but worth fixing alongside the above with the same helper.

## Suggested Fix

Percent-encode `datacenter`/`cluster`/`host`/`path`/`vm` per `/`-delimited sub-segment (not as one string) — datacenter/cluster names can be folder-nested (e.g. `MyFolder/MyDC`), and that `/` must stay literal.

versions
ACS 4.22.1

贡献指南

打开贡献指南

调研方向

从 plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java 开始,阅读 buildVpxUrl、getExportOVAUrlFromRemoteInstance 和 encodeUsername。在 datacenter、cluster、host、path 或 VM 名称中包含空格的情况下重现导入,并检查 OVA 和 VDDK 两种路径。生成的 vpx:// 和 vi:// URI 能够成功解析,同时文件夹分隔符保持不变,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
backend, infrastructure
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
75/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。