bug fix use FAIL/PASS as criteria for integration in automatic reporting
[functest.git] / testcases / features / doctor.py
index 9ca6bf6..ef55506 100644 (file)
 #
 #
 
-import logging
+import os
 import time
 import yaml
 
-import functest_utils
+import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as functest_utils
 
-with open('/home/opnfv/functest/conf/config_functest.yaml') as f:
+with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
     functest_yaml = yaml.safe_load(f)
 
 dirs = functest_yaml.get('general').get('directories')
@@ -28,25 +29,18 @@ FUNCTEST_REPO = dirs.get('dir_repo_functest')
 DOCTOR_REPO = dirs.get('dir_repo_doctor')
 TEST_DB_URL = functest_yaml.get('results').get('test_db_url')
 
-logger = logging.getLogger('doctor')
-logger.setLevel(logging.DEBUG)
-ch = logging.StreamHandler()
-ch.setLevel(logging.DEBUG)
-formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - ' +
-                              '%(message)s')
-ch.setFormatter(formatter)
-logger.addHandler(ch)
+logger = ft_logger.Logger("doctor").getLogger()
 
 
 def main():
     cmd = 'cd %s/tests && ./run.sh' % DOCTOR_REPO
-    start_time_ts = time.time()
+    start_time = time.time()
 
     ret = functest_utils.execute_command(cmd, logger, exit_on_error=False)
 
-    end_time_ts = time.time()
-    duration = round(end_time_ts - start_time_ts, 1)
-    if ret:
+    stop_time = time.time()
+    duration = round(stop_time - start_time, 1)
+    if ret == 0:
         logger.info("doctor OK")
         test_status = 'OK'
     else:
@@ -54,20 +48,20 @@ def main():
         test_status = 'NOK'
 
     details = {
-        'timestart': start_time_ts,
+        'timestart': start_time,
         'duration': duration,
         'status': test_status,
     }
     pod_name = functest_utils.get_pod_name(logger)
     scenario = functest_utils.get_scenario(logger)
-    version = scenario
+    version = functest_utils.get_version(logger)
     build_tag = functest_utils.get_build_tag(logger)
 
-    status = "failed"
+    status = "FAIL"
     if details['status'] == "OK":
-        status = "passed"
+        status = "PASS"
 
-    logger.info("Pushing result: TEST_DB_URL=%(db)s pod_name=%(pod)s "
+    logger.info("Pushing Doctor results: TEST_DB_URL=%(db)s pod_name=%(pod)s "
                 "version=%(v)s scenario=%(s)s criteria=%(c)s details=%(d)s" % {
                     'db': TEST_DB_URL,
                     'pod': pod_name,
@@ -77,11 +71,13 @@ def main():
                     'b': build_tag,
                     'd': details,
                 })
-    functest_utils.push_results_to_db(TEST_DB_URL,
-                                      'doctor', 'doctor-notification',
-                                      logger, pod_name, version, scenario,
-                                      status, build_tag, details)
-
+    functest_utils.push_results_to_db("doctor",
+                                      "doctor-notification",
+                                      logger,
+                                      start_time,
+                                      stop_time,
+                                      status,
+                                      details)
 
 if __name__ == '__main__':
     main()