[ONOS-7937] Trigger slack notifications when test pass percentage is lower than expected

Change-Id: I2cec4181e6b9b8d972956aacbeab1adfe61d707b
(cherry picked from commit c2e22b2e66838d80ffb4f72cdef69a028d7756c1)
diff --git a/TestON/core/logger.py b/TestON/core/logger.py
index 0fdc49a..263e95b 100644
--- a/TestON/core/logger.py
+++ b/TestON/core/logger.py
@@ -126,7 +126,7 @@
         main.resultFile = main.logdir + "/" + main.TEST + "Result.txt"
         main.alarmFileName = main.logdir + "/" + main.TEST + "Alarm.txt"
 
-        main.TOTAL_TC_SUCCESS = 0
+        main.TOTAL_TC_SUCCESS_PERCENT = 0
 
         # Add log-level - Report
         logging.addLevelName( 9, "REPORT" )
@@ -283,9 +283,9 @@
         main.ENDTIME = datetime.datetime.now()
         main.EXECTIME = main.ENDTIME - main.STARTTIME
         if ( main.TOTAL_TC_PASS == 0 ):
-            main.TOTAL_TC_SUCCESS = 0
+            main.TOTAL_TC_SUCCESS_PERCENT = 0
         else:
-            main.TOTAL_TC_SUCCESS = str( ( main.TOTAL_TC_PASS * 100 ) / main.TOTAL_TC_RUN )
+            main.TOTAL_TC_SUCCESS_PERCENT = main.TOTAL_TC_PASS * 100 / main.TOTAL_TC_RUN
         if ( main.TOTAL_TC_RUN == 0 ):
             main.TOTAL_TC_EXECPERCENT = 0
         else:
@@ -294,13 +294,13 @@
         testResult = testResult + "\n Test Start           : " + str( main.STARTTIME.strftime( "%d %b %Y %H:%M:%S" ) )
         testResult = testResult + "\n Test End             : " + str( main.ENDTIME.strftime( "%d %b %Y %H:%M:%S" ) )
         testResult = testResult + "\n Execution Time       : " + str( main.EXECTIME )
-        testResult = testResult + "\n Total tests planned  : " + str( main.TOTAL_TC_PLANNED )
-        testResult = testResult + "\n Total tests RUN      : " + str( main.TOTAL_TC_RUN )
+        testResult = testResult + "\n Total Tests Planned  : " + str( main.TOTAL_TC_PLANNED )
+        testResult = testResult + "\n Total Tests Run      : " + str( main.TOTAL_TC_RUN )
         testResult = testResult + "\n Total Pass           : " + str( main.TOTAL_TC_PASS )
         testResult = testResult + "\n Total Fail           : " + str( main.TOTAL_TC_FAIL )
         testResult = testResult + "\n Total No Result      : " + str( main.TOTAL_TC_NORESULT )
-        testResult = testResult + "\n Success Percentage   : " + str( main.TOTAL_TC_SUCCESS ) + "%"
-        testResult = testResult + "\n Execution Result     : " + str( main.TOTAL_TC_EXECPERCENT ) + "%\n"
+        testResult = testResult + "\n Success Percentage   : " + str( main.TOTAL_TC_SUCCESS_PERCENT ) + "%"
+        testResult = testResult + "\n Execution Percentage : " + str( main.TOTAL_TC_EXECPERCENT ) + "%\n"
         if main.failedCase:
             testResult = testResult + "\n Case Failed          : " + str( main.failedCase )
         if main.noResultCase:
@@ -311,6 +311,12 @@
         main.testResult = testResult
         main.log.exact( testResult )
 
+        # Write to alarm log if Success Percentage is lower than expected
+        if 'ALARM' in main.params.keys() and 'minPassPercent' in main.params[ 'ALARM' ].keys():
+            minPassPercent = int( main.params[ 'ALARM' ][ 'minPassPercent' ] )
+            if main.TOTAL_TC_SUCCESS_PERCENT < minPassPercent:
+                main.log.alarm( 'Success percentage: {}% < {}%'.format( main.TOTAL_TC_SUCCESS_PERCENT, minPassPercent ) )
+
         # CSV output needed for Jenkin's plot plugin
         # NOTE: the elements were orded based on the colors assigned to the data
         logfile = open( main.JenkinsCSV , "w" )
