Skip to content

Commit 1369bfe

Browse files
authored
Merge pull request #4317 from smitterl/fix_utils_net
utils_net: improve dhcpcd support
2 parents db0410e + 48161b9 commit 1369bfe

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

virttest/utils_net.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,24 @@ def get_guest_nameserver(session):
16921692
return output
16931693

16941694

1695+
def _deactivate_ipv4ll_dhcpcd(session):
1696+
"""
1697+
The command is more prone to requesting link local addresses, such as
1698+
169.254.200.199 and the guest ends up with two ipv4 addresses.
1699+
As this can lead to ipv4 discovery issues in this module and is
1700+
different from the previous behavior when using dhclient, deactivate it.
1701+
1702+
:param session: guest console session
1703+
"""
1704+
cmd = "grep -qxF 'noipv4ll' /etc/dhcpcd.conf "
1705+
cmd += "|| echo 'noipv4ll' >> /etc/dhcpcd.conf"
1706+
status, _ = utils_misc.cmd_status_output(
1707+
cmd, shell=True, ignore_status=True, session=session
1708+
)
1709+
if status:
1710+
raise exceptions.TestError("Couldn't deactivate IPv4 local link setting.")
1711+
1712+
16951713
def get_dhcp_client(session):
16961714
"""
16971715
Return the available dhcp client command and its release argument.
@@ -1709,6 +1727,8 @@ def get_dhcp_client(session):
17091727
"which %s" % cmd, shell=True, ignore_status=True, session=session
17101728
)
17111729
if status == 0:
1730+
if cmd == "dhcpcd":
1731+
_deactivate_ipv4ll_dhcpcd(session)
17121732
return cmd, release_flag
17131733

17141734
raise exceptions.TestError("No dhcp client found on the system")
@@ -1732,13 +1752,13 @@ def restart_guest_network(
17321752
if mac_addr:
17331753
nic_ifname = get_linux_ifname(session, mac_addr)
17341754
restart_cmd = "ifconfig %s up; " % nic_ifname
1735-
restart_cmd += "%s; " % release_flag
1755+
restart_cmd += "%s %s; " % (dhcp_cmd, release_flag)
17361756
if ip_version == "ipv6":
17371757
restart_cmd += "%s -6 %s" % (dhcp_cmd, nic_ifname)
17381758
else:
17391759
restart_cmd += "%s %s" % (dhcp_cmd, nic_ifname)
17401760
else:
1741-
restart_cmd = "%s; " % release_flag
1761+
restart_cmd += "%s %s; " % (dhcp_cmd, release_flag)
17421762
if ip_version == "ipv6":
17431763
restart_cmd += "%s -6" % dhcp_cmd
17441764
else:

0 commit comments

Comments
 (0)