Skip to content

<fix>[expon]: fix vhost installPath overwrite and test cleanup#3360

Open
ZStack-Robot wants to merge 1 commit into5.5.6from
sync/yaohua.wu/ZSTAC-82153@@2
Open

<fix>[expon]: fix vhost installPath overwrite and test cleanup#3360
ZStack-Robot wants to merge 1 commit into5.5.6from
sync/yaohua.wu/ZSTAC-82153@@2

Conversation

@ZStack-Robot
Copy link
Collaborator

ZSTAC-82153

Changes

  • Fix vhost installPath being overwritten during volume migration
  • Make vhost bound USS simulator stateful for test stability
  • Move XinfiniPrimaryStorageCase from premium to community test
  • Add null host check in preReleaseVmResource
  • Fix CD-ROM null path handling

Test

  • ExponPrimaryStorageCase: 10/10 stability test passed
  • XinfiniPrimaryStorageCase: 10/10 stability test passed

Related: ZSTAC-82153

sync from gitlab !9194

Fix CBD KvmCbdNodeServer overwriting vhost volume installPath
and add Expon storage API simulators for integration test.

1. Why is this change necessary?
KvmCbdNodeServer.convertPathIfNeeded unconditionally returned
the original installPath for non-CBD protocols, causing
convertAndSetPathIfNeeded to overwrite the /var/run/vhost path
that KvmVhostNodeServer had already set. This made the
ExponPrimaryStorageCase test fail on installPath assertion.
Additionally, vol2 was not cleaned up in testClean, causing
a ConstraintViolationException during env.delete.

2. How does it address the problem?
- Changed convertPathIfNeeded to return null for non-CBD
  protocols so the setter is skipped
- Added vol2 cleanup in testClean to prevent FK violation
- Added Expon API simulators in ExternalPrimaryStorageSpec
- Updated ExponStorageController and SDK for test support

3. Are there any side effects?
None. The CBD fix only affects non-CBD protocol volumes
which should not have been modified by CBD code.

# Summary of changes (by module):
- cbd: fix convertPathIfNeeded to skip non-CBD protocols
- expon: add simulator support for ExponStorageController
- expon/sdk: update ExponClient and ExponConnectConfig
- test: fix vol2 cleanup and update test assertions
- testlib: add Expon API simulators

Related: ZSTAC-82153
Change-Id: I6515e2e7bce3461f08f70918b6ee30714b0b3149
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Walkthrough

此 PR 为外部主存储平台(Expon 和 Xinfini)增加完整支持,包括 URL scheme 配置处理、KVM CBD 路径转换逻辑调整、存储资源释放保护,以及广泛的集成测试框架和测试用例。

Changes

Cohort / File(s) Summary
Expon Scheme 配置
plugin/expon/src/main/java/org/zstack/expon/ExponStorageController.java, plugin/expon/src/main/java/org/zstack/expon/sdk/ExponClient.java, plugin/expon/src/main/java/org/zstack/expon/sdk/ExponConnectConfig.java
新增 scheme 字段到 ExponConnectConfig,默认值为 "https";ExponStorageController 构造函数中读取 URI scheme 并设置默认端口(https 为 443,否则为 80);ExponClient 中将 URL scheme 从硬编码改为使用 config.scheme。
KVM CBD 路径处理
plugin/cbd/src/main/java/org/zstack/cbd/kvm/KvmCbdNodeServer.java
调整 convertPathIfNeeded 逻辑,当协议非 CBD 或无节点服务时返回 null;convertAndSetPathIfNeeded 仅在路径非空时设置值。
外部主存储资源管理
storage/src/main/java/org/zstack/storage/addon/primary/ExternalPrimaryStorageFactory.java
为 preReleaseVmResource 添加 null destination host 保护,防止目标主机不存在时触发卷停用操作。
测试基础设施与模拟器
testlib/src/main/java/org/zstack/testlib/ExternalPrimaryStorageSpec.groovy, testlib/src/main/java/org/zstack/testlib/SpringSpec.groovy, test/src/test/groovy/org/zstack/test/integration/storage/StorageTest.groovy
为 ExternalPrimaryStorageSpec 添加 ExponSimulators 和 XinfiniSimulators 两个完整的 Simulator 实现;SpringSpec 新增 xinfini() 方法;StorageTest 添加 xinfini() 初始化调用。
集成测试用例
test/src/test/groovy/org/zstack/test/integration/storage/primary/addon/expon/ExponPrimaryStorageCase.groovy, test/src/test/groovy/org/zstack/test/integration/storage/primary/addon/xinfini/XinfiniPrimaryStorageCase.groovy
修改 ExponPrimaryStorageCase 将 HTTPS 改为 HTTP、改为顺序 VM 创建、增强 USS 端点模拟器;新增 XinfiniPrimaryStorageCase 完整测试套件,覆盖存储创建、VM 生命周期、卷操作、快照、模板等场景。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Expon 和 Xinfini 齐上阵,
Scheme 配置巧妙又端庄,
路径智慧更保守谨慎,
测试框架如春笋竹竿,
存储梦想向前冲冲冲! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ⚠️ Unable to check for merge conflicts: Invalid branch name format
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows the required format [scope]: with 62 characters and clearly summarizes the main changes related to fixing vhost installPath overwrite and test cleanup.
Description check ✅ Passed The pull request description is comprehensive and directly related to the changeset, detailing specific fixes, test improvements, and including issue references with test results.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/yaohua.wu/ZSTAC-82153@@2
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch sync/yaohua.wu/ZSTAC-82153@@2
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

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

