Skip to content

<fix>[kvm]: normalize osVersion when matching DVD metadata#3748

Closed
ZStack-Robot wants to merge 1 commit into5.5.12from
sync/yaohua.wu/bugfix/ZSTAC-83682-reopen@@2
Closed

<fix>[kvm]: normalize osVersion when matching DVD metadata#3748
ZStack-Robot wants to merge 1 commit into5.5.12from
sync/yaohua.wu/bugfix/ZSTAC-83682-reopen@@2

Conversation

@ZStack-Robot
Copy link
Copy Markdown
Collaborator

ZSTAC-83682 (reopen)

Root Cause

On Kylin Linux Advanced Server V10 hosts, KVMHostVO.osVersion is persisted as V10 straight from /etc/os-release (VERSION_ID="V10"), while the matching DVD script /opt/zstack-dvd/x86_64/ky10sp3/Extra/virtualizer-info.sh hard-codes platform.version:10. KvmHypervisorInfoHelper.collectExpectedHypervisorInfoForHosts builds the lookup key as String.format("%s %s", os.distribution, os.version), so the host side asks for kylin V10 while HostOsCategoryVO.osReleaseVersion only has kylin 10. The join silently returns 0 rows, matchTargetVersion stays null and every Kylin host is stuck in matchState=Unknown even when its qemu-kvm version matches the DVD exactly. Verified on env 172.24.189.63 — 4 hosts, host qemu and DVD metadata both 6.2.0-451.g623f2a5caf.ky10, all stuck in Unknown.

This was masked before the alarm-side fixes because the alarm filter only looked at Unmatched. Once the alarm side started covering non-Matched states, the case test_zstack_mn_host_qemu (which asserts API field values directly) exposed the lookup miss.

Changes

Module Change
plugin/kvm Add KvmHypervisorInfoHelper.normalizeOsVersion. Strip a leading V/v only when followed by a digit (V10 -> 10, Vrouter stays Vrouter).
plugin/kvm Apply normalizeOsVersion in collectExpectedHypervisorInfoForHosts when building the lookup key.
plugin/kvm Apply normalizeOsVersion in HypervisorMetadataCollectorImpl.collectHypervisorMetadata when persisting a fresh metadata row from the DVD script output.

Test

  • New HypervisorMetadataCase.testNormalizeOsVersionForKylinHost subtest (in the linked premium MR) covers the helper boundaries (V10/v10/10/null/empty/V/Vrouter/whitespace) and a simulated Kylin V10 host plus DVD platform.version:10 end-to-end join.
  • Existing CentOS-based subtests are untouched and remain a no-op against the new helper.

Impact

  • Existing CentOS/Rocky/Helix hosts whose osVersion is already a plain numeric string see no behavioral change (normalization is a no-op for them).
  • Existing metadata is rebuilt with the normalized form on the next refreshMetadata() call (i.e. MN restart). No manual data migration needed.

Related MRs

  • premium MR: see bugfix/ZSTAC-83682-reopen@@2 on premium

Related: ZSTAC-83682

sync from gitlab !9616

Strip a leading V/v from osVersion before building the
HostOsCategoryVO lookup key, so that distributions that
expose VERSION_ID="V10" (notably Kylin Linux Advanced
Server) join correctly with DVD metadata that records
the same release as plain "10".

1. Why is this change necessary?
KvmHypervisorInfoHelper.collectExpectedHypervisorInfoForHosts
builds the lookup key as "<distribution> <version>" and
compares it against HostOsCategoryVO.osReleaseVersion. On
Kylin V10 hosts KVMHostVO.osVersion is persisted as "V10"
straight from /etc/os-release VERSION_ID, while the DVD
script /opt/zstack-dvd/x86_64/ky10sp3/Extra/virtualizer-info.sh
hard-codes platform.version:10. The two sides build
"kylin V10" vs "kylin 10", the join silently returns
nothing and matchTargetVersion stays null, leaving every
Kylin host in matchState=Unknown even when its qemu-kvm
version matches the DVD exactly. Was masked before by the
alarm filter only looking at Unmatched.

2. How does it address the problem?
Add KvmHypervisorInfoHelper.normalizeOsVersion that strips
a leading V/v only when the next character is a digit, so
"V10" -> "10" but "Vrouter" stays "Vrouter". Apply the
same normalization on both sides: when lookup builds the
osReleaseVersion key, and when HypervisorMetadataCollectorImpl
writes a fresh metadata row from the DVD script output.
With both sides normalized the join succeeds and the
existing matchState pipeline reports Matched/Unmatched.

3. Are there any side effects?
None on existing CentOS/Rocky/Helix hosts whose osVersion
is already a plain numeric string. Existing metadata is
rebuilt with the normalized form on the next refreshMetadata
call (i.e. MN restart) so no manual data migration is
needed.

# Summary of changes (by module):
- kvm: add normalizeOsVersion helper and apply it both in
  collectExpectedHypervisorInfoForHosts (lookup) and in
  HypervisorMetadataCollectorImpl.collectHypervisorMetadata
  (metadata write).

Related: ZSTAC-83682
Change-Id: I4c160f416490e91a08df0acdc5594effb23160e4
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 9a893954-097e-481f-b2dd-7b4058fd49c1

📥 Commits

Reviewing files that changed from the base of the PR and between fd5cea1 and bcb77ba.

📒 Files selected for processing (2)
  • plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/HypervisorMetadataCollectorImpl.java
  • plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/KvmHypervisorInfoHelper.java

演进概览

两个KVM超管理器文件现已规范化操作系统版本值。新增normalizeOsVersion方法用于删除前导"V"字母并修剪空格。HypervisorMetadataCollectorImplKvmHypervisorInfoHelper均采用该规范化逻辑。

变更明细

队列 / 文件 摘要
OS版本规范化辅助方法
plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/KvmHypervisorInfoHelper.java
新增公共静态方法normalizeOsVersion,用于修剪空格并移除版本号前的"V"/"v"字母(如V1010),防止不同OS发布源之间的join键不匹配。
超管理器元数据收集
plugin/kvm/src/main/java/org/zstack/kvm/hypervisor/HypervisorMetadataCollectorImpl.java
collectHypervisorMetadata方法现在规范化platformVersion值后再设置OS发布版本字符串,通过调用新增的规范化方法确保版本格式一致。

代码审阅工作量估计

🎯 2 (简单) | ⏱️ ~10 分钟

庆祝诗

🐰 版本号规范化,前导V字消散,
空格修剪整齐,join键不再冲突,
小小改动,大大稳定,
超管理器更和谐!✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题完全相关,清晰总结了主要变更:为DVD元数据匹配时的osVersion标准化,遵循指定格式且长度58字符(≤72字符)。
Description check ✅ Passed 描述与变更集高度相关,详细说明了根本原因、具体修改、测试方案和影响范围。

✏️ 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/yaohua.wu/bugfix/ZSTAC-83682-reopen@@2

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

@MatheMatrix MatheMatrix deleted the sync/yaohua.wu/bugfix/ZSTAC-83682-reopen@@2 branch April 16, 2026 05:18
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