Change prepareYardstickEnv to prepare_env and add log info
[yardstick.git] / api / resources / release_action.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9 from __future__ import absolute_import
10 import uuid
11 import os
12 import logging
13
14 from api.utils.common import result_handler
15 from api.utils.thread import TaskThread
16 from yardstick.common import constants as consts
17 from yardstick.benchmark.core import Param
18 from yardstick.benchmark.core.task import Task
19
20 logger = logging.getLogger(__name__)
21 logger.setLevel(logging.DEBUG)
22
23
24 def run_test_case(args):
25     try:
26         case_name = args['testcase']
27     except KeyError:
28         return result_handler(consts.API_ERROR, 'testcase must be provided')
29
30     testcase = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
31
32     task_id = str(uuid.uuid4())
33
34     task_args = {
35         'inputfile': [testcase],
36         'task_id': task_id
37     }
38     task_args.update(args.get('opts', {}))
39
40     param = Param(task_args)
41     task_thread = TaskThread(Task().start, param)
42     task_thread.start()
43
44     return result_handler(consts.API_SUCCESS, {'task_id': task_id})