Skip to content

ZSTAC-63024 Block cross-vendor VM migration#4199

Open
zstack-robot-1 wants to merge 2 commits into
5.5.28from
sync/ye.zou/fix/ZSTAC-63024-5.5.28
Open

ZSTAC-63024 Block cross-vendor VM migration#4199
zstack-robot-1 wants to merge 2 commits into
5.5.28from
sync/ye.zou/fix/ZSTAC-63024-5.5.28

Conversation

@zstack-robot-1

Copy link
Copy Markdown
Collaborator

Summary

  • Reuse the existing KVM migration host allocator property filter to reject known incompatible host CPU vendors.
  • Derive Hygon/Intel/AMD vendor from HostSystemTags.HOST_CPU_MODEL_NAME instead of adding a migration-specific extension point.
  • Recognize Hygon/C86, Intel/GenuineIntel, and AMD/EPYC/AuthenticAMD host CPU model strings.
  • Add regression coverage in MigrateVmCheckKvmPropertyCase for Intel/Hygon and Intel/AMD migration candidates.

Verification

  • PR docker privileged container with zstack and premium mounted, using container MySQL.
  • ./runMavenProfile premium passed before the follow-up zstack-only patch.
  • mvn install -DskipTests -Djacoco.skip=true -DskipJacoco=true in plugin/kvm passed.
  • mvn test -Dtest=StabilityTestCase -Dcases=org.zstack.test.integration.kvm.host.MigrateVmCheckKvmPropertyCase -Dtimes=1 -Djacoco.skip=true -DskipJacoco=true in test passed.

Resolves: ZSTAC-63024

sync from gitlab !10156

AlanJager added 2 commits June 5, 2026 20:37
Keep migration compatibility in the existing KVM host allocator filter and derive known host CPU vendors from HostSystemTags.HOST_CPU_MODEL_NAME.

Constraint: Hygon and Intel hosts are not live-migration compatible
Rejected: Add a dedicated migration extension point | existing KVM migration property filtering already owns these checks
Confidence: high
Scope-risk: narrow
Tested: PR docker ./runMavenProfile premium
Tested: mvn test -Dtest=StabilityTestCase -Dcases=org.zstack.test.integration.kvm.host.MigrateVmCheckKvmPropertyCase -Dtimes=1

Resolves: ZSTAC-63024

Change-Id: I407c1a6358b2bfa91f5676cbbcab1fabd573603a
Recognize AMD, EPYC, AuthenticAMD and GenuineIntel host CPU model strings when filtering live migration candidates.

Tested: mvn install -DskipTests -Djacoco.skip=true -DskipJacoco=true in plugin/kvm
Tested: mvn test -Dtest=StabilityTestCase -Dcases=org.zstack.test.integration.kvm.host.MigrateVmCheckKvmPropertyCase -Dtimes=1 -Djacoco.skip=true -DskipJacoco=true in test

Resolves: ZSTAC-63024

Change-Id: I4b4d9c703dc14942c63a24599e8299ed9a9b2afd
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Could not fetch remote config from http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml: TimeoutError: The operation was aborted due to timeout
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

总览

该PR在KVM主机分配过滤中新增CPU供应商兼容性检查机制。通过从CPU型号名映射供应商,在主机选择时确保源主机和目标主机的CPU供应商一致,影响Live Migration候选主机的筛选范围。

变更

CPU供应商兼容性检查

层级 / 文件 说明
属性定义与接口扩展
plugin/kvm/src/main/java/org/zstack/kvm/KVMHostAllocatorFilterExtensionPoint.java
新增HOST_CPU_VENDOR属性常量、HostSystemTags导入,以及KVMPropertyChecker接口的propertyMatched默认方法,支持自定义属性匹配逻辑。
CPU供应商检查器实现与匹配逻辑更新
plugin/kvm/src/main/java/org/zstack/kvm/KVMHostAllocatorFilterExtensionPoint.java
实现HostCpuVendorCheckerHOST_CPU_MODEL_NAME系统标签读取CPU型号名,按关键字映射为amd/hygon/intel供应商;将allPropertiesMatched的属性比对从Objects.equals改为调用各检查器的propertyMatched方法;更新过滤失败原因文案加入供应商不兼容描述。
测试用例验证CPU供应商兼容性
test/src/test/groovy/org/zstack/test/integration/kvm/host/MigrateVmCheckKvmPropertyCase.groovy
新增Intel/AMD/Hygon型号常量、HostSystemTags导入,在环境模拟中设置宿主CPU型号,在testHostTokenMismatch后续场景中验证不同供应商组合下迁移候选主机的可用性。

预估评审工作量

🎯 3 (Moderate) | ⏱️ ~25 minutes

诗句

