Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions virttest/utils_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,10 +1718,13 @@ def get_dhcp_client(session):
:return: tuple of dhcp command and its release argument, raises TestError if none found
"""
dhcp_clients = [("dhclient", "-r"), ("dhcpcd", "-k")]
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]]
Comment on lines +1722 to +1727
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]]

for cmd, release_flag in dhcp_clients:
status, _ = utils_misc.cmd_status_output(
"which %s" % cmd, shell=True, ignore_status=True, session=session
Expand Down
Loading