1 # ############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
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 # ############################################################################
10 from __future__ import absolute_import
15 from flasgger.utils import swag_from
17 from yardstick.benchmark.core.testcase import Testcase
18 from yardstick.benchmark.core.task import Task
19 from yardstick.benchmark.core import Param
20 from yardstick.common import constants as consts
21 from yardstick.common.utils import result_handler
22 from api.utils.thread import TaskThread
23 from api import ApiResource
24 from api.swagger import models
26 LOG = logging.getLogger(__name__)
27 LOG.setLevel(logging.DEBUG)
30 class V1Testcase(ApiResource):
34 testcase_list = Testcase().list_all(param)
35 return result_handler(consts.API_SUCCESS, testcase_list)
38 class V1CaseDocs(ApiResource):
40 def get(self, case_name):
41 docs_path = os.path.join(consts.DOCS_DIR, '{}.rst'.format(case_name))
43 if not os.path.exists(docs_path):
44 return result_handler(consts.API_ERROR, 'case not exists')
46 LOG.info('Reading %s', case_name)
47 with open(docs_path) as f:
50 return result_handler(consts.API_SUCCESS, {'docs': content})
53 TestCaseActionModel = models.TestCaseActionModel
54 TestCaseActionArgsModel = models.TestCaseActionArgsModel
55 TestCaseActionArgsOptsModel = models.TestCaseActionArgsOptsModel
56 TestCaseActionArgsOptsTaskArgModel = models.TestCaseActionArgsOptsTaskArgModel
59 class V1ReleaseCase(ApiResource):
61 @swag_from(os.path.join(consts.REPOS_DIR,
62 'api/swagger/docs/release_action.yaml'))
64 return self._dispatch_post()
66 def run_test_case(self, args):
68 name = args['testcase']
70 return result_handler(consts.API_ERROR, 'testcase must be provided')
72 testcase = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(name))
74 task_id = str(uuid.uuid4())
77 'inputfile': [testcase],
80 task_args.update(args.get('opts', {}))
82 param = Param(task_args)
83 task_thread = TaskThread(Task().start, param)
86 return result_handler(consts.API_SUCCESS, {'task_id': task_id})
89 class V1SampleCase(ApiResource):
92 return self._dispatch_post()
94 def run_test_case(self, args):
96 name = args['testcase']
98 return result_handler(consts.API_ERROR, 'testcase must be provided')
100 testcase = os.path.join(consts.SAMPLE_CASE_DIR, '{}.yaml'.format(name))
102 task_id = str(uuid.uuid4())
105 'inputfile': [testcase],
108 task_args.update(args.get('opts', {}))
110 param = Param(task_args)
111 task_thread = TaskThread(Task().start, param)
114 return result_handler(consts.API_SUCCESS, {'task_id': task_id})