forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[sdnController]: set lacp mode when change host #3149
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
Closed
+11
−3
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,16 +200,24 @@ private void validate(APISdnControllerChangeHostMsg msg) { | |
| msg.setNicNames(new ArrayList<>(nicNamePciAddressMap.keySet())); | ||
| } | ||
|
|
||
| if (msg.getNicNames().size() > 1 && msg.getBondMode() == null) { | ||
| if (msg.getBondMode() == null) { | ||
| msg.setBondMode(refVO.getBondMode()); | ||
| } | ||
|
|
||
| if (msg.getLacpMode() == null) { | ||
| if (msg.getBondMode().equals(refVO.getBondMode())) { | ||
| msg.setLacpMode(refVO.getLacpMode()); | ||
| } | ||
|
|
||
| if (msg.getBondMode() != null && msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_TCP) && msg.getLacpMode() == null) { | ||
| if (msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_TCP)) { | ||
| msg.setLacpMode(L2NetworkConstant.LACP_MODE_ACTIVE); | ||
|
Comment on lines
+211
to
212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 主要问题:用户提供的 lacpMode 被无条件覆盖。 当 建议仅在 if (msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_TCP)) {
- msg.setLacpMode(L2NetworkConstant.LACP_MODE_ACTIVE);
+ if (msg.getLacpMode() == null) {
+ msg.setLacpMode(L2NetworkConstant.LACP_MODE_ACTIVE);
+ }
}🤖 Prompt for AI Agents |
||
| } else if (msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_SLB)) { | ||
| if (msg.getLacpMode() == null) { | ||
| msg.setLacpMode(L2NetworkConstant.LACP_MODE_OFF); | ||
| } else if (!(msg.getLacpMode().equals(L2NetworkConstant.LACP_MODE_PASSIVE))) { | ||
| msg.setLacpMode(L2NetworkConstant.LACP_MODE_OFF); | ||
| } | ||
| } else { | ||
| msg.setLacpMode(L2NetworkConstant.LACP_MODE_OFF); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
严重问题:存在 NullPointerException 风险且代码逻辑存在缺陷。
第 207 行存在两个问题:
NPE 风险:如果
refVO.getBondMode()返回null,那么第 204 行会将msg.setBondMode(null),导致第 207 行msg.getBondMode().equals()抛出NullPointerException。无效代码:第 208 行设置的
lacpMode会被第 211-221 行的逻辑无条件覆盖。无论第 208 行设置什么值,后续的 if-else 链都会重新设置lacpMode。这使得第 207-209 行的代码实际上没有任何作用。🔎 建议的修复方案
需要重新设计此逻辑。如果意图是在 bondMode 未改变时保留原有 lacpMode,则应:
if (msg.getBondMode() == null) { msg.setBondMode(refVO.getBondMode()); } +if (msg.getBondMode() == null) { + throw new ApiMessageInterceptionException(argerr("could not change host[uuid:%s] of sdn controller[uuid:%s], " + + "because bondMode is not specified and reference bondMode is null", msg.getHostUuid(), msg.getSdnControllerUuid())); +} + -if (msg.getBondMode().equals(refVO.getBondMode())) { - msg.setLacpMode(refVO.getLacpMode()); -} - -if (msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_TCP)) { +if (msg.getBondMode().equals(refVO.getBondMode()) && msg.getLacpMode() == null) { + msg.setLacpMode(refVO.getLacpMode()); +} else if (msg.getLacpMode() == null && msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_TCP)) { msg.setLacpMode(L2NetworkConstant.LACP_MODE_ACTIVE); } else if (msg.getBondMode().equals(L2NetworkConstant.BONDING_MODE_SLB)) { if (msg.getLacpMode() == null) { msg.setLacpMode(L2NetworkConstant.LACP_MODE_OFF); } else if (!(msg.getLacpMode().equals(L2NetworkConstant.LACP_MODE_PASSIVE))) { msg.setLacpMode(L2NetworkConstant.LACP_MODE_OFF); } -} else { +} else if (msg.getLacpMode() == null) { msg.setLacpMode(L2NetworkConstant.LACP_MODE_OFF); }注意:此修复假设只在用户未提供 lacpMode 时才进行默认赋值。请根据实际业务需求调整。
🤖 Prompt for AI Agents