[PATCH v2 03/11] Utils: Moved get_corespond_local_ip() to NetUtils

rpazdera at redhat.com rpazdera at redhat.com
Mon Aug 13 10:01:44 UTC 2012


From: Radek Pazdera <rpazdera at redhat.com>

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 at 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 at 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 at 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
-- 
1.7.7.6



More information about the LNST-developers mailing list