1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 We can launch the API with this file
19 - json args validation with schemes
20 - POST/PUT/DELETE for PODs
21 - POST/PUT/GET/DELETE for installers, platforms (enrich results info)
22 - count cases for GET on test_projects
23 - count results for GET on cases
25 - swagger documentation
36 from resources.handlers import VersionHandler, PodHandler, \
37 TestProjectHandler, TestCasesHandler, TestResultsHandler, DashboardHandler
38 from common.config import APIConfig
41 # optionally get config file from command line
42 parser = argparse.ArgumentParser()
43 parser.add_argument("-c", "--config-file", dest='config_file',
44 help="Config file location")
45 args = parser.parse_args()
46 CONF = APIConfig().parse(args.config_file)
48 # connecting to MongoDB server, and choosing database
49 client = motor.MotorClient(CONF.mongo_url)
50 db = client[CONF.mongo_dbname]
54 return tornado.web.Application(
56 # GET /version => GET API version
57 (r"/version", VersionHandler),
60 # GET /pods => Get all pods
61 # GET /pods/1 => Get details on POD 1
62 (r"/pods", PodHandler),
63 (r"/pods/([^/]+)", PodHandler),
67 # GET /test_projects/yardstick
68 (r"/test_projects", TestProjectHandler),
69 (r"/test_projects/([^/]+)", TestProjectHandler),
72 # GET /test_projects/qtip/cases => Get cases for qtip
74 (r"/test_projects/([^/]+)/cases", TestCasesHandler),
75 (r"/test_projects/([^/]+)/cases/([^/]+)", TestCasesHandler),
76 # (r"/test_cases/([^/]+)", TestCasesHandler),
78 # new path to avoid a long depth
79 # GET /results?project=functest&case=keystone.catalog&pod=1
80 # => get results with optional filters
82 # Push results with mandatory request payload parameters
83 # (project, case, and pod)
84 (r"/results", TestResultsHandler),
85 (r"/results([^/]*)", TestResultsHandler),
86 (r"/results/([^/]*)", TestResultsHandler),
88 # Method to manage Dashboard ready results
89 # GET /dashboard?project=functest&case=vPing&pod=opnfv-jump2
90 # => get results in dasboard ready format
92 # => get the list of project with dashboard ready results
93 (r"/dashboard", DashboardHandler),
94 (r"/dashboard([^/]*)", DashboardHandler),
95 (r"/dashboard/([^/]*)", DashboardHandler),
98 debug=CONF.api_debug_on,
103 application = make_app()
104 application.listen(CONF.api_port)
105 tornado.ioloop.IOLoop.current().start()
108 if __name__ == "__main__":