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

Change-Id: I3b2ed69997886b1433409b4c6b8b3d252fcd9fda
diff --git a/src/test/acl/aclTest.py b/src/test/acl/aclTest.py
index 79de329..c0c88fe 100644
--- a/src/test/acl/aclTest.py
+++ b/src/test/acl/aclTest.py
@@ -16,7 +16,7 @@
 import unittest
 from nose.tools import *
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from OnosFlowCtrl import OnosFlowCtrl
 from onosclidriver import OnosCliDriver
@@ -42,7 +42,7 @@
     ingress_iface = 1
     egress_iface = 2
     MAX_PORTS = 100
-    CURRENT_PORT_NUM = egress_iface 
+    CURRENT_PORT_NUM = egress_iface
     ACL_SRC_IP = '192.168.20.3/32'
     ACL_DST_IP = '192.168.30.2/32'
     ACL_SRC_IP_RULE_2 = '192.168.40.3/32'
@@ -79,7 +79,7 @@
     def tearDown(self):
         '''Deactivate the acl app'''
         log.info('Tear down setup')
-        self.CURRENT_PORT_NUM = 4 
+        self.CURRENT_PORT_NUM = 4
 
     def cliEnter(self):
         retries = 0
@@ -115,12 +115,12 @@
                break
             egress_iface_count += 1
             egress_iface_num += 1
-            
+
 
     @classmethod
     def acl_hosts_remove(cls, egress_iface_count = 1,  egress_iface_num = None):
         if egress_iface_num is None:
-           egress_iface_num = cls.egress_iface  
+           egress_iface_num = cls.egress_iface
         n = 0
         for n in range(egress_iface_count):
            egress = cls.port_map[egress_iface_num]
@@ -246,7 +246,7 @@
         if status is False:
             log.info('JSON request returned status %d' %code)
             assert_equal(status, True)
-        
+
     def test_acl_remove_all_rules_without_add(self):
         status, _ = ACLTest.remove_acl_rule()
         if status is False:
@@ -272,7 +272,7 @@
         if status is False:
             log.info('JSON request returned status %d' %code)
             assert_equal(status, True)
-        
+
     def test_acl_allow_rules_for_matched_dst_ips(self):
         acl_rule = ACLTest()
         status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp ='192.168.30.2/24', action = 'allow')
@@ -1152,6 +1152,3 @@
         self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 987, positive_test = False)
         self.cliExit()
         self.acl_hosts_remove(egress_iface_count = 2,  egress_iface_num = egress-1)
-
-
-
diff --git a/src/test/cluster/clusterTest.py b/src/test/cluster/clusterTest.py
index 88a9915..ab919a0 100644
--- a/src/test/cluster/clusterTest.py
+++ b/src/test/cluster/clusterTest.py
@@ -15,9 +15,9 @@
 import unittest
 from nose.tools import *
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
-from socket import socket
+from CordTestUtils import get_mac, get_controller, get_controllers
 from OnosFlowCtrl import OnosFlowCtrl
 from nose.twistedtools import reactor, deferred
 from twisted.internet import defer
@@ -75,16 +75,6 @@
         if self._testMethodName not in self.testcaseLoggers:
             super(cluster_exchange, self).tearDown()
 
-    def get_controller(self):
-        controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
-        controller = controller.split(',')[0]
-        return controller
-
-    @classmethod
-    def get_controllers(cls):
-        controllers = os.getenv('ONOS_CONTROLLER_IP') or ''
-        return controllers.split(',')
-
     def cliEnter(self, controller = None):
         retries = 0
         while retries < 30:
@@ -130,7 +120,7 @@
     def get_leaders(self, controller = None):
         result_map = {}
         if controller is None:
-            controller = self.get_controller()
+            controller = get_controller()
         if type(controller) in [ list, tuple ]:
             for c in controller:
                 leaders = self.get_leader(controller = c)
@@ -202,7 +192,7 @@
 
     def get_cluster_container_names_ips(self,controller=None):
         onos_names_ips = {}
