utils_net: fix dhcp client selection logic and restart_cmd assignment#4320
utils_net: fix dhcp client selection logic and restart_cmd assignment#4320quanwenli wants to merge 1 commit intoavocado-framework:masterfrom
Conversation
Summary of ChangesHello @quanwenli, 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 addresses two key issues related to network utility functions. It refines the DHCP client selection mechanism to ensure RHEL 10+ specific logic is applied only in the appropriate host context, avoiding unintended behavior in guest environments. Additionally, it corrects an assignment error in the network restart command generation, ensuring proper command construction. Highlights
Changelog
Activity
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 addresses two issues in utils_net.py. First, it corrects the DHCP client selection logic for RHEL >= 10 to apply only to the host, not the guest. Second, it modifies the assignment of restart_cmd. My review includes a suggestion to improve the efficiency of the distro detection and points out a potential bug in the restart_cmd assignment change, which appears to be inconsistent with the function's design.
| restart_cmd += "%s %s" % (dhcp_cmd, nic_ifname) | ||
| else: | ||
| restart_cmd += "%s %s; " % (dhcp_cmd, release_flag) | ||
| restart_cmd = "%s %s; " % (dhcp_cmd, release_flag) |
There was a problem hiding this comment.
This change from += to = seems incorrect. The function parameter restart_cmd is documented as an "extra restart command", which implies it can be used as a prefix. All other branches in this function use += to append to restart_cmd. Changing this to = makes this branch inconsistent and will cause any passed restart_cmd to be ignored. Was this intended? If not, it should be reverted to +=.
| restart_cmd = "%s %s; " % (dhcp_cmd, release_flag) | |
| restart_cmd += "%s %s; " % (dhcp_cmd, release_flag) |
| if session is None: | ||
| if distro.detect().name == "rhel" and int(distro.detect().version) >= 10: | ||
| dhcp_clients = [dhcp_clients[1]] | ||
| else: | ||
| dhcp_clients = [dhcp_clients[0]] |
There was a problem hiding this comment.
For efficiency, it's better to call distro.detect() only once and store its result in a variable. This avoids potentially expensive duplicate calls to determine the OS distribution.
| if session is None: | |
| if distro.detect().name == "rhel" and int(distro.detect().version) >= 10: | |
| dhcp_clients = [dhcp_clients[1]] | |
| else: | |
| dhcp_clients = [dhcp_clients[0]] | |
| if session is None: | |
| distro_info = distro.detect() | |
| if distro_info.name == "rhel" and int(distro_info.version) >= 10: | |
| dhcp_clients = [dhcp_clients[1]] | |
| else: | |
| dhcp_clients = [dhcp_clients[0]] |
|
The tests passed both with rhel9 and rhel10 vm. JOB LOG : /root/avocado/job-results/job-2026-02-10T21.03-f38563b/job.log (1/1) type_specific.io-github-autotest-libvirt.virtual_network.qemu_test.performance.netperf.bridge_test.host_guest.throughput: STARTED |
|
@smitterl could you help review this ? thanks a lot. |
fix RHEL >= 10 dhcp logic wrongly applied to guest, limit it to host side only Signed-off-by: Wenli Quan <wquan@redhat.com>
ID: LIBVIRTAT-22313, LIBVIRTAT-22314