# http://www.apache.org/licenses/LICENSE-2.0
#
+""" global variables """
+
+from datetime import datetime as dt
import json
import os
import os.path
import re
-import requests
import shutil
import socket
import subprocess
import sys
import urllib2
-import yaml
+
+import functest.ci.tier_builder as tb
from git import Repo
+import requests
+import yaml
+
+
+REPOS_DIR = os.getenv('repos_dir')
+FUNCTEST_REPO = ("%s/functest/" % REPOS_DIR)
# ----------------------------------------------------------
return build_tag
-def push_results_to_db(db_url, project, case_name, logger, pod_name,
- version, scenario, criteria, build_tag, payload):
+def get_db_url(logger=None):
+ """
+ Returns DB URL
+ """
+ with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
+ functest_yaml = yaml.safe_load(f)
+ f.close()
+ db_url = functest_yaml.get("results").get("test_db_url")
+ return db_url
+
+
+def push_results_to_db(project, case_name, logger,
+ start_date, stop_date, criteria, details):
"""
POST results to the Result target DB
"""
- url = db_url + "/results"
+ # Retrieve params from CI and conf
+ url = get_db_url(logger) + "/results"
installer = get_installer_type(logger)
+ scenario = get_scenario(logger)
+ version = get_version(logger)
+ pod_name = get_pod_name(logger)
+ build_tag = get_build_tag(logger)
+ 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": criteria,
- "build_tag": build_tag, "details": payload}
+ "build_tag": build_tag, "start_date": test_start,
+ "stop_date": test_stop, "details": details}
headers = {'Content-Type': 'application/json'}
try:
except Exception, e:
print ("Error [push_results_to_db('%s', '%s', '%s', " +
"'%s', '%s', '%s', '%s', '%s', '%s')]:" %
- (db_url, project, case_name, pod_name, version,
- scenario, criteria, build_tag, payload), e)
+ (url, project, case_name, pod_name, version,
+ scenario, criteria, build_tag, details)), e
return False
print(msg_exec)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
while True:
- line = p.stdout.readline().replace('\n', '')
+ output = p.stdout.readline()
+ line = output.replace('\n', '')
if not line:
break
if logger:
deployment_dir = (rally_dir + "/tempest/for-deployment-" +
deployment_uuid)
return deployment_dir
+
+
+def get_criteria_by_test(testname):
+ criteria = ""
+ file = FUNCTEST_REPO + "/ci/testcases.yaml"
+ tiers = tb.TierBuilder("", "", file)
+ for tier in tiers.get_tiers():
+ for test in tier.get_tests():
+ if test.get_name() == testname:
+ criteria = test.get_criteria()
+
+ return criteria
+
+
+# ----------------------------------------------------------
+#
+# YAML UTILS
+#
+# -----------------------------------------------------------
+def get_parameter_from_yaml(parameter, file=None):
+ """
+ Returns the value of a given parameter in config_functest.yaml
+ parameter must be given in string format with dots
+ Example: general.openstack.image_name
+ """
+ if file is None:
+ file = os.environ["CONFIG_FUNCTEST_YAML"]
+ with open(file) as f:
+ functest_yaml = yaml.safe_load(f)
+ f.close()
+ value = functest_yaml
+ for element in parameter.split("."):
+ value = value.get(element)
+ if value is None:
+ raise ValueError("The parameter %s is not defined in"
+ " config_functest.yaml" % parameter)
+ return value