-
Notifications
You must be signed in to change notification settings - Fork 259
utils_net: enable host interface setting for ovs bridge #4280
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
base: master
Are you sure you want to change the base?
Conversation
ovs bridge handling discovers the network interface to use. However, in our environments we need to select a specific interface that has DHCP. Make this parameter configurable but default to previous behavior to not change anything for existing tests. Signed-off-by: Sebastian Mitterle <smitterl@redhat.com>
WalkthroughThis pull request adds an optional Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
virttest/utils_net.py (1)
4631-4632: Consider validating user-provided interface name.When
iface_nameis explicitly provided by the user, the function doesn't validate that the interface exists or is in an appropriate state. This could lead to confusing errors later in the tmux command execution.Consider adding validation like:
if not iface_name: up_ifaces = get_net_if(runner=runner, state="UP", ip_options=ip_options) if not up_ifaces: raise exceptions.TestError( "No network interfaces in UP state found for OVS bridge creation" ) iface_name = up_ifaces[0] else: # Validate user-provided interface exists and is UP all_ifaces = get_net_if(runner=runner, ip_options=ip_options) if iface_name not in all_ifaces: raise exceptions.TestError( f"Specified interface '{iface_name}' does not exist" ) up_ifaces = get_net_if(runner=runner, state="UP", ip_options=ip_options) if iface_name not in up_ifaces: LOG.warning( f"Specified interface '{iface_name}' is not in UP state" )This same pattern would apply to
delete_ovs_bridgeat lines 4677-4678.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
virttest/utils_net.py(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Static checks
| if not iface_name: | ||
| iface_name = get_net_if(runner=runner, state="UP", ip_options=ip_options)[0] |
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.
Add bounds checking to prevent IndexError.
If get_net_if() returns an empty list (e.g., no interfaces in UP state), accessing [0] will raise an IndexError and crash at runtime.
Apply this diff to add proper error handling:
- if not iface_name:
- iface_name = get_net_if(runner=runner, state="UP", ip_options=ip_options)[0]
+ if not iface_name:
+ up_ifaces = get_net_if(runner=runner, state="UP", ip_options=ip_options)
+ if not up_ifaces:
+ raise exceptions.TestError(
+ "No network interfaces in UP state found for OVS bridge creation"
+ )
+ iface_name = up_ifaces[0]🤖 Prompt for AI Agents
In virttest/utils_net.py around lines 4631-4632, the code unconditionally
indexes [0] from get_net_if() which can be an empty list; add bounds checking by
capturing the returned list into a variable, test if it's non-empty, and only
then assign iface_name = result[0]; if the list is empty, raise a clear
exception (e.g., ValueError) or return a sensible default/None with a
descriptive message so the caller does not get an unhandled IndexError.
| if not iface_name: | ||
| iface_name = get_net_if(runner=runner, state="UP", ip_options=ip_options)[0] |
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.
Add bounds checking to prevent IndexError.
If get_net_if() returns an empty list (e.g., no interfaces in UP state), accessing [0] will raise an IndexError and crash at runtime.
Apply this diff to add proper error handling:
- if not iface_name:
- iface_name = get_net_if(runner=runner, state="UP", ip_options=ip_options)[0]
+ if not iface_name:
+ up_ifaces = get_net_if(runner=runner, state="UP", ip_options=ip_options)
+ if not up_ifaces:
+ raise exceptions.TestError(
+ "No network interfaces in UP state found for OVS bridge deletion"
+ )
+ iface_name = up_ifaces[0]🤖 Prompt for AI Agents
In virttest/utils_net.py around lines 4677-4678, the call get_net_if(...)[0] can
raise IndexError if it returns an empty list; change to first assign the result
to a variable (e.g., candidates = get_net_if(...)), check if candidates is
non-empty, and if empty raise a clear exception or handle the case (return, log
and exit, or raise ValueError with context including runner and ip_options);
otherwise set iface_name = candidates[0]. Ensure the new behavior is covered by
an appropriate error message and the function's callers can handle the raised
error.
|
Tested via autotest/tp-libvirt#6717 |
Tested via autotest/tp-libvirt#6717
ovs bridge handling discovers the network interface to use. However, in our environments we need to select a specific interface that has DHCP. Make this parameter configurable but default to previous behavior to not change anything for existing tests.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.