aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-01-20 14:41:32 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-01-21 01:07:41 +0100
commita6df43da7ab4de653eecbc9b6380d5fc7ce7bc14 (patch)
tree028d5516ead89f61929866382b600598e6dac926 /functest/utils
parent45fdfedc5b5573926c53264ff5eb3e48a43345d9 (diff)
Move push_results_to_db to TestCase
It removes the link between TestCase and Functest utils (xtesting). It should be noted that testresults url can only be set by env var. Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com> Change-Id: Ie072c675890d0ae2e63619c599d2684a8c7d762d Signed-off-by: Jose Lausuch <jalausuch@suse.com> Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/utils')
-rw-r--r--functest/utils/functest_utils.py101
1 files changed, 0 insertions, 101 deletions
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index 6d0b345d..1e88dadb 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -8,7 +8,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
import functools
-import json
import logging
import os
import pkg_resources
@@ -17,16 +16,12 @@ import shutil
import subprocess
import sys
import time
-from datetime import datetime as dt
import dns.resolver
-import requests
from six.moves import urllib
import yaml
from functest.utils import constants
-from functest.utils import decorators
-from functest.utils.constants import CONST
logger = logging.getLogger(__name__)
@@ -68,102 +63,6 @@ def download_url(url, dest_path):
# CI UTILS
#
# -----------------------------------------------------------
-def get_version():
- """
- Get version
- """
- # Use the build tag to retrieve the version
- # By default version is unknown
- # if launched through CI the build tag has the following format
- # jenkins-<project>-<installer>-<pod>-<job>-<branch>-<id>
- # e.g. jenkins-functest-fuel-opnfv-jump-2-daily-master-190
- # jenkins-functest-fuel-baremetal-weekly-master-8
- # use regex to match branch info
- rule = "(dai|week)ly-(.+?)-[0-9]*"
- build_tag = CONST.__getattribute__('BUILD_TAG')
- if not build_tag:
- build_tag = 'none'
- m = re.search(rule, build_tag)
- if m:
- return m.group(2)
- else:
- return "unknown"
-
-
-@decorators.can_dump_request_to_file
-def push_results_to_db(project, case_name,
- start_date, stop_date, result, details):
- """
- POST results to the Result target DB
- """
- # Retrieve params from CI and conf
- if (hasattr(CONST, 'TEST_DB_URL')):
- url = CONST.__getattribute__('TEST_DB_URL')
- else:
- url = CONST.__getattribute__("results_test_db_url")
-
- try:
- installer = os.environ['INSTALLER_TYPE']
- scenario = os.environ['DEPLOY_SCENARIO']
- pod_name = os.environ['NODE_NAME']
- build_tag = os.environ['BUILD_TAG']
- except KeyError as e:
- logger.error("Please set env var: " + str(e))
- return False
- version = get_version()
- test_start = dt.fromtimestamp(start_date).strftime('%Y-%m-%d %H:%M:%S')
- test_stop = dt.fromtimestamp(stop_date).strftime('%Y-%m-%d %H:%M:%S')
-
- params = {"project_name": project, "case_name": case_name,
- "pod_name": pod_name, "installer": installer,
- "version": version, "scenario": scenario, "criteria": result,
- "build_tag": build_tag, "start_date": test_start,
- "stop_date": test_stop, "details": details}
-
- error = None
- headers = {'Content-Type': 'application/json'}
- try:
- r = requests.post(url, data=json.dumps(params, sort_keys=True),
- headers=headers)
- logger.debug(r)
- r.raise_for_status()
- except requests.RequestException as exc:
- if 'r' in locals():
- error = ("Pushing Result to DB(%s) failed: %s" %
- (r.url, r.content))
- else:
- error = ("Pushing Result to DB(%s) failed: %s" % (url, exc))
- except Exception as e:
- error = ("Error [push_results_to_db("
- "DB: '%(db)s', "
- "project: '%(project)s', "
- "case: '%(case)s', "
- "pod: '%(pod)s', "
- "version: '%(v)s', "
- "scenario: '%(s)s', "
- "criteria: '%(c)s', "
- "build_tag: '%(t)s', "
- "details: '%(d)s')]: "
- "%(error)s" %
- {
- 'db': url,
- 'project': project,
- 'case': case_name,
- 'pod': pod_name,
- 'v': version,
- 's': scenario,
- 'c': result,
- 't': build_tag,
- 'd': details,
- 'error': e
- })
- finally:
- if error:
- logger.error(error)
- return False
- return True
-
-
def get_resolvconf_ns():
"""
Get nameservers from current resolv.conf