We can launch the API with this file
TODOs :
+ - logging
- json args validation with schemes
+ - POST/PUT/DELETE for PODs
+ - POST/PUT/GET/DELETE for installers, platforms (enrich results info)
- count cases for GET on test_projects
- count results for GET on cases
- - provide filtering on requests
- include objects
- - logging
- - external configuration file
+ - swagger documentation
- setup file
- results pagination
- - POST/PUT/DELETE for PODs
- - POST/PUT/GET/DELETE for installers, platforms (enrich results info)
+ - unit tests
"""
import tornado.ioloop
import motor
+import argparse
from resources.handlers import VersionHandler, PodHandler, \
- TestProjectHandler, TestCasesHandler, TestResultsHandler
-from common.constants import API_LISTENING_PORT, MONGO_URL
+ TestProjectHandler, TestCasesHandler, TestResultsHandler, DashboardHandler
+from common.config import APIConfig
+
+
+# optionally get config file from command line
+parser = argparse.ArgumentParser()
+parser.add_argument("-c", "--config-file", dest='config_file',
+ help="Config file location")
+args = parser.parse_args()
+CONF = APIConfig().parse(args.config_file)
# connecting to MongoDB server, and choosing database
-db = motor.MotorClient(MONGO_URL).test_results_collection
+client = motor.MotorClient(CONF.mongo_url)
+db = client[CONF.mongo_dbname]
def make_app():
# GET /pods => Get all pods
# GET /pods/1 => Get details on POD 1
(r"/pods", PodHandler),
- (r"/pods/(\d*)", PodHandler),
+ (r"/pods/([^/]+)", PodHandler),
# few examples:
# GET /test_projects
# => get results with optional filters
# POST /results =>
# Push results with mandatory request payload parameters
- # (project, case, and pod_id)
+ # (project, case, and pod)
(r"/results", TestResultsHandler),
(r"/results([^/]*)", TestResultsHandler),
(r"/results/([^/]*)", TestResultsHandler),
+
+ # Method to manage Dashboard ready results
+ # GET /dashboard?project=functest&case=vPing&pod=opnfv-jump2
+ # => get results in dasboard ready format
+ # get /dashboard
+ # => get the list of project with dashboard ready results
+ (r"/dashboard", DashboardHandler),
+ (r"/dashboard([^/]*)", DashboardHandler),
+ (r"/dashboard/([^/]*)", DashboardHandler),
],
db=db,
- debug=True,
+ debug=CONF.api_debug_on,
)
def main():
application = make_app()
- application.listen(API_LISTENING_PORT)
+ application.listen(CONF.api_port)
tornado.ioloop.IOLoop.current().start()
+
if __name__ == "__main__":
main()