Merge "Include cirros image in the docker container"
[functest.git] / testcases / Dashboard / functest2Dashboard.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2015 Orange
4 # morgan.richomme@orange.com
5 #
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
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # This script is used to get data from test DB
13 # and format them into a json format adapted for a dashboard
14 #
15 # v0.1: basic example
16 #
17 import logging
18 import argparse
19 import pprint
20 import dashboard_utils
21 import os
22 import yaml
23
24 pp = pprint.PrettyPrinter(indent=4)
25
26 parser = argparse.ArgumentParser()
27 parser.add_argument("repo_path", help="Path to the repository")
28 parser.add_argument("-d", "--debug", help="Debug mode",  action="store_true")
29 args = parser.parse_args()
30
31 """ logging configuration """
32 logger = logging.getLogger('config_functest')
33 logger.setLevel(logging.DEBUG)
34
35 ch = logging.StreamHandler()
36 if args.debug:
37     ch.setLevel(logging.DEBUG)
38 else:
39     ch.setLevel(logging.INFO)
40
41 formatter = logging.Formatter('%(asctime)s - %(name)s -\
42                                  %(levelname)s - %(message)s')
43 ch.setFormatter(formatter)
44 logger.addHandler(ch)
45
46 if not os.path.exists(args.repo_path):
47     logger.error("Repo directory not found '%s'" % args.repo_path)
48     exit(-1)
49
50 with open(args.repo_path+"testcases/config_functest.yaml") as f:
51     functest_yaml = yaml.safe_load(f)
52 f.close()
53
54 """ global variables """
55 # Directories
56 HOME = os.environ['HOME']+"/"
57 REPO_PATH = args.repo_path
58 TEST_DB = functest_yaml.get("results").get("test_db_url")
59
60
61 def main():
62     try:
63         logger.info("Functest test result generation for dashboard")
64
65         # TODO create the loop to provide all the json files
66         logger.debug("Retrieve all the testcases from DB")
67         test_cases = dashboard_utils.get_testcases(TEST_DB, "functest")
68
69         # TODO to be refactor once graph for Tempest, rally and ODL ready
70         # Do it only for vPing in first stage
71         for case in test_cases:
72             logger.debug("Generate " + case + " json files")
73             dashboard_utils.generateJson('functest', case, TEST_DB)
74
75         logger.info("Functest json files for dashboard successfully generated")
76     except:
77         logger.error("Impossible to generate json files for dashboard")
78
79
80 if __name__ == '__main__':
81     main()