Skip to content

Commit 82d16e8

Browse files
committed
utils_net: disable color chars
The command might output ip address with color characters which will break the script, like below. Get ipv6 address of vm1: �[34m2620:52:11:1601:982f:7bff:fe94:1415�[0m This is to disable the color characters in the outputs. Signed-off-by: Dan Zheng <dzheng@redhat.com>
1 parent 27a366f commit 82d16e8

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

virttest/utils_net.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ def get_remote_host_net_ifs(session, state=None, ip_options=""):
15011501
return (phy_interfaces, vir_interfaces)
15021502

15031503

1504-
def get_net_if_addrs(if_name, runner=None):
1504+
def get_net_if_addrs(if_name, runner=None, ip_options=""):
15051505
"""
15061506
Get network device ip addresses. ioctl not used because it's not
15071507
compatible with ipv6 address.
@@ -1511,7 +1511,7 @@ def get_net_if_addrs(if_name, runner=None):
15111511
"""
15121512
if runner is None:
15131513
runner = local_runner
1514-
cmd = "ip addr show %s" % (if_name)
1514+
cmd = f"ip {ip_options} addr show {if_name}"
15151515
result = runner(cmd)
15161516
return {
15171517
"ipv4": re.findall("inet (.+?)/..?", result, re.MULTILINE),
@@ -1549,7 +1549,13 @@ def get_net_if_and_addrs(runner=None):
15491549

15501550

15511551
def get_guest_ip_addr(
1552-
session, mac_addr, os_type="linux", ip_version="ipv4", linklocal=False, timeout=1
1552+
session,
1553+
mac_addr,
1554+
os_type="linux",
1555+
ip_version="ipv4",
1556+
linklocal=False,
1557+
timeout=1,
1558+
ip_options="",
15531559
):
15541560
"""
15551561
Get guest ip addresses by serial session
@@ -1570,7 +1576,9 @@ def get_guest_ip_addr(
15701576
if os_type == "linux":
15711577
nic_ifname = get_linux_ifname(session, mac_addr)
15721578
info_cmd = "ifconfig -a; ethtool -S %s" % nic_ifname
1573-
nic_address = get_net_if_addrs(nic_ifname, session.cmd_output)
1579+
nic_address = get_net_if_addrs(
1580+
nic_ifname, session.cmd_output, ip_options=ip_options
1581+
)
15741582
elif os_type == "windows":
15751583
info_cmd = "ipconfig /all"
15761584
nic_address = get_net_if_addrs_win(session, mac_addr)

0 commit comments

Comments
 (0)