Currently, utils_test has two methods to get the ifname, for the sys_method, it has a bug when bonding module loaded, because the module create one file named bonding_masters, not a directory.
Thus, when run the command "cat /sys/class/net/bonding_masters/address" will get an error. To avoid this, iplink_method will get a better result, especially in Fedora17 guest while bonding module also loaded. Signed-off-by: Mike Qiu <[email protected]> --- virttest/utils_test.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/virttest/utils_test.py b/virttest/utils_test.py index b23634d..9f79527 100644 --- a/virttest/utils_test.py +++ b/virttest/utils_test.py @@ -1869,19 +1869,12 @@ def get_linux_ifname(session, mac_address): except IndexError: return None - def sys_method(): + def iplink_method(): try: - interfaces = session.cmd('ls --color=never /sys/class/net') - interfaces = interfaces.strip() - for interface in interfaces.split(" "): - if interface: - mac_address_interface = session.cmd("cat " - "/sys/class/net/%s/address" % interface) - mac_address_interface = mac_address_interface.strip() - if mac_address_interface == mac_address: - return interface - except error.CmdError, e: - logging.debug(e) + output = session.cmd_output("ip link | grep -B1 '%s' -i"%mac_address) + return re.findall("\d+:\s+(\w+):\s+.*", output, + re.IGNORECASE)[0] + except IndexError: return None # Try ifconfig first @@ -1889,8 +1882,8 @@ def get_linux_ifname(session, mac_address): if i is not None: return i - # Then, look on /sys - i = sys_method() + # Then, use ip link + i = iplink_method() if i is not None: return i -- 1.7.10.1 _______________________________________________ Virt-test-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/virt-test-devel
