forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[externalapiadapter]: fix VM NIC driver type fallback #3933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zstack-robot-1
wants to merge
1
commit into
5.4.2
Choose a base branch
from
sync/boce.wang/fix-85160
base: 5.4.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 103
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 418
🏁 Script executed:
sed -n '140,160p' compute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.javaRepository: MatheMatrix/zstack
Length of output: 1041
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 126
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 5235
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 279
🏁 Script executed:
rg -n "platform" header/src/main/java/org/zstack/header/vm/VmInstanceAO.javaRepository: MatheMatrix/zstack
Length of output: 256
🏁 Script executed:
sed -n '75,95p' header/src/main/java/org/zstack/header/vm/VmInstanceAO.javaRepository: MatheMatrix/zstack
Length of output: 385
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 946
🏁 Script executed:
rg -n "prepareDbInitialValue" compute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.java -B5 -A15Repository: MatheMatrix/zstack
Length of output: 893
🏁 Script executed:
sed -n '120,170p' compute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.javaRepository: MatheMatrix/zstack
Length of output: 2231
避免在启动修复路径直接对平台字符串调用
valueOf,需要做安全解析VmInstanceAO.platform字段为可空(@Column未设置nullable=false),但 line 146 的ImagePlatform.valueOf(vmPlatform)在遇到 null 值或未知平台值时会抛IllegalArgumentException,导致prepareDbInitialValue()启动修复被中断。需要安全解析:未知/空值平台降级为defaultNicDriver并记录告警。建议修改(示例)
for (Tuple vmTuple : tupleList) { String vmUuid = vmTuple.get(0, String.class); String vmPlatform = vmTuple.get(1, String.class); - vmDrivers.put(vmUuid, virtioVmUuids.contains(vmUuid) || ImagePlatform.valueOf(vmPlatform).isParaVirtualization() ? - defaultPVNicDriver : defaultNicDriver); + Optional<ImagePlatform> platformOpt = Arrays.stream(ImagePlatform.values()) + .filter(p -> p.toString().equals(vmPlatform)) + .findFirst(); + boolean isParaVirtualization = platformOpt.map(ImagePlatform::isParaVirtualization).orElse(false); + if (vmPlatform != null && !platformOpt.isPresent()) { + logger.warn(String.format("unknown vm platform[%s] for vm[uuid:%s], fallback to default nic driver", + vmPlatform, vmUuid)); + } + vmDrivers.put(vmUuid, virtioVmUuids.contains(vmUuid) || isParaVirtualization + ? defaultPVNicDriver : defaultNicDriver); }符合向后兼容原则:启动修复应容错处理历史脏数据,避免因个别异常记录导致全局启动失败。
🤖 Prompt for AI Agents