aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/testsuites_action.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-06-26 09:46:24 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-06-29 11:25:17 +0000
commitda62008a0a98cb8793ea42827a7da5e149edd144 (patch)
treef91e35eabe04ebb8c6618345c0fd1b76c5f37a2c /api/resources/testsuites_action.py
parent1ff9df7e724eb0c981aebd5f5b8aa90db0da292b (diff)
Call core code directly in the API of run test case
JIRA: YARDSTICK-688 We need to call core code directly in the API of runTestCase. It would be more stable. Change-Id: I431a85ded7cd3b20da0462f947c25d91bb99decd Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources/testsuites_action.py')
-rw-r--r--api/resources/testsuites_action.py52
1 files changed, 18 insertions, 34 deletions
diff --git a/api/resources/testsuites_action.py b/api/resources/testsuites_action.py
index a385290d9..e37eacc3e 100644
--- a/api/resources/testsuites_action.py
+++ b/api/resources/testsuites_action.py
@@ -6,57 +6,41 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
-"""Yardstick test suite api action"""
-
from __future__ import absolute_import
import uuid
import os
import logging
-import yaml
-from api.utils import common as common_utils
+from api.utils.common import result_handler
+from api.utils.thread import TaskThread
from yardstick.common import constants as consts
-from yardstick.common.task_template import TaskTemplate
+from yardstick.benchmark.core import Param
+from yardstick.benchmark.core.task import Task
logger = logging.getLogger(__name__)
+logger.setLevel(logging.DEBUG)
-def runTestSuite(args):
+def run_test_suite(args):
try:
- opts = args.get('opts', {})
- testsuite = args['testsuite']
+ suite_name = args['testsuite']
except KeyError:
- return common_utils.error_handler('Lack of testsuite argument')
+ return result_handler(consts.API_ERROR, 'testsuite must be provided')
- if 'suite' not in opts:
- opts['suite'] = 'true'
-
- testsuite = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(testsuite))
+ testsuite = os.path.join(consts.TESTSUITE_DIR,
+ '{}.yaml'.format(suite_name))
task_id = str(uuid.uuid4())
- command_list = ['task', 'start']
- command_list = common_utils.get_command_list(command_list, opts, testsuite)
- logger.debug('The command_list is: %s', command_list)
-
- logger.debug('Start to execute command list')
- task_dic = {
+ task_args = {
+ 'inputfile': [testsuite],
'task_id': task_id,
- 'details': _get_cases_from_suite_file(testsuite)
+ 'suite': True
}
- common_utils.exec_command_task(command_list, task_dic)
-
- return common_utils.result_handler('success', task_id)
-
-
-def _get_cases_from_suite_file(testsuite):
- def get_name(full_name):
- return os.path.splitext(full_name)[0]
+ task_args.update(args.get('opts', {}))
- with open(testsuite) as f:
- contents = TaskTemplate.render(f.read())
+ param = Param(task_args)
+ task_thread = TaskThread(Task().start, param)
+ task_thread.start()
- suite_dic = yaml.safe_load(contents)
- testcases = (get_name(c['file_name']) for c in suite_dic['test_cases'])
- return ','.join(testcases)
+ return result_handler(consts.API_SUCCESS, {'task_id': task_id})