Create API to run test cases
[yardstick.git] / api / actions / test.py
1 import uuid
2 import json
3 import os
4 import logging
5
6 from api import conf
7 from api.utils import common as common_utils
8
9 logger = logging.getLogger(__name__)
10
11
12 def runTestCase(args):
13     try:
14         opts = args.get('opts', {})
15         testcase = args['testcase']
16     except KeyError:
17         logger.error('Lack of testcase argument')
18         result = {
19             'status': 'error',
20             'message': 'need testcase name'
21         }
22         return json.dumps(result)
23
24     testcase = os.path.join(conf.TEST_CASE_PATH,
25                             conf.TEST_CASE_PRE + testcase + '.yaml')
26
27     task_id = str(uuid.uuid4())
28
29     command_list = ['task', 'start']
30     command_list = common_utils.get_command_list(command_list, opts, testcase)
31     logger.debug('The command_list is: %s', command_list)
32
33     logger.debug('Start to execute command list')
34     common_utils.exec_command_task(command_list, task_id)
35
36     result = {
37         'status': 'success',
38         'task_id': task_id
39     }
40     return json.dumps(result)