Skip to content

Commit

Permalink
Merge pull request avocado-framework#3536 from yanglei-rh/bug2133384
Browse files Browse the repository at this point in the history
utils_net.get_ip_address_by_interface:fix a regression bug
  • Loading branch information
luckyh authored Jan 16, 2023
2 parents 8ae342f + 92e1d2d commit 751289d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions virttest/utils_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -3462,15 +3462,22 @@ def get_ip_address_by_interface(ifname, ip_ver="ipv4", linklocal=False):
:param ifname: interface name
:param ip_ver: Host IP version, ipv4 or ipv6.
:param linklocal: Whether ip address is local or remote
:raise NetError: When failed to fetch IP address (ioctl raised IOError.).
:raise NetError: When failed to fetch IP address.
"""
if ip_ver == "ipv6":
ver = netifaces.AF_INET6
linklocal_prefix = "fe80"
else:
ver = netifaces.AF_INET
linklocal_prefix = "169.254"
addr = netifaces.ifaddresses(ifname).get(ver)
try:
addr = netifaces.ifaddresses(ifname).get(ver)
# FIXME: The kind of exceptions caught should be more specific
except:
# TODO: NetError is a very general usage,it will be changed to a
# more friendly way in the future
raise NetError(
"Error while retrieving IP address from interface %s." % ifname)

if addr is not None:
try:
Expand Down

0 comments on commit 751289d

Please sign in to comment.