From patchwork Tue May 24 07:08:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 811052 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4O78Dfk011241 for ; Tue, 24 May 2011 07:08:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753781Ab1EXHIK (ORCPT ); Tue, 24 May 2011 03:08:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49198 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752341Ab1EXHIH (ORCPT ); Tue, 24 May 2011 03:08:07 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4O787JR022798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 May 2011 03:08:07 -0400 Received: from freedom.redhat.com (vpn-9-252.rdu.redhat.com [10.11.9.252]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4O783xT021922; Tue, 24 May 2011 03:08:05 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues , Jiri Zupka Subject: [PATCH 1/4] client.bin.net.net_utils: Introduce get_local_ip() Date: Tue, 24 May 2011 04:08:08 -0300 Message-Id: <1306220891-3993-2-git-send-email-lmr@redhat.com> In-Reply-To: <1306220891-3993-1-git-send-email-lmr@redhat.com> References: <1306220891-3993-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 24 May 2011 07:08:14 +0000 (UTC) Get ip address in local system which can communicate with a given ip, that will be useful for subtests like netperf2. Signed-off-by: Jiri Zupka --- client/bin/net/net_utils.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/client/bin/net/net_utils.py b/client/bin/net/net_utils.py index 868958c..7c96ba0 100644 --- a/client/bin/net/net_utils.py +++ b/client/bin/net/net_utils.py @@ -5,6 +5,7 @@ This library is to release in the public repository. import commands, os, re, socket, sys, time, struct from autotest_lib.client.common_lib import error +from autotest_lib.client.bin import utils as client_utils import utils TIMEOUT = 10 # Used for socket timeout and barrier timeout @@ -27,6 +28,22 @@ class network_utils(object): utils.system('/sbin/ifconfig -a') + def get_ip_local(self, query_ip, netmask="24"): + """ + Get ip address in local system which can communicate with query_ip. + + @param query_ip: IP of client which wants to communicate with + autotest machine. + @return: IP address which can communicate with query_ip + """ + ip = client_utils.system_output("ip addr show to %s/%s" % + (query_ip, netmask)) + ip = re.search(r"inet ([0-9.]*)/",ip) + if ip is None: + return ip + return ip.group(1) + + def disable_ip_local_loopback(self, ignore_status=False): utils.system("echo '1' > /proc/sys/net/ipv4/route/no_local_loopback", ignore_status=ignore_status)