commit 5f3e82e813c9057a57fb895f1c46eb7a81227049 Author: Radek Pazdera rpazdera@redhat.com Date: Mon Aug 13 12:01:44 2012 +0200
Utils: Moved get_corespond_local_ip() to NetUtils
This commit moves get_corespond_local_ip function from the general utility module to the new network specific one.
Signed-off-by: Radek Pazdera rpazdera@redhat.com
Common/NetUtils.py | 20 ++++++++++++++++++++ Common/Utils.py | 20 ++------------------ NetTest/NetTestController.py | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) --- diff --git a/Common/NetUtils.py b/Common/NetUtils.py index 059ce6e..7e642b6 100644 --- a/Common/NetUtils.py +++ b/Common/NetUtils.py @@ -11,6 +11,26 @@ rpazdera@redhat.com (Radek Pazdera) """
import logging +import re +import socket +import subprocess
def normalize_hwaddr(hwaddr): return hwaddr.upper().rstrip("\n") + +def get_corespond_local_ip(query_ip): + """ + Get ip address in local system which can communicate with query_ip. + + @param query_ip: IP of client which want communicate with autotest machine. + @return: IP address which can communicate with query_ip + """ + query_ip = socket.gethostbyname(query_ip) + ip = subprocess.Popen("ip route get %s" % (query_ip), + shell=True, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + ip = ip.communicate()[0] + ip = re.search(r"src ([0-9.]*)",ip) + if ip is None: + return ip + return ip.group(1) diff --git a/Common/Utils.py b/Common/Utils.py index 8f39729..f6ba201 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -9,7 +9,8 @@ published by the Free Software Foundation; see COPYING for details. __autor__ = """ jzupka@redhat.com (Jiri Zupka) """ -import logging, time, subprocess, re, socket +import logging +import time
def die_when_parent_die(): try: @@ -51,20 +52,3 @@ def wait_for(func, timeout, first=0.0, step=1.0, text=None):
logging.debug("Timeout elapsed") return None - - -def get_corespond_local_ip(query_ip): - """ - Get ip address in local system which can communicate with quert_ip. - - @param query_ip: IP of client which want communicate with autotest machine. - @return: IP address which can communicate with query_ip - """ - query_ip = socket.gethostbyname(query_ip) - ip = subprocess.Popen("ip route get %s" % (query_ip), - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - ip = ip.communicate()[0] - ip = re.search(r"src ([0-9.]*)",ip) - if ip is None: - return ip - return ip.group(1) diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py index 8e23152..a997e37 100644 --- a/NetTest/NetTestController.py +++ b/NetTest/NetTestController.py @@ -20,7 +20,7 @@ from pprint import pprint, pformat from Common.XmlRpc import ServerProxy from NetTest.NetTestParse import NetTestParse from Common.SlaveUtils import prepare_client_session -from Common.Utils import get_corespond_local_ip +from Common.NetUtils import get_corespond_local_ip from NetTest.NetTestSlave import DefaultRPCPort from NetTest.NetTestCommand import NetTestCommand, str_command from Common.LoggingServer import LoggingServer
lnst-developers@lists.fedorahosted.org