refactor: do not read pid file when calling ovs/ovn appctl command#6230
refactor: do not read pid file when calling ovs/ovn appctl command#6230zhangzujian merged 1 commit intokubeovn:masterfrom
Conversation
Summary of ChangesHello @zhangzujian, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the internal mechanism for executing Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the way ovs-appctl and ovn-appctl commands are executed by introducing helper functions, removing the need to read PID files. This is a good simplification of the codebase. However, I've identified a critical compilation error in the new code, along with a couple of medium-severity issues related to code clarity and robustness. Please review the detailed comments.
| switch { | ||
| case strings.IndexRune(target, os.PathSeparator) == 0: | ||
| fallthrough | ||
| case strings.HasPrefix(target, "ovn"): | ||
| cmd = cmdOvnAppctl | ||
| case strings.HasPrefix(target, "ovs"): | ||
| cmd = cmdOvsAppctl | ||
| default: | ||
| return "", fmt.Errorf("unknown target %q", target) | ||
| } |
There was a problem hiding this comment.
The use of fallthrough here makes the logic for choosing between ovn-appctl and ovs-appctl a bit subtle. It effectively defaults to using ovn-appctl for any absolute path. While this may work since ovn-appctl is a wrapper for ovs-appctl, it would be more robust and clearer to explicitly handle path-based targets. For example, you could check if the path contains 'ovn' or 'openvswitch' to select the appropriate tool. This would make the code more resilient, especially if it's ever used with OVS sockets in an environment where ovn-appctl might not be available.
05398b4 to
da9d1b9
Compare
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
da9d1b9 to
f31d0b8
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors how ovs/ovn appctl commands are executed by removing the need to read PID files. This is an excellent improvement that increases robustness and simplifies the code. The introduction of helper functions like ovs.OvnDatabaseControl also enhances code clarity at the call sites. I've identified one high-severity issue in the new logic for determining which appctl command to use, where any absolute path would incorrectly default to ovn-appctl. A code suggestion to rectify this logic has been provided.
| switch { | ||
| case strings.IndexRune(target, os.PathSeparator) == 0: | ||
| fallthrough | ||
| case strings.HasPrefix(target, "ovn"): | ||
| cmd = cmdOvnAppctl | ||
| case strings.HasPrefix(target, "ovs"): | ||
| cmd = cmdOvsAppctl | ||
| default: | ||
| return "", fmt.Errorf("unknown target %q", target) | ||
| } |
There was a problem hiding this comment.
The logic to determine whether to use ovs-appctl or ovn-appctl is flawed due to the use of fallthrough. Currently, any absolute path provided as a target will cause ovn-appctl to be used, which is incorrect for OVS control sockets (e.g., /var/run/openvswitch/ovs-vswitchd.ctl). This can lead to command failures for valid OVS targets specified with an absolute path. I suggest restructuring the logic to be more explicit and correct.
switch {
case strings.HasPrefix(target, "ovs"):
cmd = cmdOvsAppctl
case strings.HasPrefix(target, "ovn"):
cmd = cmdOvnAppctl
case strings.IndexRune(target, os.PathSeparator) == 0:
if strings.Contains(target, "openvswitch") {
cmd = cmdOvsAppctl
} else {
cmd = cmdOvnAppctl
}
default:
return "", fmt.Errorf("unknown target %q", target)
}
Pull Request
What type of this PR
Examples of user facing changes:
Which issue(s) this PR fixes
Fixes #(issue-number)