Get results json data from database 99/34099/3
authorxudan <xudan16@huawei.com>
Wed, 3 May 2017 06:11:51 +0000 (06:11 +0000)
committerxudan <xudan16@huawei.com>
Thu, 4 May 2017 02:40:07 +0000 (02:40 +0000)
JIRA: DOVETAIL-417

1. If report results with files, all results will be stored in local files.
2. If report to database, will get results from database and stored with file results.json

Change-Id: Ic30037bd66cd37042f82b75fac2043a876e21c6f
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/conf/dovetail_config.yml
dovetail/run.py
dovetail/utils/dovetail_utils.py

index 332628a..ec1f525 100644 (file)
@@ -1,7 +1,8 @@
 ---
-report_file: 'dovetail_report.txt'
+report_file: 'dovetail_report.txt'
 cli_file_name: 'cmd_config.yml'
 report_dest: 'file'
+result_file: 'results.json'
 
 # OPENSTACK Credential file
 openrc: '/home/opnfv/dovetail/openrc.sh'
index 4bea9b5..5b4dca8 100755 (executable)
@@ -74,17 +74,20 @@ def check_tc_result(testcase, logger):
     result_dir = dt_cfg.dovetail_config['result_dir']
     validate_type = testcase.validate_type()
     functest_result = dt_cfg.dovetail_config['functest']['result']['file_path']
+    dovetail_result = os.path.join(result_dir,
+                                   dt_cfg.dovetail_config['result_file'])
     if dt_cfg.dovetail_config['report_dest'].startswith("http"):
         if validate_type.lower() == 'yardstick':
             logger.info("Results have been stored with file %s.",
                         os.path.join(result_dir,
                                      testcase.validate_testcase() + '.out'))
         else:
-            if dt_utils.check_db_results(dt_cfg.dovetail_config['report_dest'],
+            if dt_utils.store_db_results(dt_cfg.dovetail_config['report_dest'],
                                          dt_cfg.dovetail_config['build_tag'],
-                                         testcase.name(),
+                                         testcase.name(), dovetail_result,
                                          logger):
-                logger.info("Results have been pushed to database.")
+                logger.info("Results have been pushed to database and stored "
+                            "with local file %s.", dovetail_result)
             else:
                 logger.error("Fail to push results to database.")
     if dt_cfg.dovetail_config['report_dest'] == "file":
index 83390e9..e6a775f 100644 (file)
@@ -132,12 +132,14 @@ def get_ext_net_name(env_file, logger=None):
     return None
 
 
-def check_db_results(db_url, build_tag, testcase, logger):
+def store_db_results(db_url, build_tag, testcase, dest_file, logger):
     url = "%s?build_tag=%s-%s" % (db_url, build_tag, testcase)
     logger.debug("Query to rest api: %s", url)
     try:
         data = json.load(urllib2.urlopen(url))
         if data['results']:
+            with open(dest_file, 'a') as f:
+                f.write(json.dumps(data['results'][0]) + '\n')
             return True
         else:
             return False