🐰 CPU厂商相逢必相同,
Intel、AMD、Hygon论芬芳,
迁移选主按此理,
主机兼容无差误,
测试场景尽周全!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR title accurately summarizes the main change: blocking cross-vendor VM migration by implementing CPU vendor compatibility checks in KVM host allocator filter.
Description check ✅ Passed PR description is directly related to the changeset, providing clear summary of implementation approach, vendor recognition strategy, test coverage, and verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/ye.zou/fix/ZSTAC-63024-5.5.28

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/src/test/groovy/org/zstack/test/integration/kvm/host/MigrateVmCheckKvmPropertyCase.groovy (1)

256-272: ⚡ Quick win

建议:增加未知厂商(null vendor)的测试场景

当前测试覆盖了 Intel↔Hygon 和 Intel↔AMD 的不兼容场景,但未测试 toCpuVendor 返回 null 的情况(即 CPU 型号无法识别时)。根据 HostCpuVendorChecker.propertyMatched 的实现,当任一方为 null 时应允许迁移。

建议添加一个测试用例,验证当某主机的 CPU 型号无法识别为已知厂商时的迁移行为:

def unknownHostCpuModelName = "Unknown CPU Model XYZ"

// 测试未知厂商应兼容任意厂商
HostSystemTags.HOST_CPU_MODEL_NAME.updateTagByToken(host2.uuid, HostSystemTags.HOST_CPU_MODEL_NAME_TOKEN, unknownHostCpuModelName)
confirmMigrateAvailable(vm1)
confirmMigrateAvailable(vm2)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@test/src/test/groovy/org/zstack/test/integration/kvm/host/MigrateVmCheckKvmPropertyCase.groovy`
around lines 256 - 272, Add a test case that sets host2's CPU model to an
unrecognized string and asserts migration is allowed: use
HostSystemTags.HOST_CPU_MODEL_NAME.updateTagByToken(host2.uuid,
HostSystemTags.HOST_CPU_MODEL_NAME_TOKEN, unknownHostCpuModelName) (define
unknownHostCpuModelName = "Unknown CPU Model XYZ") and call
confirmMigrateAvailable(vm1) and confirmMigrateAvailable(vm2); this verifies
HostCpuVendorChecker.propertyMatched behavior when toCpuVendor returns null and
complements the existing Intel/Hygon/AMD checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@plugin/kvm/src/main/java/org/zstack/kvm/KVMHostAllocatorFilterExtensionPoint.java`:
- Around line 24-25: The enum constant CPU_MODEL_NAME has a typo in its
associated string value; update the value in
KVMHostAllocatorFilterExtensionPoint (the CPU_MODEL_NAME enum entry) from "cpu
mode name" to "cpu model name" so the constant correctly reads
CPU_MODEL_NAME("cpu model name"); leave HOST_CPU_VENDOR unchanged.

---

Nitpick comments:
In
`@test/src/test/groovy/org/zstack/test/integration/kvm/host/MigrateVmCheckKvmPropertyCase.groovy`:
- Around line 256-272: Add a test case that sets host2's CPU model to an
unrecognized string and asserts migration is allowed: use
HostSystemTags.HOST_CPU_MODEL_NAME.updateTagByToken(host2.uuid,
HostSystemTags.HOST_CPU_MODEL_NAME_TOKEN, unknownHostCpuModelName) (define
unknownHostCpuModelName = "Unknown CPU Model XYZ") and call
confirmMigrateAvailable(vm1) and confirmMigrateAvailable(vm2); this verifies
HostCpuVendorChecker.propertyMatched behavior when toCpuVendor returns null and
complements the existing Intel/Hygon/AMD checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 757fa610-be67-4aac-aed8-dfdcdf0d2913

📥 Commits

Reviewing files that changed from the base of the PR and between c19ba5c and 6f8f555.

📒 Files selected for processing (2)
  • plugin/kvm/src/main/java/org/zstack/kvm/KVMHostAllocatorFilterExtensionPoint.java
  • test/src/test/groovy/org/zstack/test/integration/kvm/host/MigrateVmCheckKvmPropertyCase.groovy

Comment on lines +24 to +25
CPU_MODEL_NAME("cpu mode name"),
HOST_CPU_VENDOR("host cpu vendor");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

枚举常量 CPU_MODEL_NAME 存在拼写错误

"cpu mode name" 应为 "cpu model name",当前拼写 "mode" 是错误的。

🐛 建议修复
-        CPU_MODEL_NAME("cpu mode name"),
+        CPU_MODEL_NAME("cpu model name"),
         HOST_CPU_VENDOR("host cpu vendor");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CPU_MODEL_NAME("cpu mode name"),
HOST_CPU_VENDOR("host cpu vendor");
CPU_MODEL_NAME("cpu model name"),
HOST_CPU_VENDOR("host cpu vendor");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@plugin/kvm/src/main/java/org/zstack/kvm/KVMHostAllocatorFilterExtensionPoint.java`
around lines 24 - 25, The enum constant CPU_MODEL_NAME has a typo in its
associated string value; update the value in
KVMHostAllocatorFilterExtensionPoint (the CPU_MODEL_NAME enum entry) from "cpu
mode name" to "cpu model name" so the constant correctly reads
CPU_MODEL_NAME("cpu model name"); leave HOST_CPU_VENDOR unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants