Yardstick: Aarch64 jenkins slave support
[yardstick.git] / api / resources / samples_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.SAMPLE_CASE_DIR,
31                             '{}.yaml'.format(case_name))
32
33     task_id = str(uuid.uuid4())
34
35     task_args = {
36         'inputfile': [testcase],
37         'task_id': task_id
38     }
39     task_args.update(args.get('opts', {}))
40
41     param = Param(task_args)
42     task_thread = TaskThread(Task().start, param)
43     task_thread.start()
44
45     return result_handler(consts.API_SUCCESS, {'task_id': task_id})