More shuffle, cleanup, reorg ...
Utility functions in CordTestUtils instead of OnosCtrl

Change-Id: I3b2ed69997886b1433409b4c6b8b3d252fcd9fda
diff --git a/src/test/utils/ACL.py b/src/test/utils/ACL.py
index 55333c4..b246de1 100644
--- a/src/test/utils/ACL.py
+++ b/src/test/utils/ACL.py
@@ -17,7 +17,8 @@
 import requests
 import os,sys,time
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac, get_controller
+from CordTestUtils import get_mac, get_controller
+from OnosCtrl import OnosCtrl
 from OnosFlowCtrl import OnosFlowCtrl
 log.setLevel('INFO')
 
@@ -137,4 +138,3 @@
         json_data = json.dumps(ports_dict)
         resp = requests.post(self.iface_create_onos_url, auth = self.auth, data = json_data)
         return resp.ok, resp.status_code, egress_host_list
-
diff --git a/src/test/utils/Cluster.py b/src/test/utils/Cluster.py
index b55d4e2..c42ea64 100644
--- a/src/test/utils/Cluster.py
+++ b/src/test/utils/Cluster.py
@@ -7,8 +7,9 @@
 from Channels import Channels, IgmpChannel
 from subscriberDb import SubscriberDB
 import time, monotonic
+from CordTestUtils import get_mac
 from OltConfig import OltConfig
-from OnosCtrl import OnosCtrl, get_mac
+from OnosCtrl import OnosCtrl
 from OnosFlowCtrl import OnosFlowCtrl
 from CordContainer import Container, Onos, Quagga
 from onosclidriver import OnosCliDriver
diff --git a/src/test/utils/CordLogger.py b/src/test/utils/CordLogger.py
index 54d8b11..e58e4ff 100644
--- a/src/test/utils/CordLogger.py
+++ b/src/test/utils/CordLogger.py
@@ -1,7 +1,7 @@
 from OnosLog import OnosLog
 from scapy.all import log
 from onosclidriver import OnosCliDriver
-from OnosCtrl import OnosCtrl, get_mac
+from OnosCtrl import OnosCtrl
 from docker import Client
 from CordContainer import *
 import json
diff --git a/src/test/utils/CordTestUtils.py b/src/test/utils/CordTestUtils.py
new file mode 100644
index 0000000..6abd356
--- /dev/null
+++ b/src/test/utils/CordTestUtils.py
@@ -0,0 +1,45 @@
+import subprocess
+import socket
+import fcntl
+import struct
+import os
+
+# we use subprocess as commands.getstatusoutput would be deprecated
+def getstatusoutput(cmd):
+    command = [ '/bin/sh', '-c', cmd ]
+    p = subprocess.Popen(command, stdout = subprocess.PIPE)
+    out, _ = p.communicate()
+    return p.returncode, out.strip()
+
+def get_ip(iface):
+    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    try:
+        info = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', bytes(iface[:15])))
+    except:
+        info = None
+    s.close()
+    if info:
+        return '.'.join( [ str(ord(c)) for c in info[20:24] ] )
+    return None
+
+def get_mac(iface = None, pad = 4):
+    if iface is None:
+        iface = os.getenv('TEST_SWITCH', 'ovsbr0')
+    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    try:
+        info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(iface[:15])))
+    except:
+        info = ['0'] * 24
+    s.close()
+    sep = ''
+    if pad == 0:
+        sep = ':'
+    return '0'*pad + sep.join(['%02x' %ord(char) for char in info[18:24]])
+
+def get_controllers():
+    controllers = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
+    return controllers.split(',')
+
+def get_controller():
+    controllers = get_controllers()
+    return controllers[0]
diff --git a/src/test/utils/OnosCtrl.py b/src/test/utils/OnosCtrl.py
index 205a31e..07cff87 100644
--- a/src/test/utils/OnosCtrl.py
+++ b/src/test/utils/OnosCtrl.py
@@ -17,26 +17,7 @@
 import requests
 import os,sys,time
 from OltConfig import OltConfig
-import fcntl, socket, struct
-
-def get_mac(iface = None, pad = 4):
-    if iface is None:
-        iface = os.getenv('TEST_SWITCH', 'ovsbr0')
-    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-    try:
-        info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', bytes(iface[:15])))
-    except:
-        info = ['0'] * 24
-    s.close()
-    sep = ''
-    if pad == 0:
-        sep = ':'
-    return '0'*pad + sep.join(['%02x' %ord(char) for char in info[18:24]])
-
-def get_controller():
-    controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
-    controller = controller.split(',')[0]
-    return controller
+from CordTestUtils import get_mac, get_controller
 
 class OnosCtrl: