3 # Copyright (c) 2015 Orange
4 # morgan.richomme@orange.com
6 # This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # This script is used to build json files for the dashboard
13 # for the vPing test case
21 import dashboard_utils
25 pp = pprint.PrettyPrinter(indent=4)
27 parser = argparse.ArgumentParser()
28 parser.add_argument("repo_path", help="Path to the repository")
29 parser.add_argument("-d", "--debug", help="Debug mode", action="store_true")
30 args = parser.parse_args()
32 """ logging configuration """
33 logger = logging.getLogger('config_functest')
34 logger.setLevel(logging.DEBUG)
36 if not os.path.exists(args.repo_path):
37 logger.error("Repo directory not found '%s'" % args.repo_path)
40 with open(args.repo_path+"testcases/config_functest.yaml") as f:
41 functest_yaml = yaml.safe_load(f)
44 """ global variables """
46 HOME = os.environ['HOME']+"/"
47 REPO_PATH = args.repo_path
48 TEST_DB = functest_yaml.get("results").get("test_db_url")
51 def format_vPing_for_dashboard(criteria):
54 myDataResults = dashboard_utils.get_results(TEST_DB, criteria)
56 # Depending on the use case, json for dashboarding is customized
57 # depending on the graph you want to show
59 test_data = [{'description': 'vPing results for Dashboard'}]
61 # Graph 1: Duration = f(time)
62 # ***************************
64 for data in myDataResults:
65 new_element.append({'x': data['creation_date'],
66 'y': data['details']['duration']})
68 test_data.append({'name': "vPing duration",
69 'info': {'type': "graph",
71 'ylabel': 'duration (s)'},
72 'data_set': new_element})
79 for data in myDataResults:
81 if data['details']['status'] == "OK":
84 test_data.append({'name': "vPing status",
85 'info': {"type": "bar"},
86 'data_set': [{'Nb tests': nbTest,
87 'Nb Success': nbTestOk}]})
90 fileName = criteria.format()
91 logger.debug("Generate json file:" + fileName)
93 with open(fileName, "w") as outfile:
94 json.dump(test_data, outfile, indent=4)