summaryrefslogtreecommitdiffstats
path: root/dovetail/utils/dovetail_utils.py
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2019-04-03 05:33:24 -0400
committerxudan <xudan16@huawei.com>2019-04-03 22:25:59 -0400
commit06a0a8f2bd8ee7ce7db154c54301ec986b93b89f (patch)
tree89bd74978b9d9c4b107b4a617d557a60c95007a7 /dovetail/utils/dovetail_utils.py
parenteb86745284805f2943d4733bb029948be760d597 (diff)
Push CI results to OPNFV test DB
In order to use OPNFV test results page to do the ayalysis of all OVP test cases, it needs to push all results generated by Dovetail CI jobs to test DB and then using http://testresults.opnfv.org/test/#/results to check all results. The following data must contain in the POST body: 1. project_name 2. case_name 3. details 4. installer 5. scenario 6. pod_name 7. build_tag 8. criteria 9. start_date 10. stop_date 11. version JIRA: DOVETAIL-767 Change-Id: I925ae249e24efd7bfb1c68a69150e9c22f0cdf36 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/utils/dovetail_utils.py')
-rw-r--r--dovetail/utils/dovetail_utils.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py
index a3d07824..aee6dc29 100644
--- a/dovetail/utils/dovetail_utils.py
+++ b/dovetail/utils/dovetail_utils.py
@@ -12,6 +12,7 @@ from __future__ import print_function
import sys
import os
import re
+import requests
import subprocess
from collections import Mapping, Set, Sequence
import json
@@ -403,3 +404,30 @@ def get_openstack_info(logger):
get_hosts_info(logger)
get_openstack_endpoint(logger)
get_hardware_info(logger)
+
+
+def push_results_to_db(case_name, details, start_date, stop_date, logger):
+ """
+ Push results to OPNFV TestAPI DB when running with OPNFV CI jobs.
+ All results can be filtered with TestAPI.
+ http://testresults.opnfv.org/test/#/results
+ """
+ try:
+ url = os.getenv('TEST_DB_URL')
+ data = {'project_name': 'dovetail', 'case_name': case_name,
+ 'details': details, 'start_date': start_date,
+ 'stop_date': stop_date}
+ data['criteria'] = details['criteria'] if details else 'FAIL'
+ data['installer'] = os.getenv('INSTALLER_TYPE')
+ data['scenario'] = os.getenv('DEPLOY_SCENARIO')
+ data['pod_name'] = os.getenv('NODE_NAME')
+ data['build_tag'] = os.getenv('BUILD_TAG')
+ data['version'] = os.getenv('VERSION')
+ req = requests.post(url, data=json.dumps(data, sort_keys=True),
+ headers={'Content-Type': 'application/json'})
+ req.raise_for_status()
+ logger.debug('The results were successfully pushed to DB.')
+ return True
+ except Exception:
+ logger.exception('The results cannot be pushed to DB.')
+ return False