diff mbox

[v2,03/17] KVM Test: Add a function get_interface_name() to kvm_test_utils.py

Message ID 20100823085211.19173.1588.stgit@190 (mailing list archive)
State New, archived
Headers show

Commit Message

Amos Kong Aug. 23, 2010, 8:52 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index 53c11ae..8cd7acd 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -481,3 +481,20 @@  def run_autotest(vm, session, control_path, timeout, outputdir):
             e_msg = ("Tests %s failed during control file execution" %
                      " ".join(bad_results))
         raise error.TestFail(e_msg)
+
+
+def get_linux_ifname(session, mac_address):
+    """
+    Return the interface name through the mac address.
+
+    @param session: session to the virtual machine
+    @mac_address: the macaddress of nic
+    """
+    output = session.get_command_output("ifconfig -a")
+
+    try:
+        ethname = re.findall("(\w+)\s+Link.*%s" % mac_address, output,
+                             re.IGNORECASE)[0]
+        return ethname
+    except:
+        return None