[ONOS-7937] Add option to skip alarm logging in cleanAndExit

Change-Id: Ibee1688e8ac426798c21f0c347af7d4e8c2ca6cf
diff --git a/TestON/core/teston.py b/TestON/core/teston.py
index 1edc721..6775856 100644
--- a/TestON/core/teston.py
+++ b/TestON/core/teston.py
@@ -793,17 +793,30 @@
         os.system( "stty sane" )  # fix format if necessary
         sys.exit()
 
-    def cleanAndExit( self ):
+    def cleanAndExit( self, alarm=True, msg="" ):
         """
             It will set the testcase result to be FAILED and update it
             before cleaning up and exitting the test.
+            alarm: when set to True, it will write to the alarm log before
+            cleaning up and exitting; otherwise it will write to error log.
+            msg: message that will be written to the log if specified;
+            otherwise a default message will be written.
         :return:
         """
         if self.CurrentTestCaseNumber:
             self.testCaseResult[ str( self.CurrentTestCaseNumber ) ] = self.FALSE
             self.organizeResult( self.CurrentTestCaseNumber, self.FALSE )
             self.logger.updateCaseResults( self )
-        self.log.alarm( "Test exited unexpectedly" )
+        if alarm:
+            if msg:
+                self.log.alarm( "Test exited unexpectedly: {}".format( msg ) )
+            else:
+                self.log.alarm( "Test exited unexpectedly" )
+        else:
+            if msg:
+                self.log.error( "Test exited unexpectedly: {}".format( msg ) )
+            else:
+                self.log.error( "Test exited unexpectedly" )
         self.cleanup()
         self.exit()
 
diff --git a/TestON/drivers/common/api/controller/onosrestdriver.py b/TestON/drivers/common/api/controller/onosrestdriver.py
index 915c29b..af4309d 100755
--- a/TestON/drivers/common/api/controller/onosrestdriver.py
+++ b/TestON/drivers/common/api/controller/onosrestdriver.py
@@ -123,9 +123,9 @@
             if debug:
                 main.log.debug( response )
             return ( response.status_code, response.text.encode( 'utf8' ) )
-        except requests.exceptions:
+        except requests.ConnectionError:
             main.log.exception( "Error sending request." )
-            return None
+            return ( None, None )
         except Exception:
             main.log.exception( self.name + ": Uncaught exception!" )
             main.cleanAndExit()
diff --git a/TestON/tests/FUNC/FUNCvirNetNB/FUNCvirNetNB.py b/TestON/tests/FUNC/FUNCvirNetNB/FUNCvirNetNB.py
index d7872fd..fe633f1 100644
--- a/TestON/tests/FUNC/FUNCvirNetNB/FUNCvirNetNB.py
+++ b/TestON/tests/FUNC/FUNCvirNetNB/FUNCvirNetNB.py
@@ -146,6 +146,9 @@
                 onpass="Post Success",
                 onfail="Post Failed " + str( Poststatus ) + str( result ) )
 
+        if not Poststatus:
+            main.cleanAndExit( alarm=False )
+
         main.step( "Get Data via HTTP" )
         Getstatus, result = ctrl.REST.send( ctrlip, port, network.id, path + 'networks/',
                                             'GET', None, None )
diff --git a/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py b/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py
index bc4f3c3..c9b6ab1 100644
--- a/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py
+++ b/TestON/tests/PLAT/PLATdockertest/PLATdockertest.py
@@ -112,7 +112,7 @@
             main.cleanAndExit()
         if imageTagCounter > len( imageTagList ):
             main.log.info( "All images have been tested" )
-            main.cleanAndExit()
+            main.cleanAndExit( alarm=False )
 
     def CASE5( self, main ):
         """
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunction/dependencies/Functions.py b/TestON/tests/USECASE/USECASE_SdnipFunction/dependencies/Functions.py
index 81d2d96..fe3b1e2 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunction/dependencies/Functions.py
+++ b/TestON/tests/USECASE/USECASE_SdnipFunction/dependencies/Functions.py
@@ -151,7 +151,7 @@
                              onfail="Ping test results are Not expected" )
 
     if not result:
-        main.cleanAndExit()
+        main.cleanAndExit( alarm=False )
 
 
 def pingHostToHost( main,
diff --git a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py
index 8edc284..f280d44 100644
--- a/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py
+++ b/TestON/tests/USECASE/USECASE_SdnipFunctionCluster/dependencies/Functions.py
@@ -145,7 +145,7 @@
                              onfail="Ping test results are Not expected" )
 
     if not result:
-        main.cleanAndExit()
+        main.cleanAndExit( alarm=False )
 
 
 def pingHostToHost( main, hosts=[ "h64514", "h64515", "h64516" ],
diff --git a/TestON/tests/dependencies/ONOSSetup.py b/TestON/tests/dependencies/ONOSSetup.py
index cb40761..d7ea792 100644
--- a/TestON/tests/dependencies/ONOSSetup.py
+++ b/TestON/tests/dependencies/ONOSSetup.py
@@ -440,8 +440,7 @@
                     ctrl.name,
                     ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )  #FIXME: This output has changed a lot
             main.log.error( "Failed to start ONOS, stopping test" )
-            main.log.alarm( "Failed to start ONOS: not all nodes are in READY state" )
-            main.cleanAndExit()
+            main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
         return main.TRUE
 
     def checkOnosApps( self, cluster, apps ):