diff --git a/TestON/core/utilities.py b/TestON/core/utilities.py
index 91fc105..012b651 100644
--- a/TestON/core/utilities.py
+++ b/TestON/core/utilities.py
@@ -220,13 +220,13 @@
                 sub = "Result summary of \"" + main.TEST + "\" run on component \"" + \
                       main.test_target + "\" Version \"" + \
                       vars( main )[ main.test_target ].get_version() + "\": " + \
-                      str( main.TOTAL_TC_SUCCESS ) + "% Passed"
+                      str( main.TOTAL_TC_SUCCESS_PERCENT ) + "% Passed"
             else:
                 sub = "Result summary of \"" + main.TEST + "\": " + \
-                      str( main.TOTAL_TC_SUCCESS ) + "% Passed"
+                      str( main.TOTAL_TC_SUCCESS_PERCENT ) + "% Passed"
         except( KeyError, AttributeError ):
             sub = "Result summary of \"" + main.TEST + "\": " + \
-                  str( main.TOTAL_TC_SUCCESS ) + "% Passed"
+                  str( main.TOTAL_TC_SUCCESS_PERCENT ) + "% Passed"
 
         msg[ 'Subject' ] = sub
         msg[ 'From' ] = main.sender
diff --git a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params
index 8614a39..1520489 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params
+++ b/TestON/tests/USECASE/SegmentRouting/SRBridging/SRBridging.params
@@ -42,4 +42,8 @@
     <SLEEP>
         <startup>10</startup>
     </SLEEP>
+
+    <ALARM>
+        <minPassPercent>100</minPassPercent>
+    </ALARM>
 </PARAMS>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRDhcprelay/SRDhcprelay.params b/TestON/tests/USECASE/SegmentRouting/SRDhcprelay/SRDhcprelay.params
index dd5a7f8..6d1ae4a 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRDhcprelay/SRDhcprelay.params
+++ b/TestON/tests/USECASE/SegmentRouting/SRDhcprelay/SRDhcprelay.params
@@ -42,4 +42,8 @@
     <SLEEP>
         <startup>10</startup>
     </SLEEP>
+
+    <ALARM>
+        <minPassPercent>63</minPassPercent>
+    </ALARM>
 </PARAMS>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRDynamicConf/SRDynamicConf.params b/TestON/tests/USECASE/SegmentRouting/SRDynamicConf/SRDynamicConf.params
index b6cfc7a..284e1e3 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRDynamicConf/SRDynamicConf.params
+++ b/TestON/tests/USECASE/SegmentRouting/SRDynamicConf/SRDynamicConf.params
@@ -41,4 +41,8 @@
     <SLEEP>
         <startup>10</startup>
     </SLEEP>
+
+    <ALARM>
+        <minPassPercent>70</minPassPercent>
+    </ALARM>
 </PARAMS>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRMulticast/SRMulticast.params b/TestON/tests/USECASE/SegmentRouting/SRMulticast/SRMulticast.params
index 2a481b6..7ee65f6 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRMulticast/SRMulticast.params
+++ b/TestON/tests/USECASE/SegmentRouting/SRMulticast/SRMulticast.params
@@ -57,4 +57,7 @@
         <linkNum>48</linkNum>
     </TOPO>
 
+    <ALARM>
+        <minPassPercent>75</minPassPercent>
+    </ALARM>
 </PARAMS>
diff --git a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params
index 00d6ce9..d71126c 100644
--- a/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params
+++ b/TestON/tests/USECASE/SegmentRouting/SRRouting/SRRouting.params
@@ -55,4 +55,7 @@
         <linkNum>48</linkNum>
     </TOPO>
 
+    <ALARM>
+        <minPassPercent>80</minPassPercent>
+    </ALARM>
 </PARAMS>