import logging
import json
import os
+import requests
import pdfkit
import yaml
response = urlopen(request)
k = response.read()
results = json.loads(k)
- except URLError, e:
- print 'No kittez. Got an error code:', e
+ except URLError as e:
+ print('No kittez. Got an error code:', e)
return results
def getScenarios(case, installer, version):
- case = case.getName()
+ try:
+ case = case.getName()
+ except:
+ # if case is not an object test case, try the string
+ if type(case) == str:
+ case = case
+ else:
+ raise ValueError("Case cannot be evaluated")
+
period = get_config('general.period')
url_base = get_config('testapi.url')
k = response.read()
results = json.loads(k)
test_results = results['results']
- except URLError, e:
- print 'Got an error code:', e
+ except URLError as e:
+ print('Got an error code:', e)
if test_results is not None:
test_results.reverse()
# Retrieve all the scenarios per installer
if not r['scenario'] in scenario_results.keys():
scenario_results[r['scenario']] = []
- scenario_results[r['scenario']].append(r)
+ # Do we consider results from virtual pods ...
+ # Do we consider results for non HA scenarios...
+ exclude_virtual_pod = get_config('functest.exclude_virtual')
+ exclude_noha = get_config('functest.exclude_noha')
+ if ((exclude_virtual_pod and "virtual" in r['pod_name']) or
+ (exclude_noha and "noha" in r['scenario'])):
+ print("exclude virtual pod results...")
+ else:
+ scenario_results[r['scenario']].append(r)
return scenario_results
response.close()
results = json.loads(k)
test_results = results['results']
- except URLError, e:
- print 'Got an error code:', e
+ except URLError as e:
+ print('Got an error code:', e)
scenario_results = {}
result_dict = {}
return result_dict
+def getQtipResults(version, installer):
+ period = get_config('qtip.period')
+ url_base = get_config('testapi.url')
+
+ url = ("http://" + url_base + "?project=qtip" +
+ "&installer=" + installer +
+ "&version=" + version + "&period=" + str(period))
+ request = Request(url)
+
+ try:
+ response = urlopen(request)
+ k = response.read()
+ response.close()
+ results = json.loads(k)['results']
+ except URLError as e:
+ print('Got an error code:', e)
+
+ result_dict = {}
+ if results:
+ for r in results:
+ key = '{}/{}'.format(r['pod_name'], r['scenario'])
+ if key not in result_dict.keys():
+ result_dict[key] = []
+ result_dict[key].append(r['details']['score'])
+
+ # return scenario_results
+ return result_dict
+
+
def getNbtestOk(results):
nb_test_ok = 0
for r in results:
if "PASS" in v:
nb_test_ok += 1
except:
- print "Cannot retrieve test status"
+ print("Cannot retrieve test status")
return nb_test_ok
def getJenkinsUrl(build_tag):
# e.g. jenkins-functest-apex-apex-daily-colorado-daily-colorado-246
# id = 246
+ # jenkins-functest-compass-huawei-pod5-daily-master-136
+ # id = 136
# note it is linked to jenkins format
# if this format changes...function to be adapted....
url_base = get_config('functest.jenkins_url')
try:
build_id = [int(s) for s in build_tag.split("-") if s.isdigit()]
- jenkins_path = filter(lambda c: not c.isdigit(), build_tag)
- url_id = jenkins_path[8:-1] + "/" + str(build_id[0])
+ url_id = (build_tag[8:-(len(str(build_id[0])) + 1)] +
+ "/" + str(build_id[0]))
jenkins_url = url_base + url_id + "/console"
except:
- print 'Impossible to get jenkins url:'
+ print('Impossible to get jenkins url:')
+
+ if "jenkins-" not in build_tag:
+ jenkins_url = None
return jenkins_url
try:
score = float(scenario_score) / float(scenario_criteria) * 100
except:
- print 'Impossible to calculate the percentage score'
+ print('Impossible to calculate the percentage score')
return score
+# *********
+# Functest
+# *********
+def getFunctestConfig(version=""):
+ config_file = get_config('functest.test_conf') + version
+ response = requests.get(config_file)
+ return yaml.safe_load(response.text)
+
+
+def getArchitectures(scenario_results):
+ supported_arch = ['x86']
+ if (len(scenario_results) > 0):
+ for scenario_result in scenario_results.values():
+ for value in scenario_result:
+ if ("armband" in value['build_tag']):
+ supported_arch.append('aarch64')
+ return supported_arch
+ return supported_arch
+
+
+def filterArchitecture(results, architecture):
+ filtered_results = {}
+ for name, results in results.items():
+ filtered_values = []
+ for value in results:
+ if (architecture is "x86"):
+ # drop aarch64 results
+ if ("armband" not in value['build_tag']):
+ filtered_values.append(value)
+ elif(architecture is "aarch64"):
+ # drop x86 results
+ if ("armband" in value['build_tag']):
+ filtered_values.append(value)
+ if (len(filtered_values) > 0):
+ filtered_results[name] = filtered_values
+ return filtered_results
+
+
# *********
# Yardstick
# *********
def _test():
status = getScenarioStatus("compass", "master")
- print "status:++++++++++++++++++++++++"
- print json.dumps(status, indent=4)
+ print("status:++++++++++++++++++++++++")
+ print(json.dumps(status, indent=4))
# ----------------------------------------------------------
scenario_installer_file.close
+def generate_csv(scenario_file):
+ import shutil
+ # csv
+ # generate sub files based on scenario_history.txt
+ csv_file = scenario_file.replace('txt', 'csv')
+ shutil.copy2(scenario_file, csv_file)
+
+
def export_pdf(pdf_path, pdf_doc_name):
try:
pdfkit.from_file(pdf_path, pdf_doc_name)