Copy link

@coderabbitai coderabbitai bot left a comment

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)
testlib/src/main/java/org/zstack/testlib/ExternalPrimaryStorageSpec.groovy (1)

23-24: ⚠️ Potential issue | 🟡 Minor

注释中包含中文文本,违反编码规范。

第 23 行的注释 下午2:28 包含中文,根据编码规范要求,代码中不应包含中文(包括注释)。

建议修复
-/**
- * `@author` Xingwei Yu
- * `@date` 2024/4/19 下午2:28
- */
+/**
+ * `@author` Xingwei Yu
+ * `@date` 2024/4/19 14:28
+ */

As per coding guidelines: **/*.*: 代码里不应当有有中文,包括报错、注释等都应当使用正确的、无拼写错误的英文来写

🧹 Nitpick comments (3)
testlib/src/main/java/org/zstack/testlib/ExternalPrimaryStorageSpec.groovy (1)

1010-1020: 建议合并重复的 null 检查逻辑。

/:flatten/:rollback 处理器中,vol == null 的检查逻辑可以提前,避免先修改状态再检查 null 的情况。

建议优化(以 /:flatten 为例)
 // 14. POST /afa/v1/bs-volumes/{id}/:flatten - FlattenVolumeRequest
 simulator("/afa/v1/bs-volumes/\\d+/:flatten") { HttpServletRequest req, HttpEntity<String> e, EnvSpec spec ->
     int volId = extractIdFromUri(req.getRequestURI())
     def vol = volumes.get(volId)
-    if (vol != null) {
-        vol.spec.flattened = true
-    }
     if (vol == null) {
         return makeNotFoundResponse()
     }
+    vol.spec.flattened = true
     return makeItemResponse(vol)
 }

Also applies to: 1023-1030

test/src/test/groovy/org/zstack/test/integration/storage/primary/addon/xinfini/XinfiniPrimaryStorageCase.groovy (1)

372-394: 考虑使用 retryInSecs 替代固定 sleep(1000)

当前使用 sleep(1000) 等待异步操作完成,这可能导致测试不稳定(在慢速环境下可能不够,在快速环境下又浪费时间)。建议参考第 396-399 行的 retryInSecs 模式。

建议优化示例
-        sleep(1000)
-        // vm in running, not deactivate volume
-        bdev = controller.apiHelper.queryBdcBdevByVolumeIdAndBdcId(volId, bdc.spec.id)
-        assert bdev != null
+        retryInSecs {
+            // vm in running, not deactivate volume
+            bdev = controller.apiHelper.queryBdcBdevByVolumeIdAndBdcId(volId, bdc.spec.id)
+            assert bdev != null
+        }
plugin/expon/src/main/java/org/zstack/expon/sdk/ExponConnectConfig.java (1)

8-46: Add validation and normalization to setScheme method.

The scheme field is passed directly to OkHttp's HttpUrl.Builder.scheme(), which only accepts "http" or "https". While OkHttp normalizes these case-insensitively, it is better to validate and normalize the input here to prevent potential issues and ensure consistency with RFC 3986. Also trim user input to handle accidental whitespace.

♻️ Recommended implementation (validation + normalization)
-import java.util.concurrent.TimeUnit;
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
@@
         public Builder setScheme(String scheme) {
-            config.scheme = scheme;
+            if (scheme == null || scheme.trim().isEmpty()) {
+                config.scheme = "https";
+                return this;
+            }
+            String normalized = scheme.trim().toLowerCase(Locale.ROOT);
+            if (!"http".equals(normalized) && !"https".equals(normalized)) {
+                throw new IllegalArgumentException("scheme must be http or https");
+            }
+            config.scheme = normalized;
             return this;
         }

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