Try to use ip link in case ifconfig didn't work. Looking
on /sys would be the last resource.

Signed-off-by: Mike Qiu <[email protected]>
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 virttest/utils_test.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/virttest/utils_test.py b/virttest/utils_test.py
index 11b014d..0107252 100644
--- a/virttest/utils_test.py
+++ b/virttest/utils_test.py
@@ -1869,6 +1869,13 @@ def get_linux_ifname(session, mac_address):
         except IndexError:
             return None
 
+    def iplink_method():
+        try:
+            output = session.cmd("ip link | grep -B1 '%s' -i" % mac_address)
+            return re.findall("\d+:\s+(\w+):\s+.*", output, re.IGNORECASE)[0]
+        except (aexpect.ShellCmdError, IndexError):
+            return None
+
     def sys_method():
         try:
             interfaces = session.cmd('ls --color=never /sys/class/net')
@@ -1897,7 +1904,12 @@ def get_linux_ifname(session, mac_address):
     if i is not None:
         return i
 
-    # Then, look on /sys
+    # No luck, try ip link
+    i = iplink_method()
+    if i is not None:
+        return i
+
+    # No luck, look on /sys
     i = sys_method()
     if i is not None:
         return i
-- 
1.8.1.4

_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel

Reply via email to