Merge "Add API(v2) to get all test case info"
[yardstick.git] / api / resources / v2 / testcases.py
1 import logging
2 import os
3
4 from api import ApiResource
5 from yardstick.common.utils import result_handler
6 from yardstick.common import constants as consts
7 from yardstick.benchmark.core import Param
8 from yardstick.benchmark.core.testcase import Testcase
9
10 LOG = logging.getLogger(__name__)
11 LOG.setLevel(logging.DEBUG)
12
13
14 class V2Testcases(ApiResource):
15
16     def get(self):
17         param = Param({})
18         testcase_list = Testcase().list_all(param)
19         return result_handler(consts.API_SUCCESS, testcase_list)
20
21     def post(self):
22         return self._dispatch_post()
23
24     def upload_case(self, args):
25         try:
26             upload_file = args['file']
27         except KeyError:
28             return result_handler(consts.API_ERROR, 'file must be provided')
29
30         case_name = os.path.join(consts.TESTCASE_DIR, upload_file.filename)
31
32         LOG.info('save case file')
33         upload_file.save(case_name)
34
35         return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename})