Database functionality added and minor refactoring
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.params b/TestON/tests/IntentPerfNext/IntentPerfNext.params
index 88f2bc7..7b3f876 100644
--- a/TestON/tests/IntentPerfNext/IntentPerfNext.params
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.params
@@ -47,6 +47,12 @@
         <intfs>s3-eth2</intfs>
     </TEST>
 
+    <DB>
+        <intentFilePath>
+        /home/admin/ONLabTest/TestON/tests/IntentPerfNext/intentInstallPathDb.log
+        </intentFilePath>
+    </DB>
+
     <JSON>
         <submittedTime>intentSubmittedTimestamp</submittedTime>
         <installedTime>intentInstalledTimestamp</installedTime>
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.py b/TestON/tests/IntentPerfNext/IntentPerfNext.py
index 345ddb2..422f1c9 100644
--- a/TestON/tests/IntentPerfNext/IntentPerfNext.py
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.py
@@ -16,12 +16,18 @@
         """
         import time
         global clusterCount
+        global timeToPost
+        global runNum
+
         clusterCount = 1
+        timeToPost = time.strftime("%Y-%m-%d %H:%M:%S")
+        runNum = time.strftime("%d%H%M%S")
 
         cellName = main.params[ 'ENV' ][ 'cellName' ]
 
         gitPull = main.params[ 'GIT' ][ 'autoPull' ]
         checkoutBranch = main.params[ 'GIT' ][ 'checkout' ]
+        intentFilePath = main.params[ 'DB' ][ 'intentFilePath' ]
 
         ONOSIp = []
         for i in range(1, 8):
@@ -33,6 +39,12 @@
 
         main.case( "Setting up test environment" )
 
+        main.step( "Clearing previous DB log file" )
+        fIntentLog = open(intentFilePath, 'w')
+        # Overwrite with empty line and close 
+        fIntentLog.write('')
+        fIntentLog.close()
+
         main.step( "Starting mininet topology" )
         main.Mininet1.startNet()
 
@@ -553,6 +565,7 @@
         import os
         import numpy
         global clusterCount
+        global timeToPost
 
         ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
         ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
@@ -584,8 +597,7 @@
         #nThread = 105
 
         # DB operation variables
-        intentInstallPath = main.params[ 'DB' ][ 'intentInstallPath' ]
-
+        intentFilePath = main.params[ 'DB' ][ 'intentFilePath' ]
 
         # Switch assignment NOTE: hardcoded
         if clusterCount == 1:
@@ -664,6 +676,7 @@
         for device in jsonObj:
             deviceIdList.append( device[ 'id' ] )
 
+        # List of install / witdhraw latencies for each batch
         batchInstallLat = []
         batchWithdrawLat = []
 
@@ -749,6 +762,8 @@
                                    str( batchIntentSize ) + "intents: " +
                                    str( withdrawResult ) + " ms" )
 
+                #NOTE: END node loop
+
                 if len( batchInstallLat ) > 0 and int( i ) > numIgnore:
                     maxInstallLat.append( max( batchInstallLat ) )
                 elif len( batchInstallLat ) == 0:
@@ -763,13 +778,18 @@
                 # Sleep in between iterations
                 time.sleep( 5 )
 
+            #NOTE: END iteration loop
+
             if maxInstallLat:
                 avgInstallLat = str( round(
                                             sum( maxInstallLat ) /
                                             len( maxInstallLat )
                                           , 2 ))
+                stdInstallLat = str( round(
+                                    numpy.std(maxInstallLat), 2))
             else:
                 avgInstallLat = "NA"
+                stdInstallLat = "NA"
                 main.log.report( "Batch installation failed" )
                 assertion = main.FALSE
 
@@ -778,8 +798,11 @@
                                             sum( maxWithdrawLat ) /
                                             len( maxWithdrawLat )
                                             , 2 ))
+                stdWithdrawLat = str( round(
+                                    numpy.std(maxWithdrawLat), 2))
             else:
                 avgWithdrawLat = "NA"
+                stdWithdrawLat = "NA"
                 main.log.report( "Batch withdraw failed" )
                 assertion = main.FALSE
 
@@ -788,16 +811,28 @@
                              str( avgInstallLat ) + " ms" )
             main.log.report( "Std Deviation of batch installation latency " +
                              ": " +
-                             str( round(numpy.std( maxInstallLat ),2)) +
-                             " ms" )
+                             str( stdInstallLat ) + " ms" )
 
             main.log.report( "Avg of batch withdraw latency " +
                              "of size " + str( batchIntentSize ) + ": " +
                              str( avgWithdrawLat ) + " ms" )
             main.log.report( "Std Deviation of batch withdraw latency " +
                              ": " +
-                             str( round(numpy.std( maxWithdrawLat ),2)) +
-                             " ms" )
+                             str( stdWithdrawLat ) + " ms" )
+
+            dbCmd = (
+                "INSERT INTO intent_latency_tests VALUES("
+                "'"+timeToPost+"','intent_latency_results',"
+                ""+runNum+","+str(clusterCount)+","+str(batchIntentSize)+","
+                ""+str(avgInstallLat)+","+str(stdInstallLat)+","
+                ""+str(avgWithdrawLat)+","+str(stdWithdrawLat)+");"
+            )
+
+            # Write result to file (which is posted to DB by jenkins)
+            fResult = open(intentFilePath, 'a')
+            if dbCmd:        
+                fResult.write(dbCmd+"\n")
+            fResult.close()
 
             if batch == 0:
                 batchIntentSize = 10
@@ -811,6 +846,8 @@
                 main.log.report( "Increasing batch intent size to " +
                              str(batchIntentSize) )
 
+        #NOTE: END batch loop
+
         #main.log.info( "Removing all intents for next test case" )
         #jsonTemp = main.ONOS1cli.intents( jsonFormat=True )
         #jsonObjIntents = json.loads( jsonTemp )
diff --git a/TestON/tests/IntentPerfNext/IntentPerfNext.topo b/TestON/tests/IntentPerfNext/IntentPerfNext.topo
index 9de0291..5575237 100644
--- a/TestON/tests/IntentPerfNext/IntentPerfNext.topo
+++ b/TestON/tests/IntentPerfNext/IntentPerfNext.topo
@@ -24,7 +24,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
+            <connect_order>3</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS2cli>
         
@@ -33,7 +33,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
+            <connect_order>4</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS3cli>
         
@@ -42,7 +42,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
+            <connect_order>5</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS4cli>
         
@@ -51,7 +51,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
+            <connect_order>6</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS5cli>
         
@@ -60,7 +60,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
+            <connect_order>7</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS6cli>
         
@@ -69,7 +69,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosCliDriver</type>
-            <connect_order>2</connect_order>
+            <connect_order>8</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS7cli>
 
@@ -78,7 +78,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>OnosDriver</type>
-            <connect_order>3</connect_order>
+            <connect_order>9</connect_order>
             <COMPONENTS> </COMPONENTS>
         </ONOS1>
 
@@ -87,7 +87,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>MininetCliDriver</type>
-            <connect_order>4</connect_order>
+            <connect_order>10</connect_order>
             <COMPONENTS>
                 <arg1> --custom topo-intent-8sw.py </arg1>
                 <arg2> --arp --mac --topo mytopo </arg2>
@@ -101,7 +101,7 @@
             <user>admin</user>
             <password>onos_test</password>
             <type>RemoteMininetDriver</type>
-            <connect_order>5</connect_order>
+            <connect_order>11</connect_order>
             <COMPONENTS> </COMPONENTS>
         </Mininet2>