5 from api import ApiResource
6 from yardstick.common.utils import result_handler
7 from yardstick.common import constants as consts
8 from yardstick.benchmark.core import Param
9 from yardstick.benchmark.core.testcase import Testcase
11 LOG = logging.getLogger(__name__)
12 LOG.setLevel(logging.DEBUG)
15 class V2Testcases(ApiResource):
19 testcase_list = Testcase().list_all(param)
20 return result_handler(consts.API_SUCCESS, testcase_list)
23 return self._dispatch_post()
25 def upload_case(self, args):
27 upload_file = args['file']
29 return result_handler(consts.API_ERROR, 'file must be provided')
31 case_name = os.path.join(consts.TESTCASE_DIR, upload_file.filename)
33 LOG.info('save case file')
34 upload_file.save(case_name)
36 return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename})
39 class V2Testcase(ApiResource):
41 def get(self, case_name):
42 case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
45 with open(case_path) as f:
48 if e.errno == errno.ENOENT:
49 return result_handler(consts.API_ERROR, 'case does not exist')
51 return result_handler(consts.API_SUCCESS, {'testcase': data})