1 ##############################################################################
2 # Copyright (c) 2016 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 """Yardstick test suite api action"""
12 from __future__ import absolute_import
18 from api.utils import common as common_utils
19 from yardstick.common import constants as consts
20 from yardstick.common.task_template import TaskTemplate
22 logger = logging.getLogger(__name__)
25 def runTestSuite(args):
27 opts = args.get('opts', {})
28 testsuite = args['testsuite']
30 return common_utils.error_handler('Lack of testsuite argument')
32 if 'suite' not in opts:
33 opts['suite'] = 'true'
35 testsuite = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(testsuite))
37 task_id = str(uuid.uuid4())
39 command_list = ['task', 'start']
40 command_list = common_utils.get_command_list(command_list, opts, testsuite)
41 logger.debug('The command_list is: %s', command_list)
43 logger.debug('Start to execute command list')
46 'details': _get_cases_from_suite_file(testsuite)
48 common_utils.exec_command_task(command_list, task_dic)
50 return common_utils.result_handler('success', task_id)
53 def _get_cases_from_suite_file(testsuite):
54 def get_name(full_name):
55 return os.path.splitext(full_name)[0]
57 with open(testsuite) as f:
58 contents = TaskTemplate.render(f.read())
60 suite_dic = yaml.safe_load(contents)
61 testcases = (get_name(c['file_name']) for c in suite_dic['test_cases'])
62 return ','.join(testcases)