Merge "import new _put_file_shell method from upstream rally"
[yardstick.git] / api / views.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 import logging
10 import os
11
12 from flask import request
13 from flask_restful import Resource
14 from flasgger.utils import swag_from
15
16 from api.utils import common as common_utils
17 from api.swagger import models
18 from api.actions import test as test_action
19 from api.actions import samples as samples_action
20 from api.actions import result as result_action
21 from api.actions import env as env_action
22
23 logger = logging.getLogger(__name__)
24
25
26 TestCaseActionModel = models.TestCaseActionModel
27 TestCaseActionArgsModel = models.TestCaseActionArgsModel
28 TestCaseActionArgsOptsModel = models.TestCaseActionArgsOptsModel
29 TestCaseActionArgsOptsTaskArgModel = models.TestCaseActionArgsOptsTaskArgModel
30
31
32 class Release(Resource):
33     @swag_from(os.getcwd() + '/swagger/docs/testcases.yaml')
34     def post(self):
35         action = common_utils.translate_to_str(request.json.get('action', ''))
36         args = common_utils.translate_to_str(request.json.get('args', {}))
37         logger.debug('Input args is: action: %s, args: %s', action, args)
38
39         try:
40             return getattr(test_action, action)(args)
41         except AttributeError:
42             return common_utils.error_handler('Wrong action')
43
44
45 class Samples(Resource):
46     def post(self):
47         action = common_utils.translate_to_str(request.json.get('action', ''))
48         args = common_utils.translate_to_str(request.json.get('args', {}))
49         logger.debug('Input args is: action: %s, args: %s', action, args)
50
51         try:
52             return getattr(samples_action, action)(args)
53         except AttributeError:
54             return common_utils.error_handler('Wrong action')
55
56
57 ResultModel = models.ResultModel
58
59
60 class Results(Resource):
61     @swag_from(os.getcwd() + '/swagger/docs/results.yaml')
62     def get(self):
63         args = common_utils.translate_to_str(request.args)
64         action = args.get('action', '')
65         logger.debug('Input args is: action: %s, args: %s', action, args)
66
67         try:
68             return getattr(result_action, action)(args)
69         except AttributeError:
70             return common_utils.error_handler('Wrong action')
71
72
73 class Env(Resource):
74     def post(self):
75         action = common_utils.translate_to_str(request.json.get('action', ''))
76         args = common_utils.translate_to_str(request.json.get('args', {}))
77         logger.debug('Input args is: action: %s, args: %s', action, args)
78
79         try:
80             return getattr(env_action, action)(args)
81         except AttributeError:
82             return common_utils.error_handler('Wrong action')