Skip to content

utils_net: fix dhcp client selection logic and restart_cmd assignment#4320

Open
quanwenli wants to merge 1 commit intoavocado-framework:masterfrom
quanwenli:fix
Open

utils_net: fix dhcp client selection logic and restart_cmd assignment#4320
quanwenli wants to merge 1 commit intoavocado-framework:masterfrom
quanwenli:fix

Conversation

@quanwenli
Copy link
Copy Markdown
Contributor

@quanwenli quanwenli commented Feb 11, 2026

  1. fix RHEL >= 10 dhcp logic wrongly applied to guest, limit it to host side only. introduced by 4309
  2. fix restart_cmd assignment, introduced by 4317

ID: LIBVIRTAT-22313, LIBVIRTAT-22314

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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

  • DHCP Client Selection Logic: The logic for selecting the DHCP client (dhclient vs. dhcpcd) on RHEL 10+ systems has been refined. Previously, this specific logic was applied universally, potentially affecting guest VMs. Now, it is correctly scoped to apply only when operating on the host system (when session is None), preventing incorrect client selection within guests.
  • Restart Command Assignment: An issue where the restart_cmd variable was incorrectly appended to using += instead of being assigned using = has been resolved. This fix ensures that the command string is correctly initialized or overwritten, preventing malformed network restart commands.
Changelog
  • virttest/utils_net.py
    • Modified the get_dhcp_client function to restrict RHEL 10+ specific DHCP client selection to host-side operations by checking if session is None.
    • Corrected the assignment of restart_cmd in the restart_guest_network function from an additive assignment (+=) to a direct assignment (=) to prevent command string concatenation errors.
Activity
  • No human activity has been recorded on this pull request since its creation.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread virttest/utils_net.py
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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 +=.

Suggested change
restart_cmd = "%s %s; " % (dhcp_cmd, release_flag)
restart_cmd += "%s %s; " % (dhcp_cmd, release_flag)

Comment thread virttest/utils_net.py
Comment on lines +1722 to +1726
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]]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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]]

@quanwenli
Copy link
Copy Markdown
Contributor Author

@smitterl @nanli1 could you help review this. thanks a lot.

@quanwenli
Copy link
Copy Markdown
Contributor Author

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
(1/1) type_specific.io-github-autotest-libvirt.virtual_network.qemu_test.performance.netperf.bridge_test.host_guest.throughput: PASS (229.38 s)
RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML : /root/avocado/job-results/job-2026-02-10T21.03-f38563b/results.html

(1/1) type_specific.io-github-autotest-libvirt.virtual_network.qemu_test.performance.netperf.bridge_test.host_guest.throughput: STARTED
(1/1) type_specific.io-github-autotest-libvirt.virtual_network.qemu_test.performance.netperf.bridge_test.host_guest.throughput: PASS (230.92 s)
RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB HTML : /root/avocado/job-results/job-2026-02-10T21.08-35a8bc2/results.html

@quanwenli
Copy link
Copy Markdown
Contributor Author

@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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant