[ODL-SFC] Add push resulst to DB 29/20929/5
authorjose.lausuch <jose.lausuch@ericsson.com>
Mon, 12 Sep 2016 16:17:07 +0000 (18:17 +0200)
committerJose Lausuch <jose.lausuch@ericsson.com>
Tue, 13 Sep 2016 08:09:04 +0000 (08:09 +0000)
Change-Id: I314cbda828f6ebda70f7fb4e7d39e781696bc073
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
testcases/features/sfc/sfc.py

index c84810e..5a361cd 100755 (executable)
@@ -58,6 +58,11 @@ def main():
     # Allow any port so that tacker commands reaches the server.
     # This will be deleted when tacker is included in OPNFV installation
 
+    status = "PASS"
+    failures = 0
+    start_time = time.time()
+    json_results = {}
+
     ssh_options = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
     contr_cmd = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                  " 'fuel node'|grep controller|awk '{print $10}'")
@@ -315,7 +320,7 @@ def main():
 
     logger.info("Waiting for 60 seconds before TEST")
     for j in range(0, 6):
-        logger.info("Test starting in {0} seconds".format(str((6 - j)*10)))
+        logger.info("Test starting in {0} seconds".format(str((6 - j) * 10)))
         time.sleep(10)
 
     i = 0
@@ -333,10 +338,13 @@ def main():
             logger.info('\033[92m' + "TEST 1 [PASSED] "
                         "==> SSH BLOCKED" + '\033[0m')
             i = i + 1
+            json_results.update({"Test 1: SSH Blocked": "Passed"})
         else:
             logger.error('\033[91m' + "TEST 1 [FAILED] "
                          "==> SSH NOT BLOCKED" + '\033[0m')
-            return
+            status = "FAIL"
+            json_results.update({"Test 1: SSH Blocked": "Failed"})
+            failures += 1
     except:
         logger.debug("Waiting for %s..." % floatip_client)
         time.sleep(6)
@@ -353,10 +361,13 @@ def main():
             logger.info('\033[92m' + "TEST 2 [PASSED] "
                         "==> HTTP WORKS" + '\033[0m')
             i = i + 1
+            json_results.update({"Test 2: HTTP works": "Passed"})
         else:
             logger.error('\033[91m' + "TEST 2 [FAILED] "
                          "==> HTTP BLOCKED" + '\033[0m')
-            return
+            status = "FAIL"
+            json_results.update({"Test 2: HTTP works": "Failed"})
+            failures += 1
     except:
         logger.debug("Waiting for %s..." % floatip_client)
         time.sleep(6)
@@ -389,13 +400,16 @@ def main():
         (stdin, stdout, stderr) = ssh.exec_command(command)
 
         if "timed out" in stdout.readlines()[0]:
-            logger.info('\033[92m' + "TEST 3 [WORKS] "
+            logger.info('\033[92m' + "TEST 3 [PASSED] "
                         "==> HTTP BLOCKED" + '\033[0m')
             i = i + 1
+            json_results.update({"Test 3: HTTP Blocked": "Passed"})
         else:
             logger.error('\033[91m' + "TEST 3 [FAILED] "
                          "==> HTTP NOT BLOCKED" + '\033[0m')
-            return
+            status = "FAIL"
+            json_results.update({"Test 3: HTTP Blocked": "Failed"})
+            failures += 1
     except:
         logger.debug("Waiting for %s..." % floatip_client)
         time.sleep(6)
@@ -409,13 +423,16 @@ def main():
         (stdin, stdout, stderr) = ssh.exec_command(command)
 
         if "succeeded" in stdout.readlines()[0]:
-            logger.info('\033[92m' + "TEST 4 [WORKS] "
+            logger.info('\033[92m' + "TEST 4 [PASSED] "
                         "==> SSH WORKS" + '\033[0m')
             i = i + 1
+            json_results.update({"Test 4: SSH works": "Passed"})
         else:
             logger.error('\033[91m' + "TEST 4 [FAILED] "
                          "==> SSH BLOCKED" + '\033[0m')
-            return
+            status = "FAIL"
+            json_results.update({"Test 4: SSH works": "Failed"})
+            failures += 1
     except:
         logger.debug("Waiting for %s..." % floatip_client)
         time.sleep(6)
@@ -426,21 +443,20 @@ def main():
             logger.info('\033[92m' + "SFC TEST WORKED"
                         " :) \n" + '\033[0m')
 
-    # TODO report results to DB
-    # functest_utils.logger_test_results("SFC",
-    # "odl-sfc",
-    # status, details)
-    # see doctor, promise, domino, ...
-    # if args.report:
-        # logger.info("Pushing odl-SFC results")
-        # functest_utils.push_results_to_db("functest",
-        #                                  "odl-sfc",
-        #                                  start_time,
-        #                                  stop_time,
-        #                                  status,
-        #                                  details)
-
-    sys.exit(0)
+    if args.report:
+        stop_time = time.time()
+        json_results.update({"tests": "4", "failures": int(failures)})
+        logger.debug("Promise Results json: " + str(json_results))
+        ft_utils.push_results_to_db("sfc",
+                                    "functest-odl-sfc",
+                                    start_time,
+                                    stop_time,
+                                    status,
+                                    json_results)
+    if status == "PASS":
+        sys.exit(0)
+    else:
+        sys.exit(1)
 
 if __name__ == '__main__':
     main()