1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd.
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 ##############################################################################
13 from api import ApiResource
14 from yardstick.common.utils import result_handler
15 from yardstick.common import constants as consts
16 from yardstick.benchmark.core import Param
17 from yardstick.benchmark.core.testcase import Testcase
19 LOG = logging.getLogger(__name__)
20 LOG.setLevel(logging.DEBUG)
23 class V2Testcases(ApiResource):
27 testcase_list = Testcase().list_all(param)
28 return result_handler(consts.API_SUCCESS, testcase_list)
31 return self._dispatch_post()
33 def upload_case(self, args):
35 upload_file = args['file']
37 return result_handler(consts.API_ERROR, 'file must be provided')
39 case_name = os.path.join(consts.TESTCASE_DIR, upload_file.filename)
41 LOG.info('save case file')
42 upload_file.save(case_name)
44 return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename})
47 class V2Testcase(ApiResource):
49 def get(self, case_name):
50 case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
53 with open(case_path) as f:
56 if e.errno == errno.ENOENT:
57 return result_handler(consts.API_ERROR, 'case does not exist')
59 return result_handler(consts.API_SUCCESS, {'testcase': data})
61 def delete(self, case_name):
62 case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
67 if e.errno == errno.ENOENT:
68 return result_handler(consts.API_ERROR, 'case does not exist')
70 return result_handler(consts.API_SUCCESS, {'testcase': case_name})