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
18 - use POD name instead of id
20 - json args validation with schemes
21 - POST/PUT/DELETE for PODs
22 - POST/PUT/GET/DELETE for installers, platforms (enrich results info)
23 - count cases for GET on test_projects
24 - count results for GET on cases
25 - provide filtering on requests
27 - swagger documentation
38 from resources.handlers import VersionHandler, PodHandler, \
39 TestProjectHandler, TestCasesHandler, TestResultsHandler
40 from common.config import APIConfig
43 # optionally get config file from command line
44 parser = argparse.ArgumentParser()
45 parser.add_argument("-c", "--config-file", dest='config_file',
46 help="Config file location")
47 args = parser.parse_args()
48 CONF = APIConfig().parse(args.config_file)
50 # connecting to MongoDB server, and choosing database
51 db = motor.MotorClient(CONF.mongo_url)
55 return tornado.web.Application(
57 # GET /version => GET API version
58 (r"/version", VersionHandler),
61 # GET /pods => Get all pods
62 # GET /pods/1 => Get details on POD 1
63 (r"/pods", PodHandler),
64 (r"/pods/(\d*)", PodHandler),
68 # GET /test_projects/yardstick
69 (r"/test_projects", TestProjectHandler),
70 (r"/test_projects/([^/]+)", TestProjectHandler),
73 # GET /test_projects/qtip/cases => Get cases for qtip
75 (r"/test_projects/([^/]+)/cases", TestCasesHandler),
76 (r"/test_projects/([^/]+)/cases/([^/]+)", TestCasesHandler),
77 # (r"/test_cases/([^/]+)", TestCasesHandler),
79 # new path to avoid a long depth
80 # GET /results?project=functest&case=keystone.catalog&pod=1
81 # => get results with optional filters
83 # Push results with mandatory request payload parameters
84 # (project, case, and pod_id)
85 (r"/results", TestResultsHandler),
86 (r"/results([^/]*)", TestResultsHandler),
87 (r"/results/([^/]*)", TestResultsHandler),
90 debug=CONF.api_debug_on,
95 application = make_app()
96 application.listen(CONF.api_port)
97 tornado.ioloop.IOLoop.current().start()
100 if __name__ == "__main__":