-        controllers = self.get_controllers()
+        controllers = get_controllers()
         i = 0
         for controller in controllers:
             if i == 0:
@@ -347,7 +337,7 @@
 	return True
 
     def cluster_controller_restarts(self, graceful = False):
-        controllers = self.get_controllers()
+        controllers = get_controllers()
         ctlr_len = len(controllers)
         if ctlr_len <= 1:
             log.info('ONOS is not running in cluster mode. This test only works for cluster mode')
@@ -446,7 +436,7 @@
 
     def test_cluster_single_controller_restarts(self):
         '''Test the cluster by repeatedly restarting the same controller'''
-        controllers = self.get_controllers()
+        controllers = get_controllers()
         ctlr_len = len(controllers)
         if ctlr_len <= 1:
             log.info('ONOS is not running in cluster mode. This test only works for cluster mode')
@@ -529,7 +519,7 @@
 
     def test_cluster_restarts(self):
         '''Test the cluster by repeatedly restarting the entire cluster'''
-        controllers = self.get_controllers()
+        controllers = get_controllers()
         ctlr_len = len(controllers)
         if ctlr_len <= 1:
             log.info('ONOS is not running in cluster mode. This test only works for cluster mode')
diff --git a/src/test/cordvtn/cordvtnTest.py b/src/test/cordvtn/cordvtnTest.py
index b20d9a1..1c5cf13 100644
--- a/src/test/cordvtn/cordvtnTest.py
+++ b/src/test/cordvtn/cordvtnTest.py
@@ -24,7 +24,8 @@
 from neutronclient.v2_0 import client as neutron_client
 import neutronclient.v2_0.client as neutronclient
 from nose.tools import assert_equal
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac
+from OnosCtrl import OnosCtrl
 from CordLogger import CordLogger
 from TestManifest import TestManifest
 from OnosFlowCtrl import OnosFlowCtrl
diff --git a/src/test/dhcprelay/dhcprelayTest.py b/src/test/dhcprelay/dhcprelayTest.py
index 5d00ccf..2cfb4be 100644
--- a/src/test/dhcprelay/dhcprelayTest.py
+++ b/src/test/dhcprelay/dhcprelayTest.py
@@ -21,7 +21,8 @@
 import time
 import os, sys
 from DHCP import DHCPTest
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from CordTestServer import cord_test_onos_restart
 from CordLogger import CordLogger
@@ -1386,7 +1387,3 @@
 	   log.info('Got dhcp client IP %s from server %s for mac %s.Which is not expected behavior as IP %s is already consumed.'
 		    %(new_cip, new_sip, new_mac, new_cip) )
 	   assert_equal(new_cip, None)
-
-
-
-
diff --git a/src/test/ipv6vrouter/ipv6vrouterTest.py b/src/test/ipv6vrouter/ipv6vrouterTest.py
index 5ac7291..00a7944 100644
--- a/src/test/ipv6vrouter/ipv6vrouterTest.py
+++ b/src/test/ipv6vrouter/ipv6vrouterTest.py
@@ -16,7 +16,8 @@
 import unittest
 from nose.tools import *
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from OnosFlowCtrl import OnosFlowCtrl
 from onosclidriver import OnosCliDriver
@@ -773,4 +774,3 @@
         time.sleep(60)
         self.vrouter_traffic_verify(positive_test = True)
         assert_equal(res, True)
-
diff --git a/src/test/proxyarp/proxyarpTest.py b/src/test/proxyarp/proxyarpTest.py
index 594fabc..836cb3b 100644
--- a/src/test/proxyarp/proxyarpTest.py
+++ b/src/test/proxyarp/proxyarpTest.py
@@ -16,7 +16,8 @@
 import unittest
 from nose.tools import *
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from OnosFlowCtrl import OnosFlowCtrl
 from onosclidriver import OnosCliDriver
