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
25 from api.database.v1.handlers import TasksHandler
27 LOG = logging.getLogger(__name__)
28 LOG.setLevel(logging.DEBUG)
31 class V1Testcase(ApiResource):
35 testcase_list = Testcase().list_all(param)
36 return result_handler(consts.API_SUCCESS, testcase_list)
39 class V1CaseDocs(ApiResource):
41 def get(self, case_name):
42 docs_path = os.path.join(consts.DOCS_DIR, '{}.rst'.format(case_name))
44 if not os.path.exists(docs_path):
45 return result_handler(consts.API_ERROR, 'case not exists')
47 LOG.info('Reading %s', case_name)
48 with open(docs_path) as f:
51 return result_handler(consts.API_SUCCESS, {'docs': content})
54 TestCaseActionModel = models.TestCaseActionModel
55 TestCaseActionArgsModel = models.TestCaseActionArgsModel
56 TestCaseActionArgsOptsModel = models.TestCaseActionArgsOptsModel
57 TestCaseActionArgsOptsTaskArgModel = models.TestCaseActionArgsOptsTaskArgModel
60 class V1ReleaseCase(ApiResource):
62 @swag_from(os.path.join(consts.REPOS_DIR,
63 'api/swagger/docs/release_action.yaml'))
65 return self._dispatch_post()
67 def run_test_case(self, args):
69 name = args['testcase']
71 return result_handler(consts.API_ERROR, 'testcase must be provided')
73 testcase = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(name))
75 task_id = str(uuid.uuid4())
78 'inputfile': [testcase],
81 task_args.update(args.get('opts', {}))
83 param = Param(task_args)
84 task_thread = TaskThread(Task().start, param, TasksHandler())
87 return result_handler(consts.API_SUCCESS, {'task_id': task_id})
90 class V1SampleCase(ApiResource):
93 return self._dispatch_post()
95 def run_test_case(self, args):
97 name = args['testcase']
99 return result_handler(consts.API_ERROR, 'testcase must be provided')
101 testcase = os.path.join(consts.SAMPLE_CASE_DIR, '{}.yaml'.format(name))
103 task_id = str(uuid.uuid4())
106 'inputfile': [testcase],
109 task_args.update(args.get('opts', {}))
111 param = Param(task_args)
112 task_thread = TaskThread(Task().start, param, TasksHandler())
115 return result_handler(consts.API_SUCCESS, {'task_id': task_id})