From a6df43da7ab4de653eecbc9b6380d5fc7ce7bc14 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Sat, 20 Jan 2018 14:41:32 +0100 Subject: Move push_results_to_db to TestCase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: Ie072c675890d0ae2e63619c599d2684a8c7d762d Signed-off-by: Jose Lausuch Signed-off-by: Cédric Ollivier --- functest/utils/functest_utils.py | 101 --------------------------------------- 1 file changed, 101 deletions(-) (limited to 'functest/utils/functest_utils.py') diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index 6d0b345d5..1e88dadb7 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------ - # 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 -- cgit 1.2.3-korg