diff --git a/src/test/setup/cord-test.py b/src/test/setup/cord-test.py
index d751124..ac66858 100755
--- a/src/test/setup/cord-test.py
+++ b/src/test/setup/cord-test.py
@@ -22,7 +22,8 @@
 sys.path.append(utils_dir)
 sys.path.append(cli_dir)
 sys.path.insert(1, '/usr/local/lib/python2.7/dist-packages')
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from OnosFlowCtrl import OnosFlowCtrl
 from threadPool import ThreadPool
diff --git a/src/test/setup/radius-config/freeradius/clients.conf b/src/test/setup/radius-config/freeradius/clients.conf
index 1786abe..c03f512 100644
--- a/src/test/setup/radius-config/freeradius/clients.conf
+++ b/src/test/setup/radius-config/freeradius/clients.conf
@@ -1374,6 +1374,34 @@
 	ipv6addr = ::
 	secret = radius_password
 }
+client 0.0.0.0/0{
+	secret = radius_password
+}
+client ipv6{
+	ipv6addr = ::
+	secret = radius_password
+}
+client 0.0.0.0/0{
+	secret = radius_password
+}
+client ipv6{
+	ipv6addr = ::
+	secret = radius_password
+}
+client 0.0.0.0/0{
+	secret = radius_password
+}
+client ipv6{
+	ipv6addr = ::
+	secret = radius_password
+}
+client 0.0.0.0/0{
+	secret = radius_password
+}
+client ipv6{
+	ipv6addr = ::
+	secret = radius_password
+}
 client localhost {
 	#  Allowed values are:
 	#	dotted quad (1.2.3.4)
diff --git a/src/test/setup/radius-config/freeradius/mods-available/sql b/src/test/setup/radius-config/freeradius/mods-available/sql
index 93e85c1..eea2245 100644
--- a/src/test/setup/radius-config/freeradius/mods-available/sql
+++ b/src/test/setup/radius-config/freeradius/mods-available/sql
@@ -825,6 +825,22 @@
 	sqlite {
 		filename = "/opt/db/radius.sqlite3"
 	}
+ 
+	sqlite {
+		filename = "/opt/db/radius.sqlite3"
+	}
+ 
+	sqlite {
+		filename = "/opt/db/radius.sqlite3"
+	}
+ 
+	sqlite {
+		filename = "/opt/db/radius.sqlite3"
+	}
+ 
+	sqlite {
+		filename = "/opt/db/radius.sqlite3"
+	}
 
 #
 #	Several drivers accept specific options, to set them, a
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:
 
diff --git a/src/test/vrouter/vrouterTest.py b/src/test/vrouter/vrouterTest.py
index 97df637..dc1f281 100644
--- a/src/test/vrouter/vrouterTest.py
+++ b/src/test/vrouter/vrouterTest.py
@@ -16,7 +16,8 @@
 import unittest
 from nose.tools import *
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from OnosFlowCtrl import OnosFlowCtrl
 from onosclidriver import OnosCliDriver
diff --git a/src/test/vsg/vsgTest.py b/src/test/vsg/vsgTest.py
index c284b12..7fc720e 100644
--- a/src/test/vsg/vsgTest.py
+++ b/src/test/vsg/vsgTest.py
@@ -15,7 +15,8 @@
 import unittest
 from nose.tools import *
 from scapy.all import *
-from OnosCtrl import OnosCtrl, get_mac
+from CordTestUtils import get_mac, get_controllers
+from OnosCtrl import OnosCtrl
 from OltConfig import OltConfig
 from socket import socket
 from OnosFlowCtrl import OnosFlowCtrl
@@ -53,18 +54,13 @@
 
     def setUp(self):
         super(vsg_exchange, self).setUp()
-        self.controllers = self.get_controllers()
+        self.controllers = get_controllers()
         self.controller = self.controllers[0]
         self.cli = None
 
     def tearDown(self):
         super(vsg_exchange, self).tearDown()
 
-    @classmethod
-    def get_controllers(cls):
-        controllers = os.getenv('ONOS_CONTROLLER_IP') or ''
-        return controllers.split(',')
-
     def cliEnter(self, controller = None):
         retries = 0
         while retries < 30: