<fix>[expon]: fix vhost installPath overwrite and test cleanup#3360
<fix>[expon]: fix vhost installPath overwrite and test cleanup#3360ZStack-Robot wants to merge 1 commit into5.5.6from
Conversation
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
Walkthrough此 PR 为外部主存储平台(Expon 和 Xinfini)增加完整支持,包括 URL scheme 配置处理、KVM CBD 路径转换逻辑调整、存储资源释放保护,以及广泛的集成测试框架和测试用例。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Comment |
There was a problem hiding this comment.
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 tosetSchememethod.The
schemefield is passed directly to OkHttp'sHttpUrl.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; }
ZSTAC-82153
Changes
Test
Related: ZSTAC-82153
sync from gitlab !9194