Skip to content

ZSTAC-86553 Fix IPv6 NBD target URI formatting#4412

Merged
MatheMatrix merged 1 commit into
5.5.28from
sync/shixin.ruan/shixin-ZSTAC-86553-5.5.28
Jul 3, 2026
Merged

ZSTAC-86553 Fix IPv6 NBD target URI formatting#4412
MatheMatrix merged 1 commit into
5.5.28from
sync/shixin.ruan/shixin-ZSTAC-86553-5.5.28

Conversation

@zstack-robot-2

Copy link
Copy Markdown
Collaborator

Summary

  • Format IPv6 hosts with brackets when generating NBD remote target URIs.
  • Add coverage for backup/addon NBD target URI formatting.

Verification

  • mvn -pl header -DskipTests compile
  • mvn -f test/pom.xml -Dtest=org.zstack.test.integration.core.ManagementNetworkIpv6Case test was attempted, but the local test module fails before this case due existing KVMHostUtils/ApiResponse API mismatches.

Jira: ZSTAC-86553

sync from gitlab !10373

Format IPv6 hosts with brackets when building NBD target URIs.

ZSTAC-86553

Test: mvn -pl header -DskipTests compile

Change-Id: I60ec48719c304cddbeb06954050ac2fe
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

本次改动为 addon 和 backup 两个包中的 NbdRemoteTarget 类引入 IPv6NetworkUtils.formatHostForUrl,在生成 NBD 目标 URI 时对主机部分进行格式化,使 IPv6 地址正确加上中括号。新增测试用例验证该行为。

Changes

NBD URI IPv6 主机格式化

Layer / File(s) Summary
主机格式化改造
header/.../addon/NbdRemoteTarget.java, header/.../backup/NbdRemoteTarget.java
两处 NbdRemoteTarget 均引入 IPv6NetworkUtils,在拼接 URI 主机部分时改用 formatHostForUrl 处理 ip/hostname。
测试验证
test/.../ManagementNetworkIpv6Case.groovy
新增测试方法验证 IPv6 地址生成带中括号的 URI,IPv4 地址不带中括号。

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant NbdRemoteTarget
  participant IPv6NetworkUtils
  Caller->>NbdRemoteTarget: getResourceURI()/getTargetUri(hostname)
  NbdRemoteTarget->>IPv6NetworkUtils: formatHostForUrl(ip/hostname)
  IPv6NetworkUtils-->>NbdRemoteTarget: 格式化后的host
  NbdRemoteTarget-->>Caller: nbd:// URI
Loading

Poem

小兔敲代码,格式来帮忙,
IPv6 地址,中括号来装,
nbd:// 链接,从此更顺畅,
测试来验证,无惧网络长~ 🐰


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error 标题与变更相关,但未按要求使用“type[scope]: description”格式,且包含 Jira 键而非规范前缀。 改为符合格式的标题,例如“fix[storage]: format IPv6 NBD target URIs”,并控制在 72 字符内。
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed 描述与本次 IPv6 NBD URI 格式化及测试覆盖新增内容一致,相关性明确。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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/shixin.ruan/shixin-ZSTAC-86553-5.5.28

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

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/src/test/groovy/org/zstack/test/integration/core/ManagementNetworkIpv6Case.groovy (1)

92-130: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

新增测试方法未被 test() 调用,实际不会执行。

testNbdTargetUriUsesBracketedIpv6Host()(第265-275行)定义完整,但在唯一的 @Test 入口 test() 方法的调用列表(93-129行)中未找到对它的调用。该测试虽然能编译通过,但永远不会被执行,PR 所声称的"新增测试覆盖"实际未生效。

🔧 修复建议:在合适位置补充调用
         testSshTargetUsesRawIpv6Host()
         testScpTargetUsesBracketedIpv6Host()
+        testNbdTargetUriUsesBracketedIpv6Host()
         testCallbackCheckerUsesIpv6Options()
🤖 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/core/ManagementNetworkIpv6Case.groovy`
around lines 92 - 130, The new test method
testNbdTargetUriUsesBracketedIpv6Host() is defined but never executed because it
is missing from the test() invocation list. Update the
ManagementNetworkIpv6Case.groovy test() method to call
testNbdTargetUriUsesBracketedIpv6Host() alongside the other test* methods so the
added coverage actually runs.
🧹 Nitpick comments (1)
test/src/test/groovy/org/zstack/test/integration/core/ManagementNetworkIpv6Case.groovy (1)

270-273: 📐 Maintainability & Code Quality | 🔵 Trivial

建议补充 addon 场景的 IPv4 断言以保持对称性。

backupTarget 同时验证了 IPv6 与 IPv4 两种情形,而 addonTarget 只验证了 IPv6。建议补充一条 IPv4 断言,确保 addon.NbdRemoteTarget 在两种地址族下都有覆盖。

♻️ 建议补充的断言
         def addonTarget = new org.zstack.header.storage.addon.NbdRemoteTarget()
         addonTarget.setIp(IPV6)
         addonTarget.setPort(10401)
         assert addonTarget.getResourceURI() == "nbd://[2001:db8::1]:10401"
+
+        addonTarget.setIp(IPV4)
+        assert addonTarget.getResourceURI() == "nbd://192.168.1.10:10401"
🤖 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/core/ManagementNetworkIpv6Case.groovy`
around lines 270 - 273, The addon.NbdRemoteTarget test currently covers only the
IPv6 getResourceURI case, so add a matching IPv4 assertion to keep parity with
backupTarget coverage. Update the ManagementNetworkIpv6Case test around
addonTarget to also set an IPv4 address and verify the URI format, using the
existing NbdRemoteTarget methods setIp and getResourceURI as the anchors for the
new assertion.
🤖 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.

Outside diff comments:
In
`@test/src/test/groovy/org/zstack/test/integration/core/ManagementNetworkIpv6Case.groovy`:
- Around line 92-130: The new test method
testNbdTargetUriUsesBracketedIpv6Host() is defined but never executed because it
is missing from the test() invocation list. Update the
ManagementNetworkIpv6Case.groovy test() method to call
testNbdTargetUriUsesBracketedIpv6Host() alongside the other test* methods so the
added coverage actually runs.

---

Nitpick comments:
In
`@test/src/test/groovy/org/zstack/test/integration/core/ManagementNetworkIpv6Case.groovy`:
- Around line 270-273: The addon.NbdRemoteTarget test currently covers only the
IPv6 getResourceURI case, so add a matching IPv4 assertion to keep parity with
backupTarget coverage. Update the ManagementNetworkIpv6Case test around
addonTarget to also set an IPv4 address and verify the URI format, using the
existing NbdRemoteTarget methods setIp and getResourceURI as the anchors for the
new assertion.

ℹ️ 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: e69b091c-f983-4f22-b3fe-3c48469b8f89

📥 Commits

Reviewing files that changed from the base of the PR and between d22b42d and 491c7e8.

📒 Files selected for processing (3)
  • header/src/main/java/org/zstack/header/storage/addon/NbdRemoteTarget.java
  • header/src/main/java/org/zstack/header/storage/backup/NbdRemoteTarget.java
  • test/src/test/groovy/org/zstack/test/integration/core/ManagementNetworkIpv6Case.groovy

@MatheMatrix MatheMatrix merged commit 1aeeb79 into 5.5.28 Jul 3, 2026
1 check passed
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.

3 participants