Skip to content

Commit

Permalink
utils_net: also check ip for host up nic
Browse files Browse the repository at this point in the history
When create linux bridge or macvtap for guest interface to use,
there maybe many UP state host nic, but only the ones with ip can
work.

Signed-off-by: Yanqiu Zhang <[email protected]>
  • Loading branch information
yanqzhan committed Aug 28, 2024
1 parent 3ff9f2d commit 745fd8d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion virttest/utils_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,11 +1439,24 @@ def get_net_if(runner=local_runner, state=".*", qdisc=".*", optional=".*"):
# As the runner converts stdout to unicode on Python2,
# it has to be converted to string for struct.pack().
result = str(runner(cmd))
return re.findall(
ifaces_up = re.findall(
r"^\d+: (\S+?)[@:].*%s.*%s.*state %s.*$" % (optional, qdisc, state),
result,
re.MULTILINE,
)
LOG.debug("The ifaces up on host: %s" % ifaces_up)
ifaces_with_ip = []
for iface in ifaces_up:
cmd = "ip -c=never addr show %s" % iface
ret = runner(cmd)
ipv4_addr = re.findall("inet (.+?)/..?", ret, re.MULTILINE)
if ipv4_addr:
ifaces_with_ip.append(iface)
LOG.debug("The ifaces up with ip on host: %s" % ifaces_with_ip)
if not ifaces_with_ip:
LOG.error("No up ifaces with ip on host!")
else:
return ifaces_with_ip


def get_sorted_net_if():
Expand Down

0 comments on commit 745fd8d

Please sign in to comment.