diff options
author | Rex Lee <limingjiang@huawei.com> | 2017-06-29 12:07:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-06-29 12:07:27 +0000 |
commit | 9ba594fa3f34d551d34abd7582281ce081924c67 (patch) | |
tree | 43e32e6d2a5ca9c09b47ef698f24abe784d8f6cc /api/resources/testsuites_action.py | |
parent | 8996240be14d6f7979a6ae02dd474b03d50e79d9 (diff) | |
parent | da62008a0a98cb8793ea42827a7da5e149edd144 (diff) |
Merge "Call core code directly in the API of run test case"
Diffstat (limited to 'api/resources/testsuites_action.py')
-rw-r--r-- | api/resources/testsuites_action.py | 52 |
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}) |