From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amos Kong Subject: [PATCH v2 03/17] KVM Test: Add a function get_interface_name() to kvm_test_utils.py Date: Mon, 23 Aug 2010 16:52:11 +0800 Message-ID: <20100823085211.19173.1588.stgit@190> References: <20100823084745.19173.61655.stgit@190> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: lmr@redhat.com, kvm@vger.kernel.org To: autotest@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:19205 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751772Ab0HWItP (ORCPT ); Mon, 23 Aug 2010 04:49:15 -0400 In-Reply-To: <20100823084745.19173.61655.stgit@190> Sender: kvm-owner@vger.kernel.org List-ID: The function get_interface_name is used to get the interface name of linux guest through the macaddress of specified macaddress. Signed-off-by: Jason Wang Signed-off-by: Amos Kong --- 0 files changed, 0 insertions(+), 0 deletions(-) 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