c3d734607c61ca2bdd292b9f13dbd8cb72d694a5
[releng.git] / utils / test / result_collection_api / opnfv_testapi / cmd / server.py
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 ##############################################################################
9
10 """
11 Pre-requisites:
12     pip install motor
13     pip install tornado
14
15 We can launch the API with this file
16
17 TODOs :
18   - logging
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 projects
23   - count results for GET on cases
24   - include objects
25   - swagger documentation
26   - setup file
27   - results pagination
28   - unit tests
29
30 """
31
32 import argparse
33
34 import tornado.ioloop
35 import motor
36
37 from opnfv_testapi.common.config import APIConfig
38 from opnfv_testapi.tornado_swagger import swagger
39 from opnfv_testapi.router import url_mappings
40
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)
47
48 # connecting to MongoDB server, and choosing database
49 client = motor.MotorClient(CONF.mongo_url)
50 db = client[CONF.mongo_dbname]
51
52 swagger.docs(base_url=CONF.swagger_base_url)
53
54
55 def make_app():
56     return swagger.Application(
57         url_mappings.mappings,
58         db=db,
59         debug=CONF.api_debug_on,
60     )
61
62
63 def main():
64     application = make_app()
65     application.listen(CONF.api_port)
66     tornado.ioloop.IOLoop.current().start()
67
68
69 if __name__ == "__main__":
70     main()