Catch timeout exception in vIMS 39/17139/3
authorboucherv <valentin.boucher@orange.com>
Tue, 19 Jul 2016 14:05:11 +0000 (16:05 +0200)
committerboucherv <valentin.boucher@orange.com>
Tue, 19 Jul 2016 14:18:18 +0000 (16:18 +0200)
JIRA: FUNCTEST-368

Change-Id: Ifeec4b89e9a05ee02d5a0829ee787dbd6ef528b2
Signed-off-by: boucherv <valentin.boucher@orange.com>
testcases/vnf/vIMS/orchestrator.py

index f52afe1..7917e77 100644 (file)
@@ -176,7 +176,7 @@ class orchestrator:
                    dep_name + " --timeout 1800; ")
 
         cmd = "/bin/bash -c '" + script + "'"
-        error = execute_command(cmd, self.logger)
+        error = execute_command(cmd, self.logger, 2000)
         if error:
             return error
         if self.logger:
@@ -205,10 +205,18 @@ def execute_command(cmd, logger, timeout=1800):
     """
     if logger:
         logger.debug('Executing command : {}'.format(cmd))
+    timeout_exception = False
     output_file = "output.txt"
     f = open(output_file, 'w+')
-    p = subprocess.call(cmd, shell=True, stdout=f,
-                        stderr=subprocess.STDOUT, timeout=timeout)
+    try:
+        p = subprocess.call(cmd, shell=True, stdout=f,
+                            stderr=subprocess.STDOUT, timeout=timeout)
+    except subprocess.TimeoutExpired:
+        timeout_exception = True
+        if logger:
+            logger.error("TIMEOUT when executing command %s" % cmd)
+        pass
+
     f.close()
     f = open(output_file, 'r')
     result = f.read()
@@ -217,7 +225,7 @@ def execute_command(cmd, logger, timeout=1800):
     if p == 0:
         return False
     else:
-        if logger:
+        if logger and not timeout_exception:
             logger.error("Error when executing command %s" % cmd)
         f = open(output_file, 'r')
         lines = f.readlines()