From 91c43fa2ea896d07e4070bed7e61ff0c576a3861 Mon Sep 17 00:00:00 2001
From: Rohit Gupta <rohit.gupta@eurecom.fr>
Date: Tue, 29 Dec 2015 20:49:11 +0100
Subject: [PATCH] updates for terminating program after fatal SSH Errors

---
 cmake_targets/autotests/openair.py                      | 9 +++++++--
 cmake_targets/autotests/run_exec_lte-softmodem_tests.py | 5 ++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cmake_targets/autotests/openair.py b/cmake_targets/autotests/openair.py
index 8427735c6..b61a29676 100644
--- a/cmake_targets/autotests/openair.py
+++ b/cmake_targets/autotests/openair.py
@@ -83,10 +83,13 @@ class openair(core):
         return (stdout, stderr)
 
     def connect(self, username, password, prompt='PEXPECT_OAI'):
-     while True:  
+     max_retries=100
+     i=0
+     while i <= max_retries:  
         self.prompt1 = prompt
         self.prompt2 = prompt
         self.password = '' 
+        i=i+1
         # WE do not store the password when sending commands for secuirity reasons. The password might be accidentally logged in such cases.
         #The password is used only to make ssh connections. In case user wants to run programs with sudo, then he/she needs to add following line in /etc/sudoers
         # your_user_name  ALL=(ALL:ALL) NOPASSWD: ALL
@@ -113,7 +116,9 @@ class openair(core):
             print error
             print "Retrying again in 1  seconds"
             time.sleep(1)
-            #sys.exit(1)
+            if i==max_retries:
+              print "Fatal Error: Terminating the program now..."
+              sys.exit(1)
                 
     def connect2(self, username, password, prompt='$'):
         self.prompt1 = prompt
diff --git a/cmake_targets/autotests/run_exec_lte-softmodem_tests.py b/cmake_targets/autotests/run_exec_lte-softmodem_tests.py
index 2e1f5c4fc..905847230 100644
--- a/cmake_targets/autotests/run_exec_lte-softmodem_tests.py
+++ b/cmake_targets/autotests/run_exec_lte-softmodem_tests.py
@@ -273,9 +273,12 @@ def SSHSessionWrapper(machine, username, key_file, password, logdir_remote_testc
        error = error + '\n username = ' + username + '\n machine = ' + machine + '\n logdir_remote = ' + logdir_remote_testcase + '\n logdir_local_base = ' + logdir_local_base 
        error = error + traceback.format_exc()
        print error
-       print " Trying again in 1 seconds"
+       print " Retrying again in 1 seconds"
        time.sleep(1)
        print "Continuing ..."
+       if i ==max_tries:
+          print "Fatal Error: Max no of retries reached. Exiting now..."
+          sys.exit(1)
 
 
  
-- 